The branch, frodo has been updated
       via  14688290167730fea4f17520ec009350a201115a (commit)
      from  2db85939212f142d4569c25fae8ed657d3dd1d95 (commit)

- Log -----------------------------------------------------------------
http://xbmc.git.sourceforge.net/git/gitweb.cgi?p=xbmc/scripts;a=commit;h=14688290167730fea4f17520ec009350a201115a

commit 14688290167730fea4f17520ec009350a201115a
Author: beenje <[email protected]>
Date:   Mon Feb 25 21:40:46 2013 +0100

    [script.module.requests] updated to version 1.1.0

diff --git a/script.module.requests/addon.xml b/script.module.requests/addon.xml
index f0c1c03..62b9b6e 100644
--- a/script.module.requests/addon.xml
+++ b/script.module.requests/addon.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <addon id="script.module.requests"
        name="requests"
-       version="1.0.4"
+       version="1.1.0"
        provider-name="kennethreitz">
   <requires>
     <import addon="xbmc.python" version="2.1.0"/>
@@ -13,5 +13,6 @@
     <description>Packed for XBMC from 
https://github.com/kennethreitz/requests</description>
     <license>Apache</license>
     <platform>all</platform>
+    <source>https://github.com/beenje/script.module.requests</source>
   </extension>
 </addon>
diff --git a/script.module.requests/lib/AUTHORS.rst 
b/script.module.requests/lib/AUTHORS.rst
index acc78e8..1244588 100644
--- a/script.module.requests/lib/AUTHORS.rst
+++ b/script.module.requests/lib/AUTHORS.rst
@@ -118,3 +118,4 @@ Patches and Suggestions
 - Martijn Pieters
 - Jonatan Heyman
 - David Bonner <[email protected]> @rascalking
+- Vinod Chandru
diff --git a/script.module.requests/lib/HISTORY.rst 
b/script.module.requests/lib/HISTORY.rst
index 7586ed0..a3491a1 100644
--- a/script.module.requests/lib/HISTORY.rst
+++ b/script.module.requests/lib/HISTORY.rst
@@ -3,6 +3,15 @@
 History
 -------
 
+1.1.0 (2013-01-10)
+++++++++++++++++++
+
+- CHUNKED REQUESTS
+- Support for iterable response bodies
+- Assume servers persist redirect params
+- Allow explicit content types to be specified for file data
+- Make merge_kwargs case-insensitive when looking up keys
+
 1.0.3 (2012-12-18)
 ++++++++++++++++++
 
diff --git a/script.module.requests/lib/LICENSE.txt 
b/script.module.requests/lib/LICENSE.txt
index ed50ab0..ca97ae0 100644
--- a/script.module.requests/lib/LICENSE.txt
+++ b/script.module.requests/lib/LICENSE.txt
@@ -1,4 +1,4 @@
-Copyright 2012 Kenneth Reitz
+Copyright 2013 Kenneth Reitz
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -10,4 +10,4 @@ Copyright 2012 Kenneth Reitz
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
-   limitations under the License.
\ No newline at end of file
+   limitations under the License.
diff --git a/script.module.requests/lib/requests/__init__.py 
b/script.module.requests/lib/requests/__init__.py
index ef34a74..7ea7e62 100644
--- a/script.module.requests/lib/requests/__init__.py
+++ b/script.module.requests/lib/requests/__init__.py
@@ -36,17 +36,17 @@ usage:
 The other HTTP methods are supported - see `requests.api`. Full documentation
 is at <http://python-requests.org>.
 
-:copyright: (c) 2012 by Kenneth Reitz.
+:copyright: (c) 2013 by Kenneth Reitz.
 :license: Apache 2.0, see LICENSE for more details.
 
 """
 
 __title__ = 'requests'
-__version__ = '1.0.4'
-__build__ = 0x01004
+__version__ = '1.1.0'
+__build__ = 0x010100
 __author__ = 'Kenneth Reitz'
 __license__ = 'Apache 2.0'
-__copyright__ = 'Copyright 2012 Kenneth Reitz'
+__copyright__ = 'Copyright 2013 Kenneth Reitz'
 
 
 from . import utils
diff --git a/script.module.requests/lib/requests/adapters.py 
b/script.module.requests/lib/requests/adapters.py
index 44e0786..5f9d9c7 100644
--- a/script.module.requests/lib/requests/adapters.py
+++ b/script.module.requests/lib/requests/adapters.py
@@ -12,9 +12,11 @@ import socket
 
 from .models import Response
 from .packages.urllib3.poolmanager import PoolManager, proxy_from_url
+from .packages.urllib3.response import HTTPResponse
 from .hooks import dispatch_hook
-from .compat import urlparse, basestring
-from .utils import DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers
+from .compat import urlparse, basestring, urldefrag
+from .utils import (DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers,
+                    prepend_scheme_if_needed)
 from .structures import CaseInsensitiveDict
 from .packages.urllib3.exceptions import MaxRetryError
 from .packages.urllib3.exceptions import TimeoutError
@@ -93,6 +95,7 @@ class HTTPAdapter(BaseAdapter):
         # Set encoding.
         response.encoding = get_encoding_from_headers(response.headers)
         response.raw = resp
+        response.reason = response.raw.reason
 
         if isinstance(req.url, bytes):
             response.url = req.url.decode('utf-8')
@@ -116,6 +119,7 @@ class HTTPAdapter(BaseAdapter):
         proxy = proxies.get(urlparse(url).scheme)
 
         if proxy:
+            proxy = prepend_scheme_if_needed(proxy, urlparse(url).scheme)
             conn = proxy_from_url(proxy)
         else:
             conn = self.poolmanager.connection_from_url(url)
@@ -130,27 +134,73 @@ class HTTPAdapter(BaseAdapter):
         """
         self.poolmanager.clear()
 
+    def request_url(self, request, proxies):
+        """Obtain the url to use when making the final request.
+
+        If the message is being sent through a proxy, the full URL has to be
+        used. Otherwise, we should only use the path portion of the URL."""
+        proxies = proxies or {}
+        proxy = proxies.get(urlparse(request.url).scheme)
+
+        if proxy:
+            url, _ = urldefrag(request.url)
+        else:
+            url = request.path_url
+
+        return url
+
     def send(self, request, stream=False, timeout=None, verify=True, 
cert=None, proxies=None):
         """Sends PreparedRequest object. Returns Response object."""
 
         conn = self.get_connection(request.url, proxies)
 
         self.cert_verify(conn, request.url, verify, cert)
+        url = self.request_url(request, proxies)
+
+        chunked = not (request.body is None or 'Content-Length' in 
request.headers)
 
         try:
+            if not chunked:
+                resp = conn.urlopen(
+                    method=request.method,
+                    url=url,
+                    body=request.body,
+                    headers=request.headers,
+                    redirect=False,
+                    assert_same_host=False,
+                    preload_content=False,
+                    decode_content=False,
+                    retries=self.max_retries,
+                    timeout=timeout
+                )
+
             # Send the request.
-            resp = conn.urlopen(
-                method=request.method,
-                url=request.path_url,
-                body=request.body,
-                headers=request.headers,
-                redirect=False,
-                assert_same_host=False,
-                preload_content=False,
-                decode_content=False,
-                retries=self.max_retries,
-                timeout=timeout,
-            )
+            else:
+                if hasattr(conn, 'proxy_pool'):
+                    conn = conn.proxy_pool
+
+                low_conn = conn._get_conn(timeout=timeout)
+                low_conn.putrequest(request.method, url, 
skip_accept_encoding=True)
+
+                for header, value in request.headers.items():
+                    low_conn.putheader(header, value)
+
+                low_conn.endheaders()
+
+                for i in request.body:
+                    low_conn.send(hex(len(i))[2:].encode('utf-8'))
+                    low_conn.send(b'\r\n')
+                    low_conn.send(i)
+                    low_conn.send(b'\r\n')
+                low_conn.send(b'0\r\n\r\n')
+
+                r = low_conn.getresponse()
+                resp = HTTPResponse.from_httplib(r,
+                    pool=conn,
+                    connection=low_conn,
+                    preload_content=False,
+                    decode_content=False
+                )
 
         except socket.error as sockerr:
             raise ConnectionError(sockerr)
