Sync httplib2. Fix user-agent code so base libraries are listed after higher level apps/libraries user-agent.
diff --git a/apiclient/oauth.py b/apiclient/oauth.py
index de20336..9907c46 100644
--- a/apiclient/oauth.py
+++ b/apiclient/oauth.py
@@ -131,10 +131,9 @@
headers = {}
headers.update(req.to_header())
if 'user-agent' in headers:
- headers['user-agent'] += ' '
+ headers['user-agent'] = self.user_agent + ' ' + headers['user-agent']
else:
- headers['user-agent'] = ''
- headers['user-agent'] += self.user_agent
+ headers['user-agent'] = self.user_agent
return request_orig(uri, method, body, headers,
redirections, connection_type)
diff --git a/httplib2/__init__.py b/httplib2/__init__.py
index 61e9caa..567e24e 100644
--- a/httplib2/__init__.py
+++ b/httplib2/__init__.py
@@ -55,9 +55,9 @@
import socket
try:
- from httplib2 import socks
+ from httplib2 import socks
except ImportError:
- socks = None
+ socks = None
# Build the appropriate socket wrapper for ssl
try:
@@ -83,7 +83,7 @@
__all__ = ['Http', 'Response', 'ProxyInfo', 'HttpLib2Error',
'RedirectMissingLocation', 'RedirectLimit', 'FailedToDecompressContent',
'UnimplementedDigestAuthOptionError', 'UnimplementedHmacDigestAuthOptionError',
- 'debuglevel']
+ 'debuglevel', 'ProxiesUnavailableError']
# The httplib debug level, set to a non-zero value to get debug output
@@ -125,6 +125,7 @@
class RelativeURIError(HttpLib2Error): pass
class ServerNotFoundError(HttpLib2Error): pass
+class ProxiesUnavailableError(HttpLib2Error): pass
# Open Items:
# -----------
@@ -721,6 +722,9 @@
def connect(self):
"""Connect to the host and port specified in __init__."""
# Mostly verbatim from httplib.py.
+ if self.proxy_info and socks is None:
+ raise ProxiesUnavailableError(
+ 'Proxy support missing but proxy use was requested!')
msg = "getaddrinfo returns an empty list"
for res in socket.getaddrinfo(self.host, self.port, 0,
socket.SOCK_STREAM):
diff --git a/httplib2/socks.py b/httplib2/socks.py
index 6f4f020..b65fb38 100644
--- a/httplib2/socks.py
+++ b/httplib2/socks.py
@@ -41,12 +41,13 @@
"""
import socket
+
+if getattr(socket, 'socket', None) is None:
+ raise ImportError('socket.socket missing, proxy support unusable')
+
import struct
import sys
-if not hasattr(socket, 'socket'):
- raise ImportError("Running on App Engine?")
-
PROXY_TYPE_SOCKS4 = 1
PROXY_TYPE_SOCKS5 = 2
PROXY_TYPE_HTTP = 3