+
+# For fuck's sake!
+import codecs
+import locale
+def fix_stdout():
+ sys.stdout = codecs.EncodedFile(sys.stdout, locale.getpreferredencoding())
+ def null_decode(input, errors='strict'):
+ return input, len(input)
+ sys.stdout.decode = null_decode
+# From
+# http://ewx.livejournal.com/457086.html?thread=3016574
+# http://ewx.livejournal.com/457086.html?thread=3016574
+# lightly modified.
+# See also Debian #415968.
+fix_stdout()
+
+
+# User agent:
+class YarrgURLopener(urllib.FancyURLopener):
+ base_version= urllib.URLopener().version
+ proc= subprocess.Popen(
+ ["./database-info-fetch", "useragentstringmap",
+ base_version, "manual islands/topology fetch"],
+ shell=False,
+ stderr=None,
+ stdout=subprocess.PIPE,
+ )
+ version = proc.communicate()[0].rstrip('\n');
+ assert(proc.returncode is not None and proc.returncode == 0)
+urllib._urlopener = YarrgURLopener()
+