c1a2d74f7c
A bit of separation is good here, and it should help with managing the code.
39 lines
838 B
Python
39 lines
838 B
Python
# Bryan Schumaker (10/24/2010)
|
|
|
|
from libsaria import version
|
|
import urllib2
|
|
import string
|
|
|
|
HEADER = version.__vers__
|
|
|
|
#vals = [ ('%','25'), (' ','20'), ('&','26'), ('<','3C'), ('>','3E'),
|
|
# ('"','22'), ('#','23'), ('$','24'), ('+', '2B'), ('\'','27'), #('+','2B'),
|
|
# (',','2C'), ('/','2F'), (':','3A'), ('[','5B'), (']','5D')]
|
|
vals = [ (' ','20'), ('&','26'), ('\'', '27') ]
|
|
|
|
|
|
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
|
|
try:
|
|
req = urllib2.Request(self.url)
|
|
req.add_header('User-Agent', HEADER)
|
|
return urllib2.urlopen(req)
|
|
except Exception, e:
|
|
print e
|
|
return None
|
|
|
|
|
|
def escape(string):
|
|
for l in vals:
|
|
string = string.replace(l[0], "%s%s" % ('%', l[1]))
|
|
return string
|
|
|