]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/util.py
Remove agent cruft. Default to api.twitter.com and version 1.
[z_archive/twitter.git] / twitter / util.py
index 76283cdeafe0cb0003769d8ef775cae4f6b577a3..b6e95c6903c7bab15dce3ef56c83eaff4b3cbf19 100644 (file)
@@ -7,11 +7,30 @@ Internal utility functions.
 
 
 import re
-from html.entities import name2codepoint
+try:
+    from html.entities import name2codepoint
+except ImportError:
+    from htmlentitydefs import name2codepoint
 
 def htmlentitydecode(s):
     return re.sub(
-        '&(%s);' % '|'.join(name2codepoint), 
+        '&(%s);' % '|'.join(name2codepoint),
         lambda m: chr(name2codepoint[m.group(1)]), s)
 
-__all__ = ["htmlentitydecode"]
+def smrt_input(globals_, locals_, ps1=">>> ", ps2="... "):
+    inputs = []
+    while True:
+        if inputs:
+            prompt = ps2
+        else:
+            prompt = ps1
+        inputs.append(input(prompt))
+        try:
+            ret = eval('\n'.join(inputs), globals_, locals_)
+            if ret:
+                print(ret)
+            return
+        except SyntaxError:
+            pass
+
+__all__ = ["htmlentitydecode", "smrt_input"]