Package httxlib :: Module httxrequest :: Class HttxRequest
[hide private]
[frames] | no frames]

Class HttxRequest

source code

urllib2.Request --+
                  |
                 HttxRequest

A subclass of urllib2 Request to retain compatibility and make it usable for cookies and whatever may be needed

Instance Methods [hide private]
 
__init__(self, url, data=None, headers=None, origin_req_host=None, unverifiable=False)
Constructor.
source code
bool
ispost(self)
Utility function to avoid cluttering external code with string comparisons
source code
bool
isget(self)
Utility function to avoid cluttering external code with string comparisons
source code
HttxRequest
clone(self, url=None)
Clone a request with a change of url to support redirection
source code
HttxRequest
__deepcopy__(self, memo)
Deepcopy support.
source code

Inherited from urllib2.Request: __getattr__, add_data, add_header, add_unredirected_header, get_data, get_full_url, get_header, get_host, get_method, get_origin_req_host, get_selector, get_type, has_data, has_header, has_proxy, header_items, is_unverifiable, set_proxy

Instance Variables [hide private]
namedtuple result of urlsplit (check the Python docs) parsed
It holds the result of the urlsplit(url) done in the constructor for practical purposes
Properties [hide private]
  allheaders
Property to return all the headers to be sent in a request
  method
Property to have a handy alias for Request.get_method
  scheme
Property to have a handy alias for Request.get_type or parsed.scheme
  netloc
Property to have a handy alias for Request.get_host or parsed.netloc
  body
Property to have a handy alias for Request.get_data
Method Details [hide private]

__init__(self, url, data=None, headers=None, origin_req_host=None, unverifiable=False)
(Constructor)

source code 

Constructor. It delegates construction to the base class Request and initializes the member variables

It performs an additional call of Request.get_type and Request.get_host to ensure that the Request object is properly initialized. Because this is done by the urllib2 library, but we are just using the request

Parameters:
  • url (str) - url to be requested in the HTTP request
  • data (str) - data for the HTTP request body (which enforces a POST)
  • headers (dict) - dictionary of header name/header value
  • origin_req_host (str) - request host of the origin transaction as per RFC 2965 - Host name or IP address of the host
  • unverifiable (bool) - if the request was not verified/requested by the end user and it is rather automatic (redirection, download of a picture inside a web page) - RFC 2965
Overrides: urllib2.Request.__init__

ispost(self)

source code 

Utility function to avoid cluttering external code with string comparisons

Returns: bool
if the request will be a POST request

isget(self)

source code 

Utility function to avoid cluttering external code with string comparisons

Returns: bool
if the request will be a GET request

clone(self, url=None)

source code 

Clone a request with a change of url to support redirection

By using the normal/unredirected header separation in Request it is easy to clone for a redirection by only supplying the new headers to the class

Parameters:
  • url (str|None) - url to redirect to if needed. Default of None for no redirection
Returns: HttxRequest
a cloned object

__deepcopy__(self, memo)

source code 

Deepcopy support.

Parameters:
  • memo (dict) - standard __deepcopy__ parameter to avoid circular references
Returns: HttxRequest
a cloned object

Property Details [hide private]

allheaders

Property to return all the headers to be sent in a request

urllib2 distinguishes amongst normal headers and headers that will not be used if the original request is redirected

Therefore it is impossible to request all headers in just one call

Although Request has a utility function, it returns a list of tuples rather than a dictionary

This property returns a dictionary

Get Method:
unreachable.allheaders(self) - Property to return all the headers to be sent in a request

method

Property to have a handy alias for Request.get_method

Get Method:
unreachable.method(self) - Property to have a handy alias for Request.get_method

scheme

Property to have a handy alias for Request.get_type or parsed.scheme

Get Method:
unreachable.scheme(self) - Property to have a handy alias for Request.get_type or parsed.scheme

netloc

Property to have a handy alias for Request.get_host or parsed.netloc

Get Method:
unreachable.netloc(self) - Property to have a handy alias for Request.get_host or parsed.netloc

body

Property to have a handy alias for Request.get_data

Get Method:
unreachable.body(self) - Property to have a handy alias for Request.get_data