Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
Http.__init__ allow proxy_info to be None (#9)
Browse files Browse the repository at this point in the history
Fix #8
  • Loading branch information
xmedeko authored and Jon Wayne Parrott committed May 20, 2017
1 parent 128d229 commit 6b94a9a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion httplib2shim/__init__.py
Expand Up @@ -20,6 +20,7 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import collections
import errno
import socket
import ssl
Expand All @@ -41,6 +42,8 @@ def _default_make_pool(http, proxy_info):

cert_reqs = 'CERT_REQUIRED' if http.ca_certs and not ssl_disabled else None

if isinstance(proxy_info, collections.Callable):
proxy_info = proxy_info()
if proxy_info:
if proxy_info.proxy_user and proxy_info.proxy_pass:
proxy_url = 'http://{}:{}@{}:{}/'.format(
Expand Down Expand Up @@ -111,7 +114,7 @@ def __init__(self, cache=None, timeout=None,
disable_ssl_certificate_validation=disable_ssl)

if not pool:
pool = self._make_pool(proxy_info=proxy_info())
pool = self._make_pool(proxy_info=proxy_info)

self.pool = pool

Expand Down
17 changes: 17 additions & 0 deletions httplib2shim/test/httplib2_test.py
Expand Up @@ -39,6 +39,7 @@
import httplib2shim
import six
from six.moves.urllib import parse as urllib_parse
import urllib3


__author__ = "Joe Gregorio (joe@bitworking.org)"
Expand Down Expand Up @@ -1880,3 +1881,19 @@ def test_from_env_none(self):
os.environ.clear()
pi = httplib2.proxy_info_from_environment()
self.assertEqual(pi, None)


class HttpShimProxyPoolTest(unittest.TestCase):

def test_none(self):
http = httplib2.Http(proxy_info=None)
self.assertIsInstance(http.pool, urllib3.PoolManager)
http = httplib2.Http(proxy_info=lambda: None)
self.assertIsInstance(http.pool, urllib3.PoolManager)

def test_instance_and_callable(self):
proxy_info = httplib2.proxy_info_from_url('http://myproxy.example.com')
http = httplib2.Http(proxy_info=proxy_info)
self.assertIsInstance(http.pool, urllib3.ProxyManager)
http = httplib2.Http(proxy_info=lambda: proxy_info)
self.assertIsInstance(http.pool, urllib3.ProxyManager)

0 comments on commit 6b94a9a

Please sign in to comment.