Automatically exported from code.google.com/p/planningalerts
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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