diff --git a/script.module.requests/lib/requests/certs.py 
b/script.module.requests/lib/requests/certs.py
index 42df2f8..8148276 100644
--- a/script.module.requests/lib/requests/certs.py
+++ b/script.module.requests/lib/requests/certs.py
@@ -2,26 +2,30 @@
 # -*- coding: utf-8 -*-
 
 """
-ceritfi.py
-~~~~~~~~~~
+certs.py
+~~~~~~~~
 
-This module returns the installation location of cacert.pem.
+This module returns the preferred default CA certificate bundle.
+
+If you are packaging Requests, e.g., for a Linux distribution or a managed
+environment, you can change the definition of where() to return a separately
+packaged CA bundle.
 """
 
-import os
+import os.path
+
+certifi = None
 try:
     import certifi
 except ImportError:
-    certifi = None
-
+    pass
 
 def where():
-
+    """Return the preferred certificate bundle."""
     if certifi:
         return certifi.where()
-    else:
-        f = os.path.split(__file__)[0]
-        return os.path.join(f, 'cacert.pem')
+
+    return os.path.join(os.path.dirname(__file__), 'cacert.pem')
 
 if __name__ == '__main__':
     print(where())
diff --git a/script.module.requests/lib/requests/models.py 
b/script.module.requests/lib/requests/models.py
index 9ddea45..5202e6f 100644
--- a/script.module.requests/lib/requests/models.py
+++ b/script.module.requests/lib/requests/models.py
@@ -22,7 +22,7 @@ from .exceptions import HTTPError, RequestException, 
MissingSchema, InvalidURL
 from .utils import (
     stream_untransfer, guess_filename, requote_uri,
     stream_decode_response_unicode, to_key_val_list, parse_header_links,
-    iter_slices, guess_json_utf)
+    iter_slices, guess_json_utf, super_len)
 from .compat import (
     cookielib, urlparse, urlunparse, urlsplit, urlencode, str, bytes, StringIO,
     is_py2, chardet, json, builtin_str, basestring)
@@ -108,8 +108,12 @@ class RequestEncodingMixin(object):
 
         for (k, v) in files:
             # support for explicit filename
+            ft = None
             if isinstance(v, (tuple, list)):
-                fn, fp = v
+                if len(v) == 2:
+                    fn, fp = v
+                else:
+                    fn, fp, ft = v
             else:
                 fn = guess_filename(v) or k
                 fp = v
@@ -117,7 +121,12 @@ class RequestEncodingMixin(object):
                 fp = StringIO(fp)
             if isinstance(fp, bytes):
                 fp = BytesIO(fp)
-            new_fields.append((k, (fn, fp.read())))
+            
+            if ft:
+                new_v = (fn, fp.read(), ft)
+            else:
+                new_v = (fn, fp.read())
+            new_fields.append((k, new_v))
 
         body, content_type = encode_multipart_formdata(new_fields)
 
@@ -321,37 +330,62 @@ class PreparedRequest(RequestEncodingMixin, 
RequestHooksMixin):
     def prepare_body(self, data, files):
         """Prepares the given HTTP body data."""
 
-        # If a generator is provided, error out.
-        if isinstance(data, type(_ for _ in [])):
-            raise NotImplementedError('Generator bodies are not supported 
yet.')
+        # Check if file, fo, generator, iterator.
+        # If not, run through normal process.
 
         # Nottin' on you.
         body = None
         content_type = None
+        length = None
+        is_stream = False
 
-        # Multi-part file uploads.
-        if files:
-            (body, content_type) = self._encode_files(files, data)
-        else:
-            if data:
+        is_stream = all([
+            hasattr(data, '__iter__'),
+            not isinstance(data, basestring),
+            not isinstance(data, dict)
+        ])
 
-                body = self._encode_params(data)
-                if isinstance(data, str) or isinstance(data, builtin_str) or 
hasattr(data, 'read'):
-                    content_type = None
-                else:
-                    content_type = 'application/x-www-form-urlencoded'
-
-        self.headers['Content-Length'] = '0'
-        if hasattr(body, 'seek') and hasattr(body, 'tell'):
-            body.seek(0, 2)
-            self.headers['Content-Length'] = str(body.tell())
-            body.seek(0, 0)
-        elif body is not None:
-            self.headers['Content-Length'] = str(len(body))
-
-        # Add content-type if it wasn't explicitly provided.
-        if (content_type) and (not 'content-type' in self.headers):
-            self.headers['Content-Type'] = content_type
+        try:
+            length = super_len(data)
+        except (TypeError, AttributeError):
+            length = False
+
+        if is_stream:
+            body = data
+
+            if files:
+                raise NotImplementedError('Streamed bodies and files are 
mutually exclusive.')
+
+            if length:
+                self.headers['Content-Length'] = length
+            else:
+                self.headers['Transfer-Encoding'] = 'chunked'
+        # Check if file, fo, generator, iterator.
+        # If not, run through normal process.
+
+        else:
+            # Multi-part file uploads.
+            if files:
+                (body, content_type) = self._encode_files(files, data)
+            else:
+                if data:
+                    body = self._encode_params(data)
+                    if isinstance(data, str) or isinstance(data, builtin_str) 
or hasattr(data, 'read'):
+                        content_type = None
+                    else:
+                        content_type = 'application/x-www-form-urlencoded'
+
+            self.headers['Content-Length'] = '0'
+            if hasattr(body, 'seek') and hasattr(body, 'tell'):
+                body.seek(0, 2)
+                self.headers['Content-Length'] = str(body.tell())
+                body.seek(0, 0)
+            elif body is not None:
+                self.headers['Content-Length'] = str(len(body))
+
+            # Add content-type if it wasn't explicitly provided.
+            if (content_type) and (not 'content-type' in self.headers):
+                self.headers['Content-Type'] = content_type
 
         self.body = body
 
diff --git a/script.module.requests/lib/requests/sessions.py 
b/script.module.requests/lib/requests/sessions.py
index 1507609..d65877c 100644
--- a/script.module.requests/lib/requests/sessions.py
+++ b/script.module.requests/lib/requests/sessions.py
@@ -49,9 +49,20 @@ def merge_kwargs(local_kwarg, default_kwarg):
     default_kwarg = from_key_val_list(default_kwarg)
     local_kwarg = from_key_val_list(local_kwarg)
 
-    # Update new values.
+    # Update new values in a case-insensitive way
+    def get_original_key(original_keys, new_key):
+        """
+        Finds the key from original_keys that case-insensitive matches new_key.
+        """
+        for original_key in original_keys:
+            if key.lower() == original_key.lower():
+                return original_key
+        return new_key
+
     kwargs = default_kwarg.copy()
-    kwargs.update(local_kwarg)
+    original_keys = kwargs.keys()
+    for key, value in local_kwarg.items():
+        kwargs[get_original_key(original_keys, key)] = value
 
     # Remove keys that are set to None.
     for (k, v) in local_kwarg.items():
@@ -112,7 +123,6 @@ class SessionRedirectMixin(object):
                     url=url,
                     method=method,
                     headers=headers,
-                    params=req.params,
                     auth=req.auth,
                     cookies=req.cookies,
                     allow_redirects=False,
diff --git a/script.module.requests/lib/requests/structures.py 
b/script.module.requests/lib/requests/structures.py
index 3fda984..6c2e0b2 100644
--- a/script.module.requests/lib/requests/structures.py
+++ b/script.module.requests/lib/requests/structures.py
@@ -8,6 +8,28 @@ Data structures that power Requests.
 
 """
 
+import os
+from itertools import islice
+
+class IteratorProxy(object):
+    """docstring for IteratorProxy"""
+    def __init__(self, i):
+        self.i = i
+        # self.i = chain.from_iterable(i)
+
+    def __iter__(self):
+        return self.i
+
+    def __len__(self):
+        if hasattr(self.i, '__len__'):
+            return len(self.i)
+        if hasattr(self.i, 'len'):
+            return self.i.len
+        if hasattr(self.i, 'fileno'):
+            return os.fstat(self.i.fileno()).st_size
+
+    def read(self, n):
+        return "".join(islice(self.i, None, n))
 
 class CaseInsensitiveDict(dict):
     """Case-insensitive Dictionary
diff --git a/script.module.requests/lib/requests/utils.py 
b/script.module.requests/lib/requests/utils.py
index 69a9d01..17570e6 100644
--- a/script.module.requests/lib/requests/utils.py
+++ b/script.module.requests/lib/requests/utils.py
@@ -19,50 +19,18 @@ import zlib
 from netrc import netrc, NetrcParseError
 
 from . import __version__
+from . import certs
 from .compat import parse_http_list as _parse_list_header
-from .compat import quote, urlparse, bytes, str, OrderedDict
+from .compat import quote, urlparse, bytes, str, OrderedDict, urlunparse
 from .cookies import RequestsCookieJar, cookiejar_from_dict
 
 _hush_pyflakes = (RequestsCookieJar,)
 
-CERTIFI_BUNDLE_PATH = None
-try:
-    # see if requests's own CA certificate bundle is installed
-    from . import certs
-    path = certs.where()
-    if os.path.exists(path):
-        CERTIFI_BUNDLE_PATH = certs.where()
-except ImportError:
-    pass
-
 NETRC_FILES = ('.netrc', '_netrc')
 
-# common paths for the OS's CA certificate bundle
-POSSIBLE_CA_BUNDLE_PATHS = [
-        # Red Hat, CentOS, Fedora and friends (provided by the ca-certificates 
package):
-        '/etc/pki/tls/certs/ca-bundle.crt',
-        # Ubuntu, Debian, and friends (provided by the ca-certificates 
package):
-        '/etc/ssl/certs/ca-certificates.crt',
-        # FreeBSD (provided by the ca_root_nss package):
-        '/usr/local/share/certs/ca-root-nss.crt',
-        # openSUSE (provided by the ca-certificates package), the 'certs' 
directory is the
-        # preferred way but may not be supported by the SSL module, thus it 
has 'ca-bundle.pem'
-        # as a fallback (which is generated from pem files in the 'certs' 
directory):
-        '/etc/ssl/ca-bundle.pem',
-]
-
-
-def get_os_ca_bundle_path():
-    """Try to pick an available CA certificate bundle provided by the OS."""
-    for path in POSSIBLE_CA_BUNDLE_PATHS:
-        if os.path.exists(path):
-            return path
-    return None
-
 # if certifi is installed, use its CA bundle;
 # otherwise, try and use the OS bundle
