Merge lp:~gholt/swift/python2.7compat into lp:~hudson-openstack/swift/trunk

Proposed by gholt
Status: Merged
Approved by: David Goetz
Approved revision: 292
Merged at revision: 291
Proposed branch: lp:~gholt/swift/python2.7compat
Merge into: lp:~hudson-openstack/swift/trunk
Diff against target: 70 lines (+33/-2)
3 files modified
CHANGELOG (+2/-0)
swift/common/bufferedhttp.py (+2/-2)
test/unit/common/test_bufferedhttp.py (+29/-0)
To merge this branch: bzr merge lp:~gholt/swift/python2.7compat
Reviewer Review Type Date Requested Status
David Goetz (community) Approve
John Dickinson Approve
Review via email: mp+60844@code.launchpad.net

Description of the change

Fixed Python 2.7 compatibility problem

To post a comment you must log in.
Revision history for this message
John Dickinson (notmyname) wrote :

is there any issue with overriding bufferedhttp.HTTPSConnection in the test and not setting it back? Shouldn't it use some sort of save globals?

review: Needs Information
Revision history for this message
gholt (gholt) wrote :

Bleh, yes it should reset things. Fix for that pushed.

lp:~gholt/swift/python2.7compat updated
292. By gholt

Fixed unit test not restoring things to prepatched state

Revision history for this message
John Dickinson (notmyname) wrote :

LGTM

review: Approve
Revision history for this message
David Goetz (david-goetz) wrote :

looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CHANGELOG'
2--- CHANGELOG 2011-05-12 19:34:47 +0000
3+++ CHANGELOG 2011-05-12 22:55:54 +0000
4@@ -8,3 +8,5 @@
5 (X-Trans-ID). Setting the transaction id has moved from the proxy server to
6 the catch_errors middleware. Additionally, the internal header has changed
7 from X-CF-Trans-ID to X-Trans-ID.
8+
9+ * Fixed Python 2.7 httplib compatibility problem.
10
11=== modified file 'swift/common/bufferedhttp.py'
12--- swift/common/bufferedhttp.py 2011-01-19 21:22:05 +0000
13+++ swift/common/bufferedhttp.py 2011-05-12 22:55:54 +0000
14@@ -131,7 +131,7 @@
15 conn.putrequest(method, path)
16 if headers:
17 for header, value in headers.iteritems():
18- conn.putheader(header, value)
19+ conn.putheader(header, str(value))
20 conn.endheaders()
21 return conn
22
23@@ -164,6 +164,6 @@
24 conn.putrequest(method, path)
25 if headers:
26 for header, value in headers.iteritems():
27- conn.putheader(header, value)
28+ conn.putheader(header, str(value))
29 conn.endheaders()
30 return conn
31
32=== modified file 'test/unit/common/test_bufferedhttp.py'
33--- test/unit/common/test_bufferedhttp.py 2011-01-04 23:34:43 +0000
34+++ test/unit/common/test_bufferedhttp.py 2011-05-12 22:55:54 +0000
35@@ -68,6 +68,35 @@
36 if err:
37 raise Exception(err)
38
39+ def test_nonstr_header_values(self):
40+
41+ class MockHTTPSConnection(object):
42+
43+ def __init__(self, hostport):
44+ pass
45+
46+ def putrequest(self, method, path):
47+ pass
48+
49+ def putheader(self, header, *values):
50+ # Essentially what Python 2.7 does that caused us problems.
51+ '\r\n\t'.join(values)
52+
53+ def endheaders(self):
54+ pass
55+
56+ origHTTPSConnection = bufferedhttp.HTTPSConnection
57+ bufferedhttp.HTTPSConnection = MockHTTPSConnection
58+ try:
59+ bufferedhttp.http_connect('127.0.0.1', 8080, 'sda', 1, 'GET', '/',
60+ headers={'x-one': '1', 'x-two': 2, 'x-three': 3.0,
61+ 'x-four': {'crazy': 'value'}}, ssl=True)
62+ bufferedhttp.http_connect_raw('127.0.0.1', 8080, 'GET', '/',
63+ headers={'x-one': '1', 'x-two': 2, 'x-three': 3.0,
64+ 'x-four': {'crazy': 'value'}}, ssl=True)
65+ finally:
66+ bufferedhttp.HTTPSConnection = origHTTPSConnection
67+
68
69 if __name__ == '__main__':
70 unittest.main()