New calculator function, as tested by yano and jasondavies!

This commit is contained in:
Sean B. Palmer
2010-11-06 12:52:35 +00:00
parent 63b981c994
commit 9ae58d0a35
3 changed files with 39 additions and 3 deletions

18
web.py
View File

@@ -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()