diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2013-07-25 19:26:52 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2015-12-03 03:29:37 +0100 |
commit | f3b86ed2d5bce85b3b9c27eb949cd88cf7d526bc (patch) | |
tree | a187725f5ec7f1c67d2b9a471b4000ad40a16b04 /web.py | |
parent | 4b905606692a2f147946505abe6ade1c241d1000 (diff) | |
download | bot-f3b86ed2d5bce85b3b9c27eb949cd88cf7d526bc.tar.gz bot-f3b86ed2d5bce85b3b9c27eb949cd88cf7d526bc.tar.bz2 bot-f3b86ed2d5bce85b3b9c27eb949cd88cf7d526bc.zip |
fix indentation and trailing whitespaces
Diffstat (limited to 'web.py')
-rwxr-xr-x | web.py | 94 |
1 files changed, 47 insertions, 47 deletions
@@ -8,64 +8,64 @@ About: http://inamidst.com/phenny/ import re, urllib from htmlentitydefs import name2codepoint -class Grab(urllib.URLopener): - def __init__(self, *args): - self.version = 'Mozilla/5.0 (Phenny)' - urllib.URLopener.__init__(self, *args) - def http_error_default(self, url, fp, errcode, errmsg, headers): - return urllib.addinfourl(fp, [headers, errcode], "http:" + url) +class Grab(urllib.URLopener): + def __init__(self, *args): + self.version = 'Mozilla/5.0 (Phenny)' + urllib.URLopener.__init__(self, *args) + def http_error_default(self, url, fp, errcode, errmsg, headers): + return urllib.addinfourl(fp, [headers, errcode], "http:" + url) urllib._urlopener = Grab() -def get(uri): - if not uri.startswith('http'): - return - u = urllib.urlopen(uri) - bytes = u.read() - u.close() - return bytes +def get(uri): + if not uri.startswith('http'): + return + u = urllib.urlopen(uri) + bytes = u.read() + u.close() + return bytes -def head(uri): - if not uri.startswith('http'): - return - u = urllib.urlopen(uri) - info = u.info() - u.close() - return info +def head(uri): + if not uri.startswith('http'): + return + u = urllib.urlopen(uri) + info = u.info() + u.close() + return info -def post(uri, query): - if not uri.startswith('http'): - return - data = urllib.urlencode(query) - u = urllib.urlopen(uri, data) - bytes = u.read() - u.close() - return bytes +def post(uri, query): + if not uri.startswith('http'): + return + data = urllib.urlencode(query) + u = urllib.urlopen(uri, data) + bytes = u.read() + u.close() + return bytes r_entity = re.compile(r'&([^;\s]+);') -def entity(match): - value = match.group(1).lower() - if value.startswith('#x'): - return unichr(int(value[2:], 16)) - elif value.startswith('#'): - return unichr(int(value[1:])) - elif name2codepoint.has_key(value): - return unichr(name2codepoint[value]) - return '[' + value + ']' +def entity(match): + value = match.group(1).lower() + if value.startswith('#x'): + return unichr(int(value[2:], 16)) + elif value.startswith('#'): + return unichr(int(value[1:])) + elif name2codepoint.has_key(value): + return unichr(name2codepoint[value]) + return '[' + value + ']' -def decode(html): - return r_entity.sub(entity, html) +def decode(html): + return r_entity.sub(entity, html) r_string = re.compile(r'("(\\.|[^"\\])*")') r_json = re.compile(r'^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]+$') env = {'__builtins__': None, 'null': None, 'true': True, 'false': False} -def json(text): - """Evaluate JSON text safely (we hope).""" - if r_json.match(r_string.sub('', text)): - text = r_string.sub(lambda m: 'u' + m.group(1), text) - return eval(text.strip(' \t\r\n'), env, {}) - raise ValueError('Input must be serialised JSON.') +def json(text): + """Evaluate JSON text safely (we hope).""" + if r_json.match(r_string.sub('', text)): + text = r_string.sub(lambda m: 'u' + m.group(1), text) + return eval(text.strip(' \t\r\n'), env, {}) + raise ValueError('Input must be serialised JSON.') -if __name__=="__main__": - main() +if __name__=="__main__": + main() |