]>
jfr.im git - z_archive/twitter.git/blob - twitter/util.py
2 Internal utility functions.
4 `htmlentitydecode` came from here:
5 http://wiki.python.org/moin/EscapingHtml
8 from __future__
import print_function
15 from html
.entities
import name2codepoint
18 from htmlentitydefs
import name2codepoint
20 def htmlentitydecode(s
):
22 '&(%s);' % '|'.join(name2codepoint
),
23 lambda m
: unichr(name2codepoint
[m
.group(1)]), s
)
25 def smrt_input(globals_
, locals_
, ps1
=">>> ", ps2
="... "):
32 inputs
.append(input(prompt
))
34 ret
= eval('\n'.join(inputs
), globals_
, locals_
)
41 def printNicely(string
):
42 if hasattr(sys
.stdout
, 'buffer'):
43 sys
.stdout
.buffer.write(string
.encode('utf8'))
46 print(string
.encode('utf8'))
48 __all__
= ["htmlentitydecode", "smrt_input"]
51 print(msg
, file=sys
.stderr
)
54 """A class to count fails during a repetitive task.
57 maximum: An integer for the maximum of fails to allow.
58 exit: An integer for the exit code when maximum of fail is reached.
61 count: Count a fail, exit when maximum of fails is reached.
62 wait: Same as count but also sleep for a given time in seconds.
64 def __init__(self
, maximum
=10, exit
=1):
71 err("Too many consecutive fails, exiting.")
72 raise SystemExit(self
.exit
)
74 def wait(self
, delay
=0):