Merge ~cjwatson/launchpad:productrelease-addreleasefile-bytes into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 95b68359d767d8ed9f9c67e558680fff25bcb234
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:productrelease-addreleasefile-bytes
Merge into: launchpad:master
Diff against target: 173 lines (+23/-20)
7 files modified
lib/lp/registry/browser/tests/milestone-views.txt (+2/-2)
lib/lp/registry/doc/productrelease-file-download.txt (+5/-5)
lib/lp/registry/doc/productrelease.txt (+1/-1)
lib/lp/registry/interfaces/productrelease.py (+2/-2)
lib/lp/registry/model/productrelease.py (+9/-6)
lib/lp/registry/tests/test_productrelease.py (+3/-3)
lib/lp/testing/factory.py (+1/-1)
Reviewer Review Type Date Requested Status
Tom Wardill (community) Approve
Review via email: mp+379650@code.launchpad.net

Commit message

Make ProductRelease.addReleaseFile take content as bytes

Description of the change

More explicit, and needed for Python 3.

To post a comment you must log in.
Revision history for this message
Tom Wardill (twom) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/registry/browser/tests/milestone-views.txt b/lib/lp/registry/browser/tests/milestone-views.txt
2index 67c6566..2613124 100644
3--- a/lib/lp/registry/browser/tests/milestone-views.txt
4+++ b/lib/lp/registry/browser/tests/milestone-views.txt
5@@ -231,7 +231,7 @@ files. If there is no release, or no files, None is returned.
6 If there are files, these files will be returned as a list.
7
8 >>> release_file = release.addReleaseFile(
9- ... 'test.txt', 'test', 'text/plain', person,
10+ ... 'test.txt', b'test', 'text/plain', person,
11 ... signature_filename='test.txt.asc', signature_content='123',
12 ... description="test file")
13 >>> view = create_view(milestone, '+index')
14@@ -678,7 +678,7 @@ milestone.
15 >>> release = milestone.createProductRelease(
16 ... owner, datetime.now(UTC))
17 >>> release_file = release.addReleaseFile(
18- ... 'test', 'test', 'text/plain', owner, description="test file")
19+ ... 'test', b'test', 'text/plain', owner, description="test file")
20 >>> specification = factory.makeSpecification(product=firefox)
21 >>> specification.milestone = milestone
22 >>> bug = factory.makeBug(target=firefox)
23diff --git a/lib/lp/registry/doc/productrelease-file-download.txt b/lib/lp/registry/doc/productrelease-file-download.txt
24index 3f47337..067e5a7 100644
25--- a/lib/lp/registry/doc/productrelease-file-download.txt
26+++ b/lib/lp/registry/doc/productrelease-file-download.txt
27@@ -49,16 +49,16 @@ Add a file alias to the productrelease.
28 >>> from lp.services.webapp.interfaces import ILaunchBag
29
30 >>> login("foo.bar@canonical.com")
31- >>> from zope.security.proxy import removeSecurityProxy
32- >>> from StringIO import StringIO
33 >>> from datetime import datetime
34+ >>> from io import BytesIO
35 >>> from pytz import UTC
36+ >>> from zope.security.proxy import removeSecurityProxy
37 >>> def add_release_file(release, file_content, name, description,
38 ... date_uploaded=None):
39 ... user = getUtility(ILaunchBag).user
40 ... result = release.addReleaseFile(
41 ... filename=name,
42- ... file_content=StringIO(file_content),
43+ ... file_content=BytesIO(file_content),
44 ... content_type='test/plain',
45 ... uploader=user,
46 ... description=description)
47@@ -66,7 +66,7 @@ Add a file alias to the productrelease.
48 ... removeSecurityProxy(result).date_uploaded = date_uploaded
49 ... return result
50 >>> product_release_file = add_release_file(
51- ... rel, 'Some useful information.',
52+ ... rel, b'Some useful information.',
53 ... 'foo.txt', 'Foo file')
54 >>> print product_release_file.description
55 Foo file
56@@ -170,7 +170,7 @@ Let's add some release files to the releases for firefox.
57 >>> from datetime import timedelta
58 >>> now = datetime.now(UTC)
59 >>> for i, release in enumerate(releases):
60- ... content = "Content %d" % i
61+ ... content = b"Content %d" % i
62 ... name = "name%d" % i
63 ... description = "description%d" % i
64 ... upload_date = now + timedelta(days=i)
65diff --git a/lib/lp/registry/doc/productrelease.txt b/lib/lp/registry/doc/productrelease.txt
66index 41ea69c..132cfb7 100644
67--- a/lib/lp/registry/doc/productrelease.txt
68+++ b/lib/lp/registry/doc/productrelease.txt
69@@ -55,7 +55,7 @@ deleted.
70 >>> milestone = firefox_1_0.newMilestone('1.0.10')
71 >>> firefox_1010 = milestone.createProductRelease(owner,
72 ... datetime.now(UTC))
73- >>> firefox_1010.addReleaseFile('test', 'test', 'text/plain', owner)
74+ >>> firefox_1010.addReleaseFile('test', b'test', 'text/plain', owner)
75 <ProductReleaseFile...
76 >>> firefox_1010.destroySelf()
77 Traceback (most recent call last):
78diff --git a/lib/lp/registry/interfaces/productrelease.py b/lib/lp/registry/interfaces/productrelease.py
79index 552b174..c5aef3e 100644
80--- a/lib/lp/registry/interfaces/productrelease.py
81+++ b/lib/lp/registry/interfaces/productrelease.py
82@@ -246,11 +246,11 @@ class IProductReleaseEditRestricted(Interface):
83 The signature file will also be added if available.
84
85 :param filename: Name of the file being uploaded.
86- :param file_content: StringIO or file object.
87+ :param file_content: `io.BytesIO` or binary file object.
88 :param content_type: A MIME content type string.
89 :param uploader: The person who uploaded the file.
90 :param signature_filename: Name of the uploaded gpg signature file.
91- :param signature_content: StringIO or file object.
92+ :param signature_content: `io.BytesIO` or binary file object.
93 :param file_type: An `UpstreamFileType` enum value.
94 :param description: Info about the file.
95 :returns: `IProductReleaseFile` object.
96diff --git a/lib/lp/registry/model/productrelease.py b/lib/lp/registry/model/productrelease.py
97index 16a4e47..6dfc8b3 100644
98--- a/lib/lp/registry/model/productrelease.py
99+++ b/lib/lp/registry/model/productrelease.py
100@@ -9,8 +9,11 @@ __all__ = [
101 'productrelease_to_milestone',
102 ]
103
104+from io import (
105+ BufferedIOBase,
106+ BytesIO,
107+ )
108 import os
109-from StringIO import StringIO
110
111 from sqlobject import (
112 ForeignKey,
113@@ -126,14 +129,14 @@ class ProductRelease(SQLBase):
114 def _getFileObjectAndSize(self, file_or_data):
115 """Return an object and length for file_or_data.
116
117- :param file_or_data: A string or a file object or StringIO object.
118- :return: file object or StringIO object and size.
119+ :param file_or_data: `bytes` or `io.BufferedIOBase`.
120+ :return: binary file object or `io.BytesIO` object and size.
121 """
122- if isinstance(file_or_data, basestring):
123+ if isinstance(file_or_data, bytes):
124 file_size = len(file_or_data)
125- file_obj = StringIO(file_or_data)
126+ file_obj = BytesIO(file_or_data)
127 else:
128- assert isinstance(file_or_data, (file, StringIO)), (
129+ assert isinstance(file_or_data, BufferedIOBase), (
130 "file_or_data is not an expected type")
131 file_obj = file_or_data
132 start = file_obj.tell()
133diff --git a/lib/lp/registry/tests/test_productrelease.py b/lib/lp/registry/tests/test_productrelease.py
134index a93b9e9..26c7410 100644
135--- a/lib/lp/registry/tests/test_productrelease.py
136+++ b/lib/lp/registry/tests/test_productrelease.py
137@@ -78,7 +78,7 @@ class ProductReleaseFileTestcase(TestCaseWithFactory):
138 maintainer = release.milestone.product.owner
139 with person_logged_in(maintainer):
140 release_file = release.addReleaseFile(
141- 'pting.txt', 'test', 'text/plain', maintainer,
142+ 'pting.txt', b'test', 'text/plain', maintainer,
143 file_type=UpstreamFileType.README, description='desc')
144 self.assertEqual('desc', release_file.description)
145 self.assertEqual(UpstreamFileType.README, release_file.filetype)
146@@ -93,7 +93,7 @@ class ProductReleaseFileTestcase(TestCaseWithFactory):
147 with person_logged_in(maintainer):
148 self.assertRaises(
149 InvalidFilename, release.addReleaseFile,
150- library_file.filename, 'test', 'text/plain', maintainer)
151+ library_file.filename, b'test', 'text/plain', maintainer)
152
153 def test_addReleaseFile_only_works_on_public_products(self):
154 owner = self.factory.makePerson()
155@@ -104,4 +104,4 @@ class ProductReleaseFileTestcase(TestCaseWithFactory):
156 self.assertFalse(release.can_have_release_files)
157 self.assertRaises(
158 ProprietaryProduct, release.addReleaseFile,
159- 'README', 'test', 'text/plain', owner)
160+ 'README', b'test', 'text/plain', owner)
161diff --git a/lib/lp/testing/factory.py b/lib/lp/testing/factory.py
162index bac9b17..c3e8a01 100644
163--- a/lib/lp/testing/factory.py
164+++ b/lib/lp/testing/factory.py
165@@ -967,7 +967,7 @@ class BareLaunchpadObjectFactory(ObjectFactory):
166 milestone=milestone)
167 with person_logged_in(release.milestone.product.owner):
168 release_file = release.addReleaseFile(
169- filename, 'test', 'text/plain',
170+ filename, b'test', 'text/plain',
171 uploader=release.milestone.product.owner,
172 signature_filename=signature_filename,
173 signature_content=signature_content,

Subscribers

People subscribed via source and target branches

to status/vote changes: