From 5e3a5fa791903672ff1e155c31909c00f824dba0 Mon Sep 17 00:00:00 2001 From: Joe Gregorio Date: Mon, 11 Oct 2010 13:03:56 -0400 Subject: [PATCH] Sync httplib2. Fix user-agent code so base libraries are listed after higher level apps/libraries user-agent. --- apiclient/oauth.py | 5 ++--- httplib2/__init__.py | 10 +++++++--- httplib2/socks.py | 7 ++++--- 3 files changed, 13 insertions(+), 9 deletions(-) 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 @@ class OAuthCredentials(Credentials): 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 @@ from gettext import gettext as _ 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 @@ def has_timeout(timeout): # python 2.6 __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 UnimplementedHmacDigestAuthOptionError(HttpLib2ErrorWithResponse): pass class RelativeURIError(HttpLib2Error): pass class ServerNotFoundError(HttpLib2Error): pass +class ProxiesUnavailableError(HttpLib2Error): pass # Open Items: # ----------- @@ -721,6 +722,9 @@ class HTTPConnectionWithTimeout(httplib.HTTPConnection): 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 @@ mainly to merge bug fixes found in Sourceforge """ 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