diff --git a/libsaria/web.py b/libsaria/web.py new file mode 100644 index 00000000..0c9a3997 --- /dev/null +++ b/libsaria/web.py @@ -0,0 +1,33 @@ +# Bryan Schumaker (10/24/2010) + +import libsaria +import urllib2 +import string + +HEADER = libsaria.__vers__ + +vals = [ ('%','25'), (' ','20'), ('&','26'), ('<','3C'), ('>','3E'), + ('"','22'), ('#','23'), ('$','24'), ('\'','27'), ('+','2B'), + (',','2C'), ('/','2F'), (':','3A'), ('[','5B'), (']','5D')] + + +class Url: + def __init__(self, url): + self.url = url + + def __setitem__(self, key, value): + value = escape(value) + self.url += "&" + key + "=" + value + + def open(self): + #print self.url + req = urllib2.Request(self.url) + req.add_header('User-Agent', HEADER) + return urllib2.urlopen(req) + + +def escape(string): + for l in vals: + string = string.replace(l[0], "%s%s" % ('%', l[1])) + return string +