proxy: no_proxy=bar was matching foobar

https://github.com/httplib2/httplib2/issues/94
diff --git a/python2/httplib2/__init__.py b/python2/httplib2/__init__.py
index 986dc7f..feffacb 100644
--- a/python2/httplib2/__init__.py
+++ b/python2/httplib2/__init__.py
@@ -838,12 +838,15 @@
         if self.bypass_hosts is AllHosts:
             return True
 
-        bypass = False
-        for domain in self.bypass_hosts:
-            if hostname.endswith(domain):
-                bypass = True
-
-        return bypass
+        hostname = '.' + hostname.lstrip('.')
+        for skip_name in self.bypass_hosts:
+            # *.suffix
+            if skip_name.startswith('.') and hostname.endswith(skip_name):
+                return True
+            # exact match
+            if hostname == '.' + skip_name:
+                return True
+        return False
 
 
 def proxy_info_from_environment(method='http'):
diff --git a/python3/httplib2/__init__.py b/python3/httplib2/__init__.py
index 61e69b2..5deee82 100644
--- a/python3/httplib2/__init__.py
+++ b/python3/httplib2/__init__.py
@@ -795,12 +795,15 @@
     if self.bypass_hosts is AllHosts:
       return True
 
-    bypass = False
-    for domain in self.bypass_hosts:
-      if hostname.endswith(domain):
-        bypass = True
-
-    return bypass
+    hostname = '.' + hostname.lstrip('.')
+    for skip_name in self.bypass_hosts:
+      # *.suffix
+      if skip_name.startswith('.') and hostname.endswith(skip_name):
+        return True
+      # exact match
+      if hostname == '.' + skip_name:
+        return True
+    return False
 
 
 def proxy_info_from_environment(method='http'):
diff --git a/tests/test_proxy.py b/tests/test_proxy.py
index d1bdb66..3f1622e 100644
--- a/tests/test_proxy.py
+++ b/tests/test_proxy.py
@@ -46,11 +46,15 @@
 def test_applies_to():
     os.environ['http_proxy'] = 'http://myproxy.example.com:80'
     os.environ['https_proxy'] = 'http://myproxy.example.com:81'
-    os.environ['no_proxy'] = 'localhost,otherhost.domain.local,example.com'
+    os.environ['no_proxy'] = 'localhost,example.com,.wildcard'
     pi = httplib2.proxy_info_from_environment()
     assert not pi.applies_to('localhost')
     assert pi.applies_to('www.google.com')
-    assert not pi.applies_to('www.example.com')
+    assert pi.applies_to('prefixlocalhost')
+    assert pi.applies_to('www.example.com')
+    assert pi.applies_to('sub.example.com')
+    assert not pi.applies_to('sub.wildcard')
+    assert not pi.applies_to('pub.sub.wildcard')
 
 
 def test_noproxy_trailing_comma():