import httplib, urllib, base64, N3Parser class N3Http: # defines the address to be accessed # example www.w3.org def putAddress(self, s): self.address = s # the string s contains the page at the mentionned address # example /index/html def getRequest(self, s): h = httplib.HTTP(self.address) h.putrequest('GET', s) h.putheader('Accept', 'text/html') h.putheader('Accept', 'text/plain') h.putheader('Host', self.address) h.endheaders() errcode, errmsg, headers = h.getreply() print errcode # Should be 200 f = h.getfile() self.httpdata = f.read() # Get the raw HTML f.close() # read an url # proxy must be set in environment variable: # http-proxy = "http:// ..." def readUrl(self, url): f = urllib.urlopen(url) self.urldata = f.read() # read an url with proxy authentication def proxyUrl(self, proxy, userPass, url): # connect to the proxy h1 = httplib.HTTP(proxy) # give the absolute URL in the request h1.putrequest('GET', url) h1.putheader('Accept', 'text/html') h1.putheader('Accept', 'text/plain') # set the header with a base64 encoding of user-id:passwd auth = "Basic " + base64.encodestring(userPass) h1.putheader('Proxy-Authorization', auth) h1.endheaders() # get the page errcode, errmsg, headers = h1.getreply() print errcode print errmsg print headers f=h1.getfile() self.urldata = "" for line in f.readlines(): self.urldata = self.urldata + line #http = N3Http() #http.putAddress("192.32.2.7") #http.getRequest("/") #print (http.httpdata) #http.readUrl("http://www.w3.org/2002/03owlt/ontAx.n3") # "http://www.w3.org/2002/03owlt/ontAx.n3") #print "urldata\n\n",http.urldata #parser = N3Parser.N3Parser() #li = parser.parseN3("", http.urldata, 0) #parser.writeOutput(li)