Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Reitz committed Oct 18, 2012
2 parents b73426a + aa08f33 commit a74c6c6
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 40 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Expand Up @@ -114,3 +114,4 @@ Patches and Suggestions
- Ian Cordasco <graffatcolmingov@gmail.com> @sigmavirus24
- Rhys Elsmore
- André Graf (dergraf)
- Stephen Zhuang (everbird)
10 changes: 5 additions & 5 deletions docs/_themes/README.rst
Expand Up @@ -11,15 +11,15 @@ this guide:

2. add this to your conf.py: ::

sys.path.append(os.path.abspath('_themes'))
html_theme_path = ['_themes']
html_theme = 'flask'
sys.path.append(os.path.abspath('_themes'))
html_theme_path = ['_themes']
html_theme = 'flask'

The following themes exist:

**kr**
the standard flask documentation theme for large projects
the standard flask documentation theme for large projects

**kr_small**
small one-page theme. Intended to be used by very small addon libraries.
small one-page theme. Intended to be used by very small addon libraries.

2 changes: 1 addition & 1 deletion docs/community/support.rst
Expand Up @@ -34,4 +34,4 @@ IRC
The official Freenode channel for Requests is
`#python-requests <irc://irc.freenode.net/python-requests>`_

I'm also available as **kennethreitz** on Freenode.
I'm also available as **kennethreitz** on Freenode.
2 changes: 1 addition & 1 deletion docs/conf.py
Expand Up @@ -241,4 +241,4 @@

sys.path.append(os.path.abspath('_themes'))
html_theme_path = ['_themes']
html_theme = 'kr'
html_theme = 'kr'
2 changes: 1 addition & 1 deletion docs/dev/authors.rst
Expand Up @@ -2,4 +2,4 @@ Authors
=======


.. include:: ../../AUTHORS.rst
.. include:: ../../AUTHORS.rst
6 changes: 3 additions & 3 deletions docs/user/install.rst
Expand Up @@ -25,10 +25,10 @@ But, you really `shouldn't do that <http://www.pip-installer.org/en/latest/other
Cheeseshop Mirror
-----------------

If the Cheeseshop is down, you can also install Requests from Kenneth Reitz's
personal `Cheeseshop mirror <http://pip.kennethreitz.com/>`_::
If the Cheeseshop is down, you can also install Requests from one of the
mirrors. `Crate.io <http://crate.io>`_ is one of them::

$ pip install -i http://pip.kennethreitz.com/simple requests
$ pip install -i http://simple.crate.io/ requests


Get the Code
Expand Down
2 changes: 1 addition & 1 deletion requests/auth.py
Expand Up @@ -94,7 +94,7 @@ def __call__(self, r):
# to preserve body.
r.url, r.headers, _ = self.client.sign(
unicode(r.full_url), unicode(r.method), None, r.headers)
elif decoded_body != None and contenttype in (CONTENT_TYPE_FORM_URLENCODED, ''):
elif decoded_body is not None and contenttype in (CONTENT_TYPE_FORM_URLENCODED, ''):
# Normal signing
if not contenttype:
r.headers['Content-Type'] = CONTENT_TYPE_FORM_URLENCODED
Expand Down
2 changes: 1 addition & 1 deletion requests/compat.py
Expand Up @@ -115,5 +115,5 @@
builtin_str = str
str = str
bytes = bytes
basestring = (str,bytes)
basestring = (str, bytes)
numeric_types = (int, float)
10 changes: 4 additions & 6 deletions requests/cookies.py
Expand Up @@ -235,7 +235,7 @@ def get_dict(self, domain=None, path=None):
Python dict of name-value pairs of cookies that meet the requirements."""
dictionary = {}
for cookie in iter(self):
if (domain == None or cookie.domain == domain) and (path == None
if (domain is None or cookie.domain == domain) and (path is None
or cookie.path == path):
dictionary[cookie.name] = cookie.value
return dictionary
Expand Down Expand Up @@ -279,7 +279,7 @@ def _find_no_duplicates(self, name, domain=None, path=None):
if cookie.name == name:
if domain is None or cookie.domain == domain:
if path is None or cookie.path == path:
if toReturn != None: # if there are multiple cookies that meet passed in criteria
if toReturn is not None: # if there are multiple cookies that meet passed in criteria
raise CookieConflictError('There are multiple cookies with name, %r' % (name))
toReturn = cookie.value # we will eventually return this as long as no cookie conflict

Expand Down Expand Up @@ -324,8 +324,7 @@ def create_cookie(name, value, **kwargs):
comment=None,
comment_url=None,
rest={'HttpOnly': None},
rfc2109=False,
)
rfc2109=False,)

badargs = set(kwargs) - set(result)
if badargs:
Expand Down Expand Up @@ -360,8 +359,7 @@ def morsel_to_cookie(morsel):
comment=morsel['comment'],
comment_url=bool(morsel['comment']),
rest={'HttpOnly': morsel['httponly']},
rfc2109=False,
)
rfc2109=False,)
return c


Expand Down
1 change: 0 additions & 1 deletion requests/hooks.py
Expand Up @@ -45,5 +45,4 @@ def dispatch_hook(key, hooks, hook_data):
if _hook_data is not None:
hook_data = _hook_data


return hook_data
6 changes: 3 additions & 3 deletions requests/models.py
Expand Up @@ -111,7 +111,7 @@ def __init__(self,
# Dictionary mapping protocol to the URL of the proxy (e.g. {'http': 'foo.bar:3128'})
self.proxies = dict(proxies or [])

for proxy_type,uri_ref in list(self.proxies.items()):
for proxy_type, uri_ref in list(self.proxies.items()):
if not uri_ref:
del self.proxies[proxy_type]

Expand Down Expand Up @@ -360,9 +360,9 @@ def _encode_files(self, files):
for field, val in fields:
if isinstance(val, list):
for v in val:
new_fields.append((field, str(v)))
new_fields.append((field, builtin_str(v)))
else:
new_fields.append((field, str(val)))
new_fields.append((field, builtin_str(val)))

for (k, v) in files:
# support for explicit filename
Expand Down
5 changes: 4 additions & 1 deletion requests/utils.py
Expand Up @@ -378,13 +378,15 @@ def stream_decode_response_unicode(iterator, r):
if rv:
yield rv


def iter_slices(string, slice_length):
"""Iterate over slices of a string."""
pos = 0
while pos < len(string):
yield string[pos:pos+slice_length]
yield string[pos:pos + slice_length]
pos += slice_length


def get_unicode_from_response(r):
"""Returns the requested content back in unicode.
Expand Down Expand Up @@ -543,6 +545,7 @@ def default_user_agent():
'%s/%s' % (platform.system(), platform.release()),
])


def parse_header_links(value):
"""Return a dict of parsed link headers proxies.
Expand Down
6 changes: 5 additions & 1 deletion tests/informal/test_leaked_connections.py
Expand Up @@ -4,7 +4,11 @@
the body of the request is not read.
"""

import gc, os, subprocess, requests, sys
import gc
import os
import requests
import subprocess
import sys


def main():
Expand Down
12 changes: 7 additions & 5 deletions tests/test_proxies.py
@@ -1,7 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys, os, unittest
import os
import sys
import unittest

# Path hack.
sys.path.insert(0, os.path.abspath('..'))
Expand All @@ -14,13 +16,13 @@ class HTTPSProxyTest(unittest.TestCase):
smoke_url = "https://github.com"

def test_empty_https_proxy(self):
proxy = {"https" : "" }
result = requests.get(self.smoke_url, verify=False, proxies = proxy)
proxy = {"https": ""}
result = requests.get(self.smoke_url, verify=False, proxies=proxy)
self.assertEqual(result.status_code, 200)

def test_empty_http_proxy(self):
proxy = {"http" : "" }
result = requests.get(self.smoke_url, proxies = proxy)
proxy = {"http": ""}
result = requests.get(self.smoke_url, proxies=proxy)
self.assertEqual(result.status_code, 200)

if __name__ == '__main__':
Expand Down
26 changes: 19 additions & 7 deletions tests/test_requests.py
Expand Up @@ -51,6 +51,7 @@ def setUp(self):
# time.sleep(1)
_httpbin = True


class TestBaseMixin(object):

def assertCookieHas(self, cookie, **kwargs):
Expand All @@ -60,6 +61,7 @@ def assertCookieHas(self, cookie, **kwargs):
message = 'Failed comparison for %s: %s != %s' % (attr, cookie_attr, expected_value)
self.assertEqual(cookie_attr, expected_value, message)


class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase):
"""Requests test cases."""

Expand Down Expand Up @@ -336,12 +338,23 @@ def test_POSTBIN_GET_POST_FILES_WITH_PARAMS(self):

with open(__file__) as f:
url = service('post')
post1 = post(url,
files={'some': f},
data={'some': 'data'})
post1 = post(url, data={'some': 'data'}, files={'some': f})
post2 = post(url, data={'some': 'data'}, files=[('some', f)])
post3 = post(url, data=[('some', 'data')],
files=[('some', f)])
post3 = post(url, data=[('some', 'data')], files=[('some', f)])

self.assertEqual(post1.status_code, 200)
self.assertEqual(post2.status_code, 200)
self.assertEqual(post3.status_code, 200)

def test_POSTBIN_GET_POST_FILES_WITH_CJK_PARAMS(self):

for service in SERVICES:

with open(__file__) as f:
url = service('post')
post1 = post(url, data={'some': '中文'}, files={'some': f})
post2 = post(url, data={'some': '日本語'}, files=[('some', f)])
post3 = post(url, data=[('some', '한국의')], files=[('some', f)])

self.assertEqual(post1.status_code, 200)
self.assertEqual(post2.status_code, 200)
Expand Down Expand Up @@ -903,7 +916,7 @@ def test_connection_error(self):
def test_connection_error_with_safe_mode(self):
config = {'safe_mode': True}
r = get('http://localhost:1/nope', allow_redirects=False, config=config)
assert r.content == None
assert r.content is None

# def test_invalid_content(self):
# # WARNING: if you're using a terrible DNS provider (comcast),
Expand Down Expand Up @@ -1038,7 +1051,6 @@ def test_danger_mode_redirects(self):
s.config['danger_mode'] = True
s.get(httpbin('redirect', '4'))


def test_empty_response(self):
r = requests.get(httpbin('status', '404'))
r.text
Expand Down
3 changes: 2 additions & 1 deletion tests/test_requests_ext.py
Expand Up @@ -2,7 +2,8 @@
# -*- coding: utf-8 -*-

# Path hack.
import sys, os
import os
import sys
sys.path.insert(0, os.path.abspath('..'))

import unittest
Expand Down
4 changes: 2 additions & 2 deletions tests/test_requests_https.py
@@ -1,8 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys, os
import json
import os
import sys
import unittest

# Path hack.
Expand Down

0 comments on commit a74c6c6

Please sign in to comment.