source: py-scraping/mechanize/_upgrade.py@ 162

Last change on this file since 162 was 106, checked in by Rick van der Zwet, 15 years ago

Initial commit...

File size: 1.3 KB
Line 
1from urllib2 import BaseHandler
2
3from _request import Request
4from _response import upgrade_response
5from _util import deprecation
6
7
8class HTTPRequestUpgradeProcessor(BaseHandler):
9 # upgrade urllib2.Request to this module's Request
10 # yuck!
11 handler_order = 0 # before anything else
12
13 def http_request(self, request):
14 if not hasattr(request, "add_unredirected_header"):
15 newrequest = Request(request.get_full_url(), request.data,
16 request.headers)
17 try: newrequest.origin_req_host = request.origin_req_host
18 except AttributeError: pass
19 try: newrequest.unverifiable = request.unverifiable
20 except AttributeError: pass
21 try: newrequest.visit = request.visit
22 except AttributeError: pass
23 request = newrequest
24 return request
25
26 https_request = http_request
27
28
29class ResponseUpgradeProcessor(BaseHandler):
30 # upgrade responses to be .close()able without becoming unusable
31 handler_order = 0 # before anything else
32
33 def __init__(self):
34 deprecation(
35 "See http://wwwsearch.sourceforge.net/mechanize/doc.html#seekable")
36
37 def any_response(self, request, response):
38 if not hasattr(response, 'closeable_response'):
39 response = upgrade_response(response)
40 return response
Note: See TracBrowser for help on using the repository browser.