Merge ~cjwatson/launchpad:py3-file-upload-client into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 238400710a4fd34ebc5c7dff4ff5c776d611efc4
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-file-upload-client
Merge into: launchpad:master
Diff against target: 59 lines (+7/-6)
1 file modified
lib/lp/services/librarian/client.py (+7/-6)
Reviewer Review Type Date Requested Status
Cristian Gonzalez (community) Approve
Review via email: mp+398885@code.launchpad.net

Commit message

Fix FileUploadClient for Python 3

Description of the change

I tried to fix this before, but at the time I couldn't test it completely. This fixes a few bits that I got slightly wrong.

To post a comment you must log in.
Revision history for this message
Cristian Gonzalez (cristiangsp) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/lib/lp/services/librarian/client.py b/lib/lp/services/librarian/client.py
index bc35ec4..6787768 100644
--- a/lib/lp/services/librarian/client.py
+++ b/lib/lp/services/librarian/client.py
@@ -134,12 +134,12 @@ class FileUploadClient:
134 raise UploadFailed('Server said early: ' + response)134 raise UploadFailed('Server said early: ' + response)
135135
136 def _sendLine(self, line, check_for_error_responses=True):136 def _sendLine(self, line, check_for_error_responses=True):
137 self.state.f.write(six.ensure_binary(line + '\r\n'))137 self.state.f.write(line + b'\r\n')
138 if check_for_error_responses:138 if check_for_error_responses:
139 self._checkError()139 self._checkError()
140140
141 def _sendHeader(self, name, value):141 def _sendHeader(self, name, value):
142 self._sendLine('%s: %s' % (name, value))142 self._sendLine(six.ensure_binary('%s: %s' % (name, value)))
143143
144 def addFile(self, name, size, file, contentType, expires=None,144 def addFile(self, name, size, file, contentType, expires=None,
145 debugID=None, allow_zero_length=False):145 debugID=None, allow_zero_length=False):
@@ -190,7 +190,7 @@ class FileUploadClient:
190 "SELECT nextval('libraryfilealias_id_seq')").get_one()[0]190 "SELECT nextval('libraryfilealias_id_seq')").get_one()[0]
191191
192 # Send command192 # Send command
193 self._sendLine('STORE %d %s' % (size, name))193 self._sendLine(b'STORE %d %s' % (size, name))
194194
195 # Send headers195 # Send headers
196 self._sendHeader('Database-Name', databaseName)196 self._sendHeader('Database-Name', databaseName)
@@ -204,7 +204,7 @@ class FileUploadClient:
204 # server when no data will be sent. Otherwise204 # server when no data will be sent. Otherwise
205 # _checkError() might consume the "200" response which205 # _checkError() might consume the "200" response which
206 # is supposed to be read below in this method.206 # is supposed to be read below in this method.
207 self._sendLine('', check_for_error_responses=(size > 0))207 self._sendLine(b'', check_for_error_responses=(size > 0))
208208
209 # Prepare to the upload the file209 # Prepare to the upload the file
210 md5_digester = hashlib.md5()210 md5_digester = hashlib.md5()
@@ -261,10 +261,11 @@ class FileUploadClient:
261 raise TypeError('No data')261 raise TypeError('No data')
262 if size <= 0:262 if size <= 0:
263 raise UploadFailed('No data')263 raise UploadFailed('No data')
264 name = six.ensure_binary(name)
264 self._connect()265 self._connect()
265 try:266 try:
266 database_name = ConnectionString(dbconfig.main_master).dbname267 database_name = ConnectionString(dbconfig.main_master).dbname
267 self._sendLine('STORE %d %s' % (size, name))268 self._sendLine(b'STORE %d %s' % (size, name))
268 self._sendHeader('Database-Name', database_name)269 self._sendHeader('Database-Name', database_name)
269 self._sendHeader('Content-Type', str(contentType))270 self._sendHeader('Content-Type', str(contentType))
270 if expires is not None:271 if expires is not None:
@@ -272,7 +273,7 @@ class FileUploadClient:
272 self._sendHeader('File-Expires', str(int(epoch)))273 self._sendHeader('File-Expires', str(int(epoch)))
273274
274 # Send blank line275 # Send blank line
275 self._sendLine('')276 self._sendLine(b'')
276277
277 # Prepare to the upload the file278 # Prepare to the upload the file
278 bytesWritten = 0279 bytesWritten = 0

Subscribers

People subscribed via source and target branches

to status/vote changes: