X-Git-Url: https://jfr.im/git/z_archive/twitter.git/blobdiff_plain/9376cfa693173f3dea378c32c1d24668eece59ca..ea5231b2fe0f40d87c9c7991b949c39c7cddd7e3:/twitter/util.py diff --git a/twitter/util.py b/twitter/util.py index 3dca53e..b78a108 100644 --- a/twitter/util.py +++ b/twitter/util.py @@ -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( @@ -25,9 +29,16 @@ def smrt_input(globals_, locals_, ps1=">>> ", ps2="... "): 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"]