diff options
author | Sean B. Palmer <sbp@aldebaran.local> | 2010-11-06 12:52:35 +0000 |
---|---|---|
committer | Sean B. Palmer <sbp@aldebaran.local> | 2010-11-06 12:52:35 +0000 |
commit | 9ae58d0a353fc610e9affc1216b2cdc77e8cf89c (patch) | |
tree | 1026c6ed477af70783ae6b11520016b044f816c1 /web.py | |
parent | 63b981c994f2b41a9fcee003b7418f3cb10ba6a4 (diff) | |
download | bot-9ae58d0a353fc610e9affc1216b2cdc77e8cf89c.tar.gz bot-9ae58d0a353fc610e9affc1216b2cdc77e8cf89c.tar.bz2 bot-9ae58d0a353fc610e9affc1216b2cdc77e8cf89c.zip |
New calculator function, as tested by yano and jasondavies!
Diffstat (limited to 'web.py')
-rwxr-xr-x | web.py | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -5,7 +5,8 @@ Author: Sean B. Palmer, inamidst.com About: http://inamidst.com/phenny/ """ -import urllib +import re, urllib +from htmlentitydefs import name2codepoint class Grab(urllib.URLopener): def __init__(self, *args): @@ -40,5 +41,20 @@ def post(uri, query): 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 decode(html): + return r_entity.sub(entity, html) + if __name__=="__main__": main() |