]> jfr.im git - z_archive/twitter.git/blame_incremental - twitter/util.py
Remove agent cruft. Default to api.twitter.com and version 1.
[z_archive/twitter.git] / twitter / util.py
... / ...
CommitLineData
1"""
2Internal utility functions.
3
4`htmlentitydecode` came from here:
5 http://wiki.python.org/moin/EscapingHtml
6"""
7
8
9import re
10try:
11 from html.entities import name2codepoint
12except ImportError:
13 from htmlentitydefs import name2codepoint
14
15def htmlentitydecode(s):
16 return re.sub(
17 '&(%s);' % '|'.join(name2codepoint),
18 lambda m: chr(name2codepoint[m.group(1)]), s)
19
20def smrt_input(globals_, locals_, ps1=">>> ", ps2="... "):
21 inputs = []
22 while True:
23 if inputs:
24 prompt = ps2
25 else:
26 prompt = ps1
27 inputs.append(input(prompt))
28 try:
29 ret = eval('\n'.join(inputs), globals_, locals_)
30 if ret:
31 print(ret)
32 return
33 except SyntaxError:
34 pass
35
36__all__ = ["htmlentitydecode", "smrt_input"]