t0mm0.common.net

class t0mm0.common.net.Net(cookie_file='', proxy='', user_agent='', http_debug=False)[source]

This class wraps urllib2 and provides an easy way to make http requests while taking care of cookies, proxies, gzip compression and character encoding.

Example:

from t0mm0.common.net import Net
net = Net()
response = net.http_GET('http://xbmc.org')
print response.content
Kwargs:

cookie_file (str): Full path to a file to be used to load and save cookies to.

proxy (str): Proxy setting (eg. 'http://user:pass@example.com:1234')

user_agent (str): String to use as the User Agent header. If not supplied the class will use a default user agent (chrome)

http_debug (bool): Set True to have HTTP header info written to the XBMC log for all requests.

get_cookies()[source]

Returns A dictionary containing all cookie information by domain.

get_proxy()[source]

Returns string containing proxy details.

get_user_agent()[source]

Returns user agent string.

http_GET(url, headers={}, compression=True)[source]

Perform an HTTP GET request.

Args:
url (str): The URL to GET.
Kwargs:

headers (dict): A dictionary describing any headers you would like to add to the request. (eg. {'X-Test': 'testing'})

compression (bool): If True (default), try to use gzip compression.

Returns:
An HttpResponse object containing headers and other meta-information about the page and the page content.
http_HEAD(url, headers={})[source]

Perform an HTTP HEAD request.

Args:
url (str): The URL to GET.
Kwargs:
headers (dict): A dictionary describing any headers you would like to add to the request. (eg. {'X-Test': 'testing'})
Returns:
An HttpResponse object containing headers and other meta-information about the page.
http_POST(url, form_data, headers={}, compression=True)[source]

Perform an HTTP POST request.

Args:

url (str): The URL to POST.

form_data (dict): A dictionary of form data to POST.

Kwargs:

headers (dict): A dictionary describing any headers you would like to add to the request. (eg. {'X-Test': 'testing'})

compression (bool): If True (default), try to use gzip compression.

Returns:
An HttpResponse object containing headers and other meta-information about the page and the page content.
save_cookies(cookie_file)[source]

Saves cookies to a file.

Args:
cookie_file (str): Full path to a file to save cookies to.
set_cookies(cookie_file)[source]

Set the cookie file and try to load cookies from it if it exists.

Args:
cookie_file (str): Full path to a file to be used to load and save cookies to.
set_proxy(proxy)[source]
Args:
proxy (str): Proxy setting (eg. 'http://user:pass@example.com:1234')
set_user_agent(user_agent)[source]
Args:
user_agent (str): String to use as the User Agent header.
class t0mm0.common.net.HttpResponse(response)[source]

This class represents a resoponse from an HTTP request.

The content is examined and every attempt is made to properly encode it to Unicode.

Args:
response (mimetools.Message): The object returned by a call to urllib2.urlopen().
content

Unicode encoded string containing the body of the reposne.

get_headers()[source]

Returns a List of headers returned by the server.

get_url()[source]

Return the URL of the resource retrieved, commonly used to determine if a redirect was followed.

Previous topic

t0mm0.common.addon

Next topic

script.module.urlresolver Documentation

This Page