# Bryan Schumaker (10/24/2010)

import libsaria
import urllib2
import string

HEADER = libsaria.__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

