Automatically exported from code.google.com/p/planningalerts
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HTTPHandlers.py 649 B

123456789101112131415161718
  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