]> jfr.im git - z_archive/twitter.git/blame - twitter/util.py
Add a simple prompt thing to twitter cmdline.
[z_archive/twitter.git] / twitter / util.py
CommitLineData
8ad2cf0b 1"""
2Internal utility functions.
3
4`htmlentitydecode` came from here:
5 http://wiki.python.org/moin/EscapingHtml
6"""
7
8
9import re
10from htmlentitydefs import name2codepoint
11
12def htmlentitydecode(s):
13 return re.sub(
a5e40197 14 '&(%s);' % '|'.join(name2codepoint),
8ad2cf0b 15 lambda m: unichr(name2codepoint[m.group(1)]), s)
16
a5e40197
MV
17def smrt_input(globals_, locals_, ps1=">>> ", ps2="... "):
18 inputs = []
19 while True:
20 if inputs:
21 prompt = ps2
22 else:
23 prompt = ps1
24 inputs.append(raw_input(prompt))
25 try:
26 ret = eval('\n'.join(inputs), globals_, locals_)
27 if ret:
28 print ret
29 return
30 except SyntaxError:
31 pass
32
33__all__ = ["htmlentitydecode", "smrt_input"]