]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/util.py
Make twitter-log work with py 3.2
[z_archive/twitter.git] / twitter / util.py
index 3dca53e6807cb0f7e0e512500b134209d2e529c3..dab8c84948aed351a2945c9ae738417611495dbb 100644 (file)
@@ -7,7 +7,11 @@ Internal utility functions.
 
 
 import re
-from html.entities import name2codepoint
+import sys
+try:
+    from html.entities import name2codepoint
+except ImportError:
+    from htmlentitydefs import name2codepoint
 
 def htmlentitydecode(s):
     return re.sub(
@@ -30,4 +34,11 @@ def smrt_input(globals_, locals_, ps1=">>> ", ps2="... "):
         except SyntaxError:
             pass
 
+def printNicely(string):
+    if hasattr(sys.stdout, 'buffer'):
+        sys.stdout.buffer.write(string.encode('utf8'))
+        print()
+    else:
+        print(string.encode('utf8'))
+
 __all__ = ["htmlentitydecode", "smrt_input"]