/usr/lib/python2.7/dist-packages/restkit/__init__.py is in python-restkit 4.2.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | # -*- coding: utf-8 -
#
# This file is part of restkit released under the MIT license.
# See the NOTICE for more information.
from restkit.version import version_info, __version__
try:
from restkit.conn import Connection
from restkit.errors import ResourceNotFound, Unauthorized, RequestFailed,\
RedirectLimit, RequestError, InvalidUrl, ResponseError, ProxyError, \
ResourceError, ResourceGone
from restkit.client import Client, MAX_FOLLOW_REDIRECTS
from restkit.wrappers import Request, Response, ClientResponse
from restkit.resource import Resource
from restkit.filters import BasicAuth, OAuthFilter
except ImportError:
import traceback
traceback.print_exc()
import urlparse
import logging
LOG_LEVELS = {
"critical": logging.CRITICAL,
"error": logging.ERROR,
"warning": logging.WARNING,
"info": logging.INFO,
"debug": logging.DEBUG
}
def set_logging(level, handler=None):
"""
Set level of logging, and choose where to display/save logs
(file or standard output).
"""
if not handler:
handler = logging.StreamHandler()
loglevel = LOG_LEVELS.get(level, logging.INFO)
logger = logging.getLogger('restkit')
logger.setLevel(loglevel)
format = r"%(asctime)s [%(process)d] [%(levelname)s] %(message)s"
datefmt = r"%Y-%m-%d %H:%M:%S"
handler.setFormatter(logging.Formatter(format, datefmt))
logger.addHandler(handler)
def request(url, method='GET', body=None, headers=None, **kwargs):
"""Quick shortcut method to pass a request
Request parameters
------------------
- **url**: str, url string
- **method**: str, by default GET. http verbs
- **body**: the body, could be a string, an iterator or a file-like object
- **headers**: dict or list of tupple, http headers
Client parameters
-----------------
- **follow_redirect**: follow redirection, by default False
- **max_follow_redirect**: number of redirections available
- **filters** http filters to pass
- **decompress**: allows the client to decompress the response body
- ** max_status_line_garbage**: defines the maximum number of ignorable
lines before we expect a HTTP response's status line. With HTTP/1.1
persistent connections, the problem arises that broken scripts could
return a wrong Content-Length (there are more bytes sent than
specified). Unfortunately, in some cases, this cannot be detected after
the bad response, but only before the next one. So the client is abble
to skip bad lines using this limit. 0 disable garbage collection, None
means unlimited number of tries.
- **max_header_count**: determines the maximum HTTP header count allowed.
by default no limit.
- manager: the manager to use. By default we use the global one.
- **response_class**: the response class to use
- **timeout**: the default timeout of the connection (SO_TIMEOUT)
- **max_tries**: the number of tries before we give up a connection
- **wait_tries**: number of time we wait between each tries.
- **ssl_args**: ssl named arguments, See
http://docs.python.org/library/ssl.html informations
"""
# detect credentials from url
u = urlparse.urlparse(url)
if u.username is not None:
password = u.password or ""
filters = kwargs.get('filters') or []
url = urlparse.urlunparse((u.scheme, u.netloc.split("@")[-1],
u.path, u.params, u.query, u.fragment))
filters.append(BasicAuth(u.username, password))
kwargs['filters'] = filters
http_client = Client(**kwargs)
return http_client.request(url, method=method, body=body,
headers=headers)
|