Package httxlib :: Module httxconnection :: Class HttxConnection
[hide private]
[frames] | no frames]

Class HttxConnection

source code

           object --+        
                    |        
httxobject.HttxObject --+    
                        |    
        httxbase.HttxBase --+
                            |
                           HttxConnection

Connection connecting object. The HttxConnection is responsible for creating and managing an underlying httplib.HTTPConnection or a HTTPSxConnection (for HTTPS) to perform the actual connection

The creation of the underlying connection is based upon a dictionary holding the class types indexed by the connection scheme (http or https)

The connection handles automatically redirection, authentication (auth and digest) and decompression (gzip, bzip2, deflate)

The behaviour can be altered through by managing the options

Instance Methods [hide private]
 
__init__(self, url=None, **kwargs)
Constructor.
source code
HttxConnection
__deepcopy__(self, memo)
Deepcopy support.
source code
HttxConnection
clone(self, options=None)
Clone the object using the supplied options or a new set of options if given.
source code
 
reset(self)
Reset the conn instance variable to None (possibly after an exception happened) to allow the connection to re-issue a createconnection on "request"
source code
 
sslize(self, url)
Add the appropriate "certificates" and/or paths and options to an underlying https connection to allow it to successfully (and according to user request) execute
source code
 
doconnect(self)
Actual connection (with https certificate preparation)
source code
 
createconnection(self, url, sock=None, plaintunnel=False)
Helper function to enable delayed creation of the underlying connection if needed.
source code
 
tunnelconnect(self, httxreq, plaintunnel=False)
Tunnel a connection over CONNECT if needed and not already done and re-create the underlying connection to use the "CONNECT"ed tunnel
source code
 
tunnelsslize(self)
If the user has connected a tunnel manually and asked for "plain tunnel" the tunnel may still be wrapped by ssl manually
source code
opaque type for the caller (a Python sock)
request(self, httxreq)
Send the HttxRequest httxreq to the specified server inside the request It does so by creating a connection if needed, then setting headers with helper functions for ompression, cookies and authentication and then relaying the call to the underlying connection
source code
HttxResponse (compatible with httplib HTTPResponse)
getresponse(self, sock)
Recover a HttxResponse
source code
 
addcookies(self, httxreq)
Add a Cookie header to httxreq if needed It uses a urllib2 cookiejar from the options set
source code
 
adddecompress(self, httxreq)
Add a content-encoding header to httxreq if needed and set in the options
source code
 
addauth(self, httxreq)
Add a WWW-Authenticate or Proxy-Authenticate header to httxreq if needed and set in the options
source code
 
addkeepalive(self, httxreq)
Adds the Connection Keep-Alive header
source code
 
adduseragent(self, httxreq)
Adds the UserAgent header if needed to
source code
 
addcontent(self, httxreq)
Add headers to httxreq if data is transmitted, borrowed from urllib2.
source code
 
extractcookies(self, response)
Perform cookie extraction from a response into a urllib2 cookiejar in the options set
source code
 
decompress(self, response)
Perform body decompression if enabled by the options and present in the response
source code
 
tunneling(self, response)
Checks if a tunnel (CONNECT) request was in place and if it has been correctly established.
source code
HttxResponse
redirect(self, response)
Perform redirection if the response requests it and enabled by the options set
source code
HttxResponse
authenticate(self, response, plaintunnel=False)
Perform authentication if the response requests it and enabled by the options set
source code

Inherited from httxbase.HttxBase: add_ca_cert, add_cert_req, add_certkey, add_password, setdecompmethods, setoptions, setproxy, setuseragent, urlopen

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables [hide private]
dict connFactory = dict(http= HTTPConnection, https= HTTPSxConnection)
class variable holding the dictionary of connection classes used to instantiate connections
  tunnelFactory = dict(http= HTTPxTunneled, https= HTTPSxTunneled)
class variable holding the dictionary of connection classes used to instantiate tunneled connections
HttxConnection auxhttx
Reference to the auxiliary connection used for either authentication or rediretion if needed
httplib.HTTPConnection or HTTPSxConnection - subclass of httplib.HTTPSConnection conn
actual connection object
HttxRequest lastreq
Last HttxRequest request issued
namedtuple from urlsplit parsed
it holds the result of urlsplit(url) for practical purposes
int redircount
count of redirections so far performed
  timestamp
last time the connection was used @type int
str url
url used to set the net location to which connections will connect

Inherited from httxbase.HttxBase: options

Inherited from httxobject.HttxObject: lock

Properties [hide private]
  sock
Property to support easy and quick access to the underlying sock object from the underlying connection.

Inherited from object: __class__

Method Details [hide private]

__init__(self, url=None, **kwargs)
(Constructor)

source code 

Constructor. It delegates construction to the base class HttxBase and initializes the member variables with the help of the createconnection method

