Browse Source

fixes for py2 py3 compat

Thomas B 3 months ago
parent
commit
6b1c517201
2 changed files with 8 additions and 4 deletions
  1. 6
    3
      macros.py
  2. 2
    1
      poole.py

+ 6
- 3
macros.py View File

@@ -1,5 +1,7 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
+from __future__ import print_function
4
+
3 5
 import sys
4 6
 import re
5 7
 import itertools
@@ -24,6 +26,7 @@ if PY3:
24 26
     def urlparse_foo(link):
25 27
         return urllib.parse.parse_qs(urllib.parse.urlparse(link).query)['v'][0]
26 28
 else:
29
+    import urllib
27 30
     import urlparse
28 31
     def urlparse_foo(link):
29 32
         return urlparse.parse_qs(urlparse.urlparse(link).query)['v'][0]
@@ -398,7 +401,7 @@ def restRequest(url):
398 401
         sys.stderr.write("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
399 402
         sys.stderr.write("\n")
400 403
         return ""
401
-    data = json.loads(response.read())
404
+    data = json.loads(response.read().decode("utf-8"))
402 405
     return data
403 406
 
404 407
 def restReleases(user, repo):
@@ -449,8 +452,8 @@ def include_url(url):
449 452
     response = urllib.request.urlopen(url) if PY3 else urllib.urlopen(url)
450 453
     if response.getcode() != 200:
451 454
         raise Exception("invalid response code", response.getcode())
452
-    data = response.read()
453
-    print(data,)
455
+    data = response.read().decode("utf-8")
456
+    print(data, end="")
454 457
 
455 458
 # -----------------------------------------------------------------------------
456 459
 # preconvert hooks

+ 2
- 1
poole.py View File

@@ -24,6 +24,7 @@
24 24
 # =============================================================================
25 25
 
26 26
 from __future__ import with_statement
27
+from __future__ import print_function
27 28
 
28 29
 import codecs
29 30
 import glob
@@ -81,7 +82,7 @@ else:
81 82
             execfile(tf.name, envdic)
82 83
     import imp
83 84
     def imp_load_source(module_name, module_path):
84
-        imp.load_source(module_name, module_path)
85
+        return imp.load_source(module_name, module_path)
85 86
     import urlparse
86 87
     def urlparse_urljoin(a, b):
87 88
         return urlparse.urljoin(a, b)

Loading…
Cancel
Save