]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/util.py
make inversion optional
[z_archive/twitter.git] / twitter / util.py
index eda73fb6cea26f7c31e5667f978926046f500656..b0a1f48e854d46f5845fc9e57157ae2f024c2778 100644 (file)
@@ -7,7 +7,12 @@ Internal utility functions.
 
 
 import re
-from htmlentitydefs import name2codepoint
+import sys
+try:
+    from html.entities import name2codepoint
+    unichr = chr
+except ImportError:
+    from htmlentitydefs import name2codepoint
 
 def htmlentitydecode(s):
     return re.sub(
@@ -21,13 +26,20 @@ def smrt_input(globals_, locals_, ps1=">>> ", ps2="... "):
             prompt = ps2
         else:
             prompt = ps1
-        inputs.append(raw_input(prompt))
+        inputs.append(input(prompt))
         try:
             ret = eval('\n'.join(inputs), globals_, locals_)
             if ret:
-                print ret
+                print(str(ret))
             return
         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"]