Merge lp:~cr3/checkbox/proxy into lp:checkbox

Proposed by Marc Tardif
Status: Merged
Merged at revision: 1422
Proposed branch: lp:~cr3/checkbox/proxy
Merge into: lp:checkbox
Diff against target: 146 lines (+17/-55)
2 files modified
checkbox/lib/fifo.py (+5/-10)
checkbox/lib/transport.py (+12/-45)
To merge this branch: bzr merge lp:~cr3/checkbox/proxy
Reviewer Review Type Date Requested Status
Daniel Manrique (community) Approve
Review via email: mp+109440@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Manrique (roadmr) wrote :

Looks good, shame about the FIFO modes, pending further diagnostics on what's going on.

Merging!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'checkbox/lib/fifo.py'
2--- checkbox/lib/fifo.py 2012-06-08 13:36:59 +0000
3+++ checkbox/lib/fifo.py 2012-06-08 21:33:20 +0000
4@@ -53,15 +53,10 @@
5
6 class FifoReader(FifoBase):
7
8- # In this case we want to read from the FIFO, but opening it in
9- # read-write mode (as opposed to read-only) is done specifically
10- # so that the frontend can open the FIFO without blocking until the
11- # backend starts; so that the frontend can wait a reasonable amount
12- # of time and then, if it hasn't received a reply from the backend,
13- # it can continue execution. This is done to prevent the frontend
14- # blocking forever if the user e.g. fails to input the password and
15- # the backend doesn't start (LP#588539).
16- mode = "r+b"
17+ # TODO: Not being able to read-write will cause the frontend to
18+ # block forever if the user e.g. fails to input the password and the
19+ # backend doesn't start (LP#588539).
20+ mode = "rb"
21
22 def read_bytes(self):
23 # Check if a connection arrived within the timeout
24@@ -87,7 +82,7 @@
25 class FifoWriter(FifoBase):
26
27 # See FifoReader.mode.
28- mode = "w+b"
29+ mode = "wb"
30
31 def write_bytes(self, _bytes):
32
33
34=== modified file 'checkbox/lib/transport.py'
35--- checkbox/lib/transport.py 2012-06-01 21:42:42 +0000
36+++ checkbox/lib/transport.py 2012-06-08 21:33:20 +0000
37@@ -27,45 +27,10 @@
38 import http.client
39 import mimetypes
40 import socket
41+import ssl
42 import urllib.request, urllib.parse, urllib.error
43
44
45-# Build the appropriate socket wrapper for ssl
46-try:
47- # Python 2.6 introduced a better ssl package
48- import ssl
49- _ssl_wrap_socket = ssl.wrap_socket
50-except ImportError:
51- # Python versions prior to 2.6 don't have ssl and ssl.wrap_socket instead
52- # they use httplib.FakeSocket
53- def _ssl_wrap_socket(sock, key_file, cert_file):
54- ssl_sock = socket.ssl(sock, key_file, cert_file)
55- return http.client.FakeSocket(sock, ssl_sock)
56-
57-try:
58- # Python 2.6 introduced create_connection convenience function
59- create_connection = socket.create_connection
60-except AttributeError:
61- def create_connection(address, timeout=None):
62- msg = "getaddrinfo returns an empty list"
63- host, port = address
64- for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
65- af, socktype, proto, canonname, sa = res
66- sock = None
67- try:
68- sock = socket.socket(af, socktype, proto)
69- if timeout is not None:
70- sock.settimeout(timeout)
71- sock.connect(sa)
72- return sock
73-
74- except socket.error as msg:
75- if sock is not None:
76- sock.close()
77-
78- raise socket.error(msg)
79-
80-
81 class ProxyHTTPConnection(http.client.HTTPConnection):
82
83 _ports = {"http": http.client.HTTP_PORT, "https": http.client.HTTPS_PORT}
84@@ -96,9 +61,11 @@
85 def connect(self):
86 http.client.HTTPConnection.connect(self)
87 #send proxy CONNECT request
88- self.send("CONNECT %s:%d HTTP/1.0\r\n\r\n" % (self._real_host, self._real_port))
89+ self.send((
90+ "CONNECT %s:%d HTTP/1.0\r\n\r\n" % (self._real_host, self._real_port)
91+ ).encode("ascii"))
92 #expect a HTTP/1.0 200 Connection established
93- response = self.response_class(self.sock, strict=self.strict, method=self._method)
94+ response = self.response_class(self.sock, method=self._method)
95 (version, code, message) = response._read_status()
96 #probably here we can handle auth requests...
97 if code != 200:
98@@ -107,9 +74,9 @@
99 raise socket.error("Proxy connection failed: %d %s" % (code, message.strip()))
100 #eat up header block from proxy....
101 while True:
102- #should not use directly fp probablu
103+ #should not use directly fp probably
104 line = response.fp.readline()
105- if line == "\r\n":
106+ if line == b"\r\n":
107 break
108
109
110@@ -124,7 +91,7 @@
111
112 def connect(self):
113 ProxyHTTPConnection.connect(self)
114- self.sock = _ssl_wrap_socket(self.sock, self.key_file, self.cert_file)
115+ self.sock = ssl.wrap_socket(self.sock, self.key_file, self.cert_file)
116
117
118 class VerifiedHTTPSConnection(http.client.HTTPSConnection):
119@@ -162,14 +129,14 @@
120 def connect(self):
121 # overrides the version in httplib so that we do
122 # certificate verification
123- sock = create_connection((self.host, self.port), self.timeout)
124+ sock = socket.create_connection((self.host, self.port), self.timeout)
125 if self._tunnel_host:
126 self.sock = sock
127 self._tunnel()
128
129 # wrap the socket using verification with the root
130 # certs in trusted_root_certs
131- self.sock = _ssl_wrap_socket(sock,
132+ self.sock = ssl.wrap_socket(sock,
133 self.key_file,
134 self.cert_file,
135 cert_reqs=ssl.CERT_REQUIRED,
136@@ -295,9 +262,9 @@
137 fields, files)
138 elif fields:
139 content_type = b"application/x-www-form-urlencoded"
140- body = urllib.parse.urlencode(fields)
141+ body = urllib.parse.urlencode(fields).encode("utf-8")
142 else:
143- body = ""
144+ body = b""
145
146 return content_type, body
147

Subscribers

People subscribed via source and target branches