OPSI.Util.HTTP module

opsi python library - HTTP

New in version 4.0.6.9: Added functions deflateEncode(), deflateDecode(), gzipEncode() and gzipDecode().

author:Jan Schneider <j.schneider@uib.de>
author:Niko Wenselowski <n.wenselowski@uib.de>
author:Erol Ueluekmen <e.ueluekmen@uib.de>
license:GNU Affero General Public License version 3
class OPSI.Util.HTTP.HTTPConnectionPool(host, port, socketTimeout=None, connectTimeout=None, retryTime=0, maxsize=1, block=False, reuseConnection=False, verifyServerCert=False, serverCertFile=None, caCertFile=None, verifyServerCertByCa=False, proxyURL=None)

Bases: object

adjustSize(maxsize)
decreaseUsageCount()
delPool()
endConnection(conn)
free()
getConnection()
getPeerCertificate(asPem=False)
get_host(url)
increaseUsageCount()
is_same_host(url)
scheme = 'http'
urlopen(method, url, body=None, headers={}, retry=True, redirect=True, assert_same_host=True, firstTryTime=None)

Get a connection from the pool and perform an HTTP request.

method
HTTP request method (such as GET, POST, PUT, etc.)
body
Data to send in the request body (useful for creating POST requests, see HTTPConnectionPool.post_url for more convenience).
headers
Custom headers to send (such as User-Agent, If-None-Match, etc.)
retry
Retry on connection failure in between self.retryTime seconds
redirect
Automatically handle redirects (status codes 301, 302, 303, 307), each redirect counts as a retry.
exception OPSI.Util.HTTP.HTTPError

Bases: exceptions.Exception

Base exception used by this module.

class OPSI.Util.HTTP.HTTPResponse(data='', headers={}, status=0, version=0, reason=None, strict=0)

Bases: object

HTTP Response container.

Similar to httplib’s HTTPResponse but the data is pre-loaded.

addData(data)
curlHeader(header)
static from_httplib(r)

Given an httplib.HTTPResponse instance, return a corresponding urllib3.HTTPResponse object.

NOTE: This method will perform r.read() which will have side effects on the original http.HTTPResponse object.

getheader(name, default=None)
getheaders()
class OPSI.Util.HTTP.HTTPSConnectionPool(host, port, socketTimeout=None, connectTimeout=None, retryTime=0, maxsize=1, block=False, reuseConnection=False, verifyServerCert=False, serverCertFile=None, caCertFile=None, verifyServerCertByCa=False, proxyURL=None)

Bases: OPSI.Util.HTTP.HTTPConnectionPool

Same as HTTPConnectionPool, but HTTPS.

scheme = 'https'
exception OPSI.Util.HTTP.HostChangedError

Bases: OPSI.Util.HTTP.HTTPError

Raised when an existing pool gets a request for a foreign host.

exception OPSI.Util.HTTP.TimeoutError

Bases: OPSI.Util.HTTP.HTTPError

Raised when a socket timeout occurs.

OPSI.Util.HTTP.closeConnection(connection)

Close the given connection and any socket that may be open on it.

OPSI.Util.HTTP.closingConnection(*args, **kwds)

This contextmanager closes the connection afterwards.

OPSI.Util.HTTP.deflateDecode(data)
OPSI.Util.HTTP.deflateEncode(data, level=1)
OPSI.Util.HTTP.destroyPool(pool)
OPSI.Util.HTTP.getPeerCertificate(httpsConnectionOrSSLSocket, asPEM=True)
OPSI.Util.HTTP.getSharedConnectionPool(scheme, host, port, **kw)
OPSI.Util.HTTP.getSharedConnectionPoolFromUrl(url, **kw)

Given a url, return an HTTP(S)ConnectionPool instance of its host.

This is a shortcut for not having to determine the host of the url before creating an HTTP(S)ConnectionPool instance.

Passes on whatever kw arguments to the constructor of HTTP(S)ConnectionPool. (e.g. timeout, maxsize, block)

OPSI.Util.HTTP.gzipDecode(data)
OPSI.Util.HTTP.gzipEncode(data, level=1)
OPSI.Util.HTTP.hybi10Decode(data)
OPSI.Util.HTTP.hybi10Encode(data)
OPSI.Util.HTTP.non_blocking_connect_http(self, connectTimeout=0)

Non blocking connect, needed for KillableThread

OPSI.Util.HTTP.non_blocking_connect_https(self, connectTimeout=0, verifyByCaCertsFile=None)
OPSI.Util.HTTP.urlsplit(url)