def test_clientcookie(self): # XXX set up test page on SF or python.org # this test page depends on cookies, and an http-equiv refresh #cj = CreateBSDDBCookieJar("/home/john/db.db") cj = CookieJar() handlers = [ HTTPCookieProcessor(cj), HTTPRefreshProcessor(max_time=None, honor_time=False), HTTPEquivProcessor(), HTTPRedirectHandler(), # needed for Refresh handling in 2.4.0 # HTTPHandler(True), # HTTPRedirectDebugProcessor(), # HTTPResponseDebugProcessor(), ] o = apply(build_opener, handlers) try: install_opener(o) r = urlopen("http://boards.ign.com/help/cookie_test.asp") data = r.read() self.assert_( string.find(data, "Your browser supports cookies!") >= 0) self.assert_(len(cj) == 1) # test response.seek() (added by HTTPEquivProcessor) r.seek(0) samedata = r.read() r.close() self.assert_(samedata == data) finally: o.close() # uninstall opener (don't try this at home) ClientCookie._urllib2_support._opener = None
def test_clientcookie(self): # XXX set up test page on SF or python.org # this test page depends on cookies, and an http-equiv refresh # cj = CreateBSDDBCookieJar("/home/john/db.db") cj = CookieJar() handlers = [ HTTPCookieProcessor(cj), HTTPRefreshProcessor(max_time=None, honor_time=False), HTTPEquivProcessor(), HTTPRedirectHandler(), # needed for Refresh handling in 2.4.0 # HTTPHandler(True), # HTTPRedirectDebugProcessor(), # HTTPResponseDebugProcessor(), ] o = apply(build_opener, handlers) try: install_opener(o) try: r = urlopen("http://wwwsearch.sf.net/cgi-bin/cookietest.cgi") except urllib2.URLError, e: # print e.read() raise data = r.read() # print data self.assert_( string.find(data, "Your browser supports cookies!") >= 0) self.assert_(len(cj) == 1) # test response.seek() (added by HTTPEquivProcessor) r.seek(0) samedata = r.read() r.close() self.assert_(samedata == data)
def navigate(self, url): if type(url) in (str, unicode): url = self.baseurl + url self.cururl = url else: self.cururl = url.get_full_url() return urlopen(url)
def test_clientcookie(self): # XXX set up test page on SF or python.org # this test page depends on cookies, and an http-equiv refresh #cj = CreateBSDDBCookieJar("/home/john/db.db") cj = CookieJar() handlers = [ HTTPCookieProcessor(cj), HTTPRefreshProcessor(max_time=None, honor_time=False), HTTPEquivProcessor(), HTTPRedirectHandler(), # needed for Refresh handling in 2.4.0 # HTTPHandler(True), # HTTPRedirectDebugProcessor(), # HTTPResponseDebugProcessor(), ] o = apply(build_opener, handlers) try: install_opener(o) try: r = urlopen("http://wwwsearch.sf.net/cgi-bin/cookietest.cgi") except urllib2.URLError, e: #print e.read() raise data = r.read() #print data self.assert_( string.find(data, "Your browser supports cookies!") >= 0) self.assert_(len(cj) == 1) # test response.seek() (added by HTTPEquivProcessor) r.seek(0) samedata = r.read() r.close() self.assert_(samedata == data)
def test_urlretrieve(self): url = "http://www.python.org/" verif = CallbackVerifier(self) fn, hdrs = urlretrieve(url, "python.html", verif.callback) try: f = open(fn) data = f.read() f.close() finally: os.remove(fn) r = urlopen(url) self.assert_(data == r.read()) r.close()