Automatically exported from code.google.com/p/planningalerts
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

19 satır
649 B

  1. from urllib2 import HTTPRedirectHandler
  2. class CookieAddingHTTPRedirectHandler(HTTPRedirectHandler):
  3. """The standard python HttpRedirectHandler doesn't add a cookie to the new request after a 302. This handler does."""
  4. def __init__(self, cookie_jar):
  5. self.cookie_jar = cookie_jar
  6. # This really ought to call the superclasses init method, but there doesn't seem to be one.
  7. def redirect_request(self, *args):
  8. new_request = HTTPRedirectHandler.redirect_request(self, *args)
  9. # We need to add a cookie from the cookie_jar
  10. self.cookie_jar.add_cookie_header(new_request)
  11. return new_request