Parameters:
  • kwargs - keywords arguments passed to HttxBase
Overrides: object.__init__

See Also: HttxOptions

__deepcopy__(self, memo)

source code 

Deepcopy support.

Parameters:
  • memo (dict @see clone) - standard __deepcopy__ parameter to avoid circular references
Returns: HttxConnection
a cloned object

clone(self, options=None)

source code 

Clone the object using the supplied options or a new set of options if given.

An equivalente set of HttxConnection objects will be replicated

A new set of options will separate the clone object from the original object, since they will no longer share cookies, user/password/realm combinations or https certificates

To support a maximum redirection count, a redircount parameter is passed along during the construction of the clone

Parameters:
  • options (HttxOptions) - options for the cloned object
Returns: HttxConnection
a cloned object

sslize(self, url)

source code 

Add the appropriate "certificates" and/or paths and options to an underlying https connection to allow it to successfully (and according to user request) execute

Parameters:
  • url (str) - url that contains the domain to use to pull certificate from the store

createconnection(self, url, sock=None, plaintunnel=False)

source code 

Helper function to enable delayed creation of the underlying connection if needed. Called from the __init__ and from request in order to ensure an underlying connection is created or recreated if tunneling

It initializes the member variables: url, parsed, conn, clock

In the case of https connections it will also set variables in the underlying connection object to ensure certificates and validation are used if requested and appropriate for the domain

Parameters:
  • url (str) - url to open a connection to
  • sock (socket (Default: None)) - socket for a tunneled connection
  • plaintunnel (bool (Default: False)) - if tunnel should not be sslized (connections are fake that do nothing or ssl_wrap)

tunnelconnect(self, httxreq, plaintunnel=False)

source code 

Tunnel a connection over CONNECT if needed and not already done and re-create the underlying connection to use the "CONNECT"ed tunnel

Parameters:
  • httxreq (HttxRequest or url (string)) - Request or url to be executed
  • plaintunnel (bool (Default: False)) - if tunnel should not be sslized (connections are fake that do nothing or ssl_wrap)

request(self, httxreq)

source code 

Send the HttxRequest httxreq to the specified server inside the request It does so by creating a connection if needed, then setting headers with helper functions for ompression, cookies and authentication and then relaying the call to the underlying connection

Parameters:
  • httxreq (HttxRequest or url (string)) - Request or url to be executed
Returns: opaque type for the caller (a Python sock)
sock
Overrides: httxbase.HttxBase.request

getresponse(self, sock)

source code 

Recover a HttxResponse

The sock parameter is not used but the function follows the abstract definition of HttxBase and the implementations of HttxManager and HttxNetLocation

Checks for authentication requests or redirectionare made. If the options allow to process those requests, new requests (with potentially new connections) are launched and the connection is marked as active to avoid any other part of the library to reuse it

Decompression of content and cookie extraction is also performed

Parameters:
  • sock (opaque (a Python sock)) - The opaque type returned by request
Returns: HttxResponse (compatible with httplib HTTPResponse)
response
Overrides: httxbase.HttxBase.getresponse

addcookies(self, httxreq)

source code 

Add a Cookie header to httxreq if needed It uses a urllib2 cookiejar from the options set

Parameters:

adddecompress(self, httxreq)

source code 

Add a content-encoding header to httxreq if needed and set in the options

Parameters:

addauth(self, httxreq)

source code 

Add a WWW-Authenticate or Proxy-Authenticate header to httxreq if needed and set in the options

It uses a HttxAuthCache from the options

Parameters:

addkeepalive(self, httxreq)

source code 

Adds the Connection Keep-Alive header

Parameters:

adduseragent(self, httxreq)

source code 

Adds the UserAgent header if needed to

Parameters:

addcontent(self, httxreq)

source code 

Add headers to httxreq if data is transmitted, borrowed from urllib2.

Parameters:

extractcookies(self, response)

source code 

Perform cookie extraction from a response into a urllib2 cookiejar in the options set

Parameters:

decompress(self, response)

source code 

Perform body decompression if enabled by the options and present in the response

Parameters:

tunneling(self, response)

source code 

Checks if a tunnel (CONNECT) request was in place and if it has been correctly established.

If so, it will reissue the original request, cleaning proxy authorization headers if they existed

Parameters:

redirect(self, response)

source code 

Perform redirection if the response requests it and enabled by the options set

Parameters:
Returns: HttxResponse
The same response with a new sock if redirection is done to an external site

authenticate(self, response, plaintunnel=False)

source code 

Perform authentication if the response requests it and enabled by the options set

Parameters:
Returns: HttxResponse
The same response preocessed

Property Details [hide private]

sock

Property to support easy and quick access to the underlying sock object from the underlying connection.

The sock object is used in the library to index active connections in cache

Get Method:
unreachable.sock(self) - Property to support easy and quick access to the underlying sock object from the underlying connection.