SimpleHttpFetch (version 4.0.0)

# Copyright (c) 2015-2016 Tim Savannah under terms of LGPLv2.
#
#  SimpleHttpFetch supports through the most simple interface possible fetching of URLs as strings or JSON as dict

 
Package Contents
       

 
Classes
       
exceptions.Exception(exceptions.BaseException)
SimpleHttpFetchBadStatus
SimpleHttpFetchTooManyRedirects

 
class SimpleHttpFetchBadStatus(exceptions.Exception)
    Exception that is raised when a non-200 (Success) code is received from upstream server. This is not including 301 (redirects).
 
Has a member "statusCode" which will list the status code returned.
 
 
Method resolution order:
SimpleHttpFetchBadStatus
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, msg, statusCode=None, reason=None)

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class SimpleHttpFetchTooManyRedirects(exceptions.Exception)
    Too many redirects have been followed and we've given up. The message will contain after the first newline character the list of urls fetched.
 
 
Method resolution order:
SimpleHttpFetchTooManyRedirects
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, urls)

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
Functions
       
fetchUrl(url, httpMethod='GET', userAgent='SimpleHttpFetch 4.0.0', defaultEncoding='utf-8', headers=None)
fetchUrl - Fetches the contents of a url.
 
Will follow redirects via Location header or 301 status.
 
@param httpMethod <str> - HTTP Method (default GET)
@param userAgent <str>  - User agent to provide, defaults to SimpleHttpFetch <version>
@param defaultEncoding <str> - default utf-8. Encoding to use if one is not specified in headers. If set to "nodecode", the results will not be decoded regardless of headers (use for binary data)
@param headers <None/dict> - overrides to default headers to send. keys is header name, value is header value.
 
@return <str> - Web page contents
 
@raises SimpleHttpFetchBadStatus If page does not return status 200 (success)
fetchUrlAsJson(url, httpMethod='GET', userAgent='SimpleHttpFetch 4.0.0', defaultEncoding='utf-8', headers=None)
fetchUrl - Fetches the contents of a url and converts the JSON to a python dictionary.
 
Will follow redirects via Location header or 301 status.
 
@param httpMethod <str> - HTTP Method (default GET)
@param userAgent <str>  - User agent to provide, defaults to SimpleHttpFetch <version>
@param defaultEncoding <str> - default utf-8. Encoding to use if one is not specified in headers. If set to "nodecode", the results will not be decoded regardless of headers (use for binary data)
@param headers <None/dict> - overrides to default headers to send. keys is header name, value is header value.
 
@return <dict> - Dictionary of parsed JSON on page
 
@raises ValueError if webpage contents are not JSON-compatible
@raises SimpleHttpFetchBadStatus If page does not return status 200 (success)
fetchUrlRaw(url, httpMethod='GET', userAgent='SimpleHttpFetch 4.0.0', headers=None)
fetchUrlRaw - Fetches the contents of a url without decoding the data.
 
Will follow redirects via Location header or 301 status.
 
@param httpMethod <str> - HTTP Method (default GET)
@param userAgent <str>  - User agent to provide, defaults to SimpleHttpFetch <version>
@param headers <None/dict> - overrides to default headers to send. keys is header name, value is header value.
 
@return <bytes> - Web page contents, unencoded.
 
@raises SimpleHttpFetchBadStatus If page does not return status 200 (success)
getConnection(url)
getConnection - Get a connection object given a url. Supports http and https
 
@return - Connection
getRequestData(connection, url, httpMethod='GET', userAgent='SimpleHttpFetch 4.0.0', defaultEncoding='utf-8', headers=None, _depth=None)
getRequestData - Given a connection, fetch a URL and return a string of the contents. Use this to make multiple requests instead of fetchUrl to the same server, as it allows you to reuse a connection.
 
Will follow redirects via Location header or 301 status.
 
@param connection <obj> - return of getConnection function
@parma url <str> - Url to fetch
@param httpMethod <str> - An http method. Probably GET.
@param userAgent <str>  - Your user agent. Defaults to SimpleHttpFetch <version>
@param defaultEncoding <str> - default utf-8. Encoding to use if one is not specified in headers. If set to "nodecode", the results will not be decoded regardless of headers (use for binary data)
@param headers <None/dict> - overrides to default headers to send. keys is header name, value is header value
@param _depth <None/list> - If you pass in a list, you can check that list after the call (the function will modify it) to see if any redirects (301's) were followed. Each url fetched will have an entry, so len(_depth) == 1 means no redirects were followed.
 
@return <str> - Web page contents
 
@raises SimpleHttpFetchBadStatus If page does not return status 200 (success)
getRequestDataAsJson(connection, url, httpMethod='GET', userAgent='SimpleHttpFetch 4.0.0', defaultEncoding='utf-8', headers=None)
getRequestDataAsJson - Given a connection, fetch a URL and return a string of the contents. Use this to make multiple requests to the same server instead of fetchUrlAsJson, as it allows you to reuse a connection.
 
Will follow relative redirects via Location header or 301 status.
 
@param connection <obj> - Return of getConnection function
@param url <str> - Url to fetch
@param httpMethod <str> - An http method. Probably GET.
@param userAgent <str> - Your user agent. Defaults to SimpleHttpFetch <version>
@param defaultEncoding <str> - default utf-8. Encoding to use if one is not specified in headers. If set to "nodecode", the results will not be decoded regardless of headers (use for binary data)
@param headers <None/dict> - overrides to default headers to send. keys is header name, value is header value.
 
@return <dict> - Dictionary of parsed JSON on page
 
@raises ValueError if webpage contents are not JSON-compatible
@raises SimpleHttpFetchBadStatus If page does not return status 200 (success)
parseURL(url)
parseURL - parses a url and returns a dictionary containing the pieces of information
 
@param url <string> - A full URL (ex: http://www.example.com/test)
 
@return - Dictionary describing url. Keys are:
    protocol <string> - http or https
    domain   <string> - host domain/server (ex: example.com)
    port     <int>    - TCP Port for request
    rel_uri  <string> - Relative URI of request (ex: /index.html)

 
Data
        __all__ = ('SimpleHttpFetchBadStatus', 'SimpleHttpFetchTooManyRedirects', 'parseURL', 'getConnection', 'getRequestData', 'getRequestDataAsJson', 'fetchUrl', 'fetchUrlAsJson', 'fetchUrlRaw')
__version__ = '4.0.0'
__version_tuple__ = (4, 0, 0)