-DEFAULT_CA_BUNDLE_PATH = CERTIFI_BUNDLE_PATH or get_os_ca_bundle_path()
-
+DEFAULT_CA_BUNDLE_PATH = certs.where()
 
 def dict_to_sequence(d):
     """Returns an internal sequence dictionary update."""
@@ -72,6 +40,13 @@ def dict_to_sequence(d):
 
     return d
 
+def super_len(o):
+    if hasattr(o, '__len__'):
+        return len(o)
+    if hasattr(o, 'len'):
+        return o.len
+    if hasattr(o, 'fileno'):
+        return os.fstat(o.fileno()).st_size
 
 def get_netrc_auth(url):
     """Returns the Requests tuple auth for a given url from netrc."""
@@ -593,3 +568,17 @@ def guess_json_utf(data):
             return 'utf-32-le'
         # Did not detect a valid UTF-32 ascii-range character
     return None
+
+
+def prepend_scheme_if_needed(url, new_scheme):
+    '''Given a URL that may or may not have a scheme, prepend the given scheme.
+    Does not replace a present scheme with the one provided as an argument.'''
+    scheme, netloc, path, params, query, fragment = urlparse(url, new_scheme)
+
+    # urlparse is a finicky beast, and sometimes decides that there isn't a
+    # netloc present. Assume that it's being over-cautious, and switch netloc
+    # and path if urlparse decided there was no netloc.
+    if not netloc:
+        netloc, path = path, netloc
+
+    return urlunparse((scheme, netloc, path, params, query, fragment))

-----------------------------------------------------------------------

Summary of changes:
 script.module.requests/addon.xml                  |    3 +-
 script.module.requests/lib/AUTHORS.rst            |    1 +
 script.module.requests/lib/HISTORY.rst            |    9 ++
 script.module.requests/lib/LICENSE.txt            |    4 +-
 script.module.requests/lib/requests/__init__.py   |    8 +-
 script.module.requests/lib/requests/adapters.py   |   78 +++++++++++++++---
 script.module.requests/lib/requests/certs.py      |   24 +++---
 script.module.requests/lib/requests/models.py     |   90 ++++++++++++++-------
 script.module.requests/lib/requests/sessions.py   |   16 +++-
 script.module.requests/lib/requests/structures.py |   22 +++++
 script.module.requests/lib/requests/utils.py      |   59 ++++++--------
 11 files changed, 217 insertions(+), 97 deletions(-)


hooks/post-receive
-- 
Scripts

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Xbmc-addons mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xbmc-addons

Reply via email to