Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
test.test_urllib2.MockHTTPSHandler Class Reference
Inheritance diagram for test.test_urllib2.MockHTTPSHandler:
Inheritance graph
[legend]
Collaboration diagram for test.test_urllib2.MockHTTPSHandler:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def https_open
def set_http_debuglevel
def do_request_
def do_open
def add_parent
def close
def __lt__

Public Attributes

 httpconn
 parent

Static Public Attributes

int handler_order = 500

Detailed Description

Definition at line 430 of file test_urllib2.py.


Constructor & Destructor Documentation

Definition at line 434 of file test_urllib2.py.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

def urllib.request.BaseHandler.__lt__ (   self,
  other 
) [inherited]

Definition at line 467 of file request.py.

00467 
00468     def __lt__(self, other):
00469         if not hasattr(other, "handler_order"):
00470             # Try to preserve the old behavior of having custom classes
00471             # inserted after default ones (works only for custom user
00472             # classes which are not aware of handler_order).
00473             return True
00474         return self.handler_order < other.handler_order
00475 

def urllib.request.BaseHandler.add_parent (   self,
  parent 
) [inherited]

Definition at line 460 of file request.py.

00460 
00461     def add_parent(self, parent):
00462         self.parent = parent

def urllib.request.BaseHandler.close (   self) [inherited]

Definition at line 463 of file request.py.

00463 
00464     def close(self):
00465         # Only exists for backwards compatibility
00466         pass

Here is the caller graph for this function:

def urllib.request.AbstractHTTPHandler.do_open (   self,
  http_class,
  req,
  http_conn_args 
) [inherited]
Return an HTTPResponse object for the request, using http_class.

http_class must implement the HTTPConnection API from http.client.

Definition at line 1097 of file request.py.

01097 
01098     def do_open(self, http_class, req, **http_conn_args):
01099         """Return an HTTPResponse object for the request, using http_class.
01100 
01101         http_class must implement the HTTPConnection API from http.client.
01102         """
01103         host = req.host
01104         if not host:
01105             raise URLError('no host given')
01106 
01107         # will parse host:port
01108         h = http_class(host, timeout=req.timeout, **http_conn_args)
01109 
01110         headers = dict(req.unredirected_hdrs)
01111         headers.update(dict((k, v) for k, v in req.headers.items()
01112                             if k not in headers))
01113 
01114         # TODO(jhylton): Should this be redesigned to handle
01115         # persistent connections?
01116 
01117         # We want to make an HTTP/1.1 request, but the addinfourl
01118         # class isn't prepared to deal with a persistent connection.
01119         # It will try to read all remaining data from the socket,
01120         # which will block while the server waits for the next request.
01121         # So make sure the connection gets closed after the (only)
01122         # request.
01123         headers["Connection"] = "close"
01124         headers = dict((name.title(), val) for name, val in headers.items())
01125 
01126         if req._tunnel_host:
01127             tunnel_headers = {}
01128             proxy_auth_hdr = "Proxy-Authorization"
01129             if proxy_auth_hdr in headers:
01130                 tunnel_headers[proxy_auth_hdr] = headers[proxy_auth_hdr]
01131                 # Proxy-Authorization should not be sent to origin
01132                 # server.
01133                 del headers[proxy_auth_hdr]
01134             h.set_tunnel(req._tunnel_host, headers=tunnel_headers)
01135 
01136         try:
01137             h.request(req.get_method(), req.selector, req.data, headers)
01138         except socket.error as err: # timeout error
01139             h.close()
01140             raise URLError(err)
01141         else:
01142             r = h.getresponse()
01143 
01144         r.url = req.get_full_url()
01145         # This line replaces the .msg attribute of the HTTPResponse
01146         # with .headers, because urllib clients expect the response to
01147         # have the reason in .msg.  It would be good to mark this
01148         # attribute is deprecated and get then to use info() or
01149         # .headers.
01150         r.msg = r.reason
01151         return r
01152 

Here is the caller graph for this function:

def urllib.request.AbstractHTTPHandler.do_request_ (   self,
  request 
) [inherited]

Definition at line 1058 of file request.py.

01058 
01059     def do_request_(self, request):
01060         host = request.host
01061         if not host:
01062             raise URLError('no host given')
01063 
01064         if request.data is not None:  # POST
01065             data = request.data
01066             if isinstance(data, str):
01067                 raise TypeError("POST data should be bytes"
01068                         " or an iterable of bytes. It cannot be str.")
01069             if not request.has_header('Content-type'):
01070                 request.add_unredirected_header(
01071                     'Content-type',
01072                     'application/x-www-form-urlencoded')
01073             if not request.has_header('Content-length'):
01074                 try:
01075                     mv = memoryview(data)
01076                 except TypeError:
01077                     if isinstance(data, collections.Iterable):
01078                         raise ValueError("Content-Length should be specified "
01079                                 "for iterable data of type %r %r" % (type(data),
01080                                 data))
01081                 else:
01082                     request.add_unredirected_header(
01083                             'Content-length', '%d' % (len(mv) * mv.itemsize))
01084 
01085         sel_host = host
01086         if request.has_proxy():
01087             scheme, sel = splittype(request.selector)
01088             sel_host, sel_path = splithost(sel)
01089         if not request.has_header('Host'):
01090             request.add_unredirected_header('Host', sel_host)
01091         for name, value in self.parent.addheaders:
01092             name = name.capitalize()
01093             if not request.has_header(name):
01094                 request.add_unredirected_header(name, value)
01095 
01096         return request

Here is the call graph for this function:

Definition at line 438 of file test_urllib2.py.

00438 
00439     def https_open(self, req):
00440         return self.do_open(self.httpconn, req)

Here is the call graph for this function:

def urllib.request.AbstractHTTPHandler.set_http_debuglevel (   self,
  level 
) [inherited]

Definition at line 1055 of file request.py.

01055 
01056     def set_http_debuglevel(self, level):
01057         self._debuglevel = level


Member Data Documentation

int urllib.request.BaseHandler.handler_order = 500 [static, inherited]

Definition at line 436 of file test_urllib2.py.

Definition at line 461 of file request.py.


The documentation for this class was generated from the following file: