Repository: GoogleCloudPlatform/httplib2shim

Issue:
proxy_info cannot be None for the ver. 0.0.2
After upgrade to ver. 0.0.2 I cannot call `httplib2shim.Http(proxy_info=None)`, it results in:
```
 File "/usr/local/lib/python3.5/dist-packages/httplib2shim/__init__.py", line 114, in __init__
    pool = self._make_pool(proxy_info=proxy_info())
TypeError: 'NoneType' object is not callable
```
Also, the `proxy_info` for the httplib2 may not be callable. While it's easy to make a lambda to change variable to callable, it's nice to allow `None` as proxy_info (and backward compatible, too.)

Discussion:
googlebot: Thanks for your pull request.  It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: **Please visit <https://cla.developers.google.com/> to sign.**

Once you've signed, please reply here (e.g. `I signed it!`) and we'll verify.  Thanks.

---

- If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address.  Check [your existing CLA data](https://cla.developers.google.com/clas) and verify that your [email is set on your git commits](https://help.github.com/articles/setting-your-email-in-git/).
- If you signed the CLA as a corporation, please let us know the company's name.

<!-- need_sender_cla -->
xmedeko: I signed it!
googlebot: CLAs look good, thanks!

<!-- ok -->
coveralls: 
[![Coverage Status](https://coveralls.io/builds/11551076/badge)](https://coveralls.io/builds/11551076)

Coverage increased (+0.08%) to 52.904% when pulling **ab4448b6168073bc916a0c0464c85dc42af72521 on xmedeko:master** into **128d229807577809a437cd20161c3c496080991f on GoogleCloudPlatform:master**.

xmedeko: @jonparrott thanks for the review.

For the `proxy_info` see the Http doc:
```
 `proxy_info` may be:
          - a callable that takes the http scheme ('http' or 'https') and
            returns a ProxyInfo instance per request.
          - a ProxyInfo instance (static proxy config).
          - None (proxy disabled).
```
I just add that the callable returns `None` when no proxy is configured (the usual case).
To be perfect compatible with the `httplib2` the `_default_make_pool` should check if it's callable or not. But I assume this is a temporary transition library so we do not be perfect - a user may simply do a lambda expression.

In regards of doc, I would rather step back and remove the doc if you do not like it. It may be added in the separate commit. Because:
- I do not use Google docstring style -> mistakes.
- I am not a native speaker ->mistakes.
- IMO doc for the private `_default_make_pool` is not necessary, better to make doc for the public `Http.__init__` - but do we have to copy the super class doc? I do not know. 
- It's not documented know and this commit is not commit to fix the doc.


cwt: @xmedeko It was my false that I didn't test all possible cases of the variable `proxy_info`. There should be a scenario that the proxy environment already set, but we want to disable it manually in the code (`proxy_info=None`).
jonparrott: It seems to me that we want is:

```python
import collections

if isinstance(proxy_info, collections.Callable):
    proxy_info = proxy_info()

if proxy_info:
    ...
```

> In regards of doc, I would rather step back and remove the doc if you do not like it. It may be added in the separate commit.

I'm happy to write the docstring for you. :) I just need to understand the change first.
xmedeko: Great! Now the `proxy_info` param is backward compatible, so the doc is not necessary :-)
I've amended the commit and added a simple unit test, too.
coveralls: 
[![Coverage Status](https://coveralls.io/builds/11578406/badge)](https://coveralls.io/builds/11578406)

Coverage increased (+1.02%) to 53.839% when pulling **0933c31513effb84194f7ff56cd923bac38189ce on xmedeko:master** into **128d229807577809a437cd20161c3c496080991f on GoogleCloudPlatform:master**.


Patch:
diff --git a/httplib2shim/__init__.py b/httplib2shim/__init__.py
index bdc9a8c..42b3aa6 100644
--- a/httplib2shim/__init__.py
+++ b/httplib2shim/__init__.py
@@ -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
@@ -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(
@@ -111,7 +114,7 @@ class Http(httplib2.Http):
             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
 


Test patch:
diff --git a/httplib2shim/test/httplib2_test.py b/httplib2shim/test/httplib2_test.py
index 5bfbd02..abb234f 100644
--- a/httplib2shim/test/httplib2_test.py
+++ b/httplib2shim/test/httplib2_test.py
@@ -39,6 +39,7 @@ import httplib2
 import httplib2shim
 import six
 from six.moves.urllib import parse as urllib_parse
+import urllib3
 
 
 __author__ = "Joe Gregorio (joe@bitworking.org)"
@@ -1880,3 +1881,19 @@ class TestProxyInfo(unittest.TestCase):
         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)