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
1diff --git a/lib/lp/services/librarian/client.py b/lib/lp/services/librarian/client.py
2index bc35ec4..6787768 100644
3--- a/lib/lp/services/librarian/client.py
4+++ b/lib/lp/services/librarian/client.py
5@@ -134,12 +134,12 @@ class FileUploadClient:
6 raise UploadFailed('Server said early: ' + response)
7
8 def _sendLine(self, line, check_for_error_responses=True):
9- self.state.f.write(six.ensure_binary(line + '\r\n'))
10+ self.state.f.write(line + b'\r\n')
11 if check_for_error_responses:
12 self._checkError()
13
14 def _sendHeader(self, name, value):
15- self._sendLine('%s: %s' % (name, value))
16+ self._sendLine(six.ensure_binary('%s: %s' % (name, value)))
17
18 def addFile(self, name, size, file, contentType, expires=None,
19 debugID=None, allow_zero_length=False):
20@@ -190,7 +190,7 @@ class FileUploadClient:
21 "SELECT nextval('libraryfilealias_id_seq')").get_one()[0]
22
23 # Send command
24- self._sendLine('STORE %d %s' % (size, name))
25+ self._sendLine(b'STORE %d %s' % (size, name))
26
27 # Send headers
28 self._sendHeader('Database-Name', databaseName)
29@@ -204,7 +204,7 @@ class FileUploadClient:
30 # server when no data will be sent. Otherwise
31 # _checkError() might consume the "200" response which
32 # is supposed to be read below in this method.
33- self._sendLine('', check_for_error_responses=(size > 0))
34+ self._sendLine(b'', check_for_error_responses=(size > 0))
35
36 # Prepare to the upload the file
37 md5_digester = hashlib.md5()
38@@ -261,10 +261,11 @@ class FileUploadClient:
39 raise TypeError('No data')
40 if size <= 0:
41 raise UploadFailed('No data')
42+ name = six.ensure_binary(name)
43 self._connect()
44 try:
45 database_name = ConnectionString(dbconfig.main_master).dbname
46- self._sendLine('STORE %d %s' % (size, name))
47+ self._sendLine(b'STORE %d %s' % (size, name))
48 self._sendHeader('Database-Name', database_name)
49 self._sendHeader('Content-Type', str(contentType))
50 if expires is not None:
51@@ -272,7 +273,7 @@ class FileUploadClient:
52 self._sendHeader('File-Expires', str(int(epoch)))
53
54 # Send blank line
55- self._sendLine('')
56+ self._sendLine(b'')
57
58 # Prepare to the upload the file
59 bytesWritten = 0

Subscribers

People subscribed via source and target branches

to status/vote changes: