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