1 |
patrick 09/04/23 09:10:39 |
2 |
|
3 |
Added: compat-2.6-0.4.0.patch |
4 |
Log: |
5 |
Py 2.6 deprecation fix. Thanks to djc for pointing it out, thanks to Benoit Chesneau for the patch. Fixes #267184 |
6 |
(Portage version: 2.2_rc31/cvs/Linux x86_64) |
7 |
|
8 |
Revision Changes Path |
9 |
1.1 dev-python/httplib2/files/compat-2.6-0.4.0.patch |
10 |
|
11 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/dev-python/httplib2/files/compat-2.6-0.4.0.patch?rev=1.1&view=markup |
12 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/dev-python/httplib2/files/compat-2.6-0.4.0.patch?rev=1.1&content-type=text/plain |
13 |
|
14 |
Index: compat-2.6-0.4.0.patch |
15 |
=================================================================== |
16 |
Index: httplib2/__init__.py |
17 |
=================================================================== |
18 |
--- httplib2/__init__.py (revision 274) |
19 |
+++ httplib2/__init__.py (revision 275) |
20 |
@@ -26,7 +26,6 @@ |
21 |
|
22 |
import re |
23 |
import sys |
24 |
-import md5 |
25 |
import email |
26 |
import email.Utils |
27 |
import email.Message |
28 |
@@ -42,7 +41,14 @@ |
29 |
import calendar |
30 |
import time |
31 |
import random |
32 |
-import sha |
33 |
+# remove depracated warning in python2.6 |
34 |
+try: |
35 |
+ from hashlib import sha1 as _sha, md5 as _md5 |
36 |
+except ImportError: |
37 |
+ import sha |
38 |
+ import md5 |
39 |
+ _sha = sha.new |
40 |
+ _md5 = md5.new |
41 |
import hmac |
42 |
from gettext import gettext as _ |
43 |
import socket |
44 |
@@ -52,12 +58,27 @@ |
45 |
except ImportError: |
46 |
socks = None |
47 |
|
48 |
+# Build the appropriate socket wrapper for ssl |
49 |
+try: |
50 |
+ import ssl # python 2.6 |
51 |
+ _ssl_wrap_socket = ssl.wrap_socket |
52 |
+except ImportError: |
53 |
+ def _ssl_wrap_socket(sock, key_file, cert_file): |
54 |
+ ssl_sock = socket.ssl(sock, key_file, cert_file) |
55 |
+ return httplib.FakeSocket(sock, ssl_sock) |
56 |
+ |
57 |
+ |
58 |
if sys.version_info >= (2,3): |
59 |
from iri2uri import iri2uri |
60 |
else: |
61 |
def iri2uri(uri): |
62 |
return uri |
63 |
|
64 |
+def has_timeout(timeout): # python 2.6 |
65 |
+ if hasattr(socket, '_GLOBAL_DEFAULT_TIMEOUT'): |
66 |
+ return (timeout is not None and timeout is not socket._GLOBAL_DEFAULT_TIMEOUT) |
67 |
+ return (timeout is not None) |
68 |
+ |
69 |
__all__ = ['Http', 'Response', 'ProxyInfo', 'HttpLib2Error', |
70 |
'RedirectMissingLocation', 'RedirectLimit', 'FailedToDecompressContent', |
71 |
'UnimplementedDigestAuthOptionError', 'UnimplementedHmacDigestAuthOptionError', |
72 |
@@ -182,7 +203,7 @@ |
73 |
pass |
74 |
if isinstance(filename,unicode): |
75 |
filename=filename.encode('utf-8') |
76 |
- filemd5 = md5.new(filename).hexdigest() |
77 |
+ filemd5 = _md5(filename).hexdigest() |
78 |
filename = re_url_scheme.sub("", filename) |
79 |
filename = re_slash.sub(",", filename) |
80 |
|
81 |
@@ -363,11 +384,11 @@ |
82 |
cache.set(cachekey, text) |
83 |
|
84 |
def _cnonce(): |
85 |
- dig = md5.new("%s:%s" % (time.ctime(), ["0123456789"[random.randrange(0, 9)] for i in range(20)])).hexdigest() |
86 |
+ dig = _md5("%s:%s" % (time.ctime(), ["0123456789"[random.randrange(0, 9)] for i in range(20)])).hexdigest() |
87 |
return dig[:16] |
88 |
|
89 |
def _wsse_username_token(cnonce, iso_now, password): |
90 |
- return base64.encodestring(sha.new("%s%s%s" % (cnonce, iso_now, password)).digest()).strip() |
91 |
+ return base64.encodestring(_sha("%s%s%s" % (cnonce, iso_now, password)).digest()).strip() |
92 |
|
93 |
|
94 |
# For credentials we need two things, first |
95 |
@@ -441,7 +462,7 @@ |
96 |
|
97 |
def request(self, method, request_uri, headers, content, cnonce = None): |
98 |
"""Modify the request headers""" |
99 |
- H = lambda x: md5.new(x).hexdigest() |
100 |
+ H = lambda x: _md5(x).hexdigest() |
101 |
KD = lambda s, d: H("%s:%s" % (s, d)) |
102 |
A2 = "".join([method, ":", request_uri]) |
103 |
self.challenge['cnonce'] = cnonce or _cnonce() |
104 |
@@ -501,13 +522,13 @@ |
105 |
if self.challenge['pw-algorithm'] not in ['SHA-1', 'MD5']: |
106 |
raise UnimplementedHmacDigestAuthOptionError( _("Unsupported value for pw-algorithm: %s." % self.challenge['pw-algorithm'])) |
107 |
if self.challenge['algorithm'] == 'HMAC-MD5': |
108 |
- self.hashmod = md5 |
109 |
+ self.hashmod = _md5 |
110 |
else: |
111 |
- self.hashmod = sha |
112 |
+ self.hashmod = _sha |
113 |
if self.challenge['pw-algorithm'] == 'MD5': |
114 |
- self.pwhashmod = md5 |
115 |
+ self.pwhashmod = _md5 |
116 |
else: |
117 |
- self.pwhashmod = sha |
118 |
+ self.pwhashmod = _sha |
119 |
self.key = "".join([self.credentials[0], ":", |
120 |
self.pwhashmod.new("".join([self.credentials[1], self.challenge['salt']])).hexdigest().lower(), |
121 |
":", self.challenge['realm'] |
122 |
@@ -604,9 +625,6 @@ |
123 |
|
124 |
AUTH_SCHEME_ORDER = ["hmacdigest", "googlelogin", "digest", "wsse", "basic"] |
125 |
|
126 |
-def _md5(s): |
127 |
- return |
128 |
- |
129 |
class FileCache(object): |
130 |
"""Uses a local directory as a store for cached files. |
131 |
Not really safe to use if multiple threads or processes are going to |
132 |
@@ -701,7 +719,7 @@ |
133 |
else: |
134 |
self.sock = socket.socket(af, socktype, proto) |
135 |
# Different from httplib: support timeouts. |
136 |
- if self.timeout is not None: |
137 |
+ if has_timeout(self.timeout): |
138 |
self.sock.settimeout(self.timeout) |
139 |
# End of difference from httplib. |
140 |
if self.debuglevel > 0: |
141 |
@@ -737,11 +755,11 @@ |
142 |
sock.setproxy(*self.proxy_info.astuple()) |
143 |
else: |
144 |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
145 |
- if self.timeout is not None: |
146 |
+ |
147 |
+ if has_timeout(self.timeout): |
148 |
sock.settimeout(self.timeout) |
149 |
sock.connect((self.host, self.port)) |
150 |
- ssl = socket.ssl(sock, self.key_file, self.cert_file) |
151 |
- self.sock = httplib.FakeSocket(sock, ssl) |
152 |
+ self.sock =_ssl_wrap_socket(sock, self.key_file, self.cert_file) |