launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #24368
[Merge] ~cjwatson/launchpad:das-setchroot-bytes into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:das-setchroot-bytes into launchpad:master.
Commit message:
Make DistroArchSeries.setChroot take data as bytes
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/379666
More explicit, and needed for Python 3.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:das-setchroot-bytes into launchpad:master.
diff --git a/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py b/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py
index 74290a4..32cd64e 100644
--- a/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py
+++ b/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py
@@ -91,7 +91,7 @@ class TestDistroArchSeriesWebservice(TestCaseWithFactory):
webservice = launchpadlib_for("testing", user, version='devel')
ws_das = ws_object(webservice, das)
self.assertRaises(
- Unauthorized, ws_das.setChroot, data='xyz', sha1sum='0')
+ Unauthorized, ws_das.setChroot, data=b'xyz', sha1sum='0')
self.assertRaises(Unauthorized, ws_das.removeChroot)
def test_setChroot_wrong_sha1sum(self):
@@ -101,7 +101,7 @@ class TestDistroArchSeriesWebservice(TestCaseWithFactory):
webservice = launchpadlib_for("testing", user)
ws_das = ws_object(webservice, das)
e = self.assertRaises(
- BadRequest, ws_das.setChroot, data='zyx', sha1sum='x')
+ BadRequest, ws_das.setChroot, data=b'zyx', sha1sum='x')
self.assertEqual("Chroot upload checksums do not match", e.content)
def test_setChroot_missing_trailing_cr(self):
@@ -117,7 +117,7 @@ class TestDistroArchSeriesWebservice(TestCaseWithFactory):
ws_das = ws_object(webservice, das)
sha1 = '95e0c0e09be59e04eb0e312e5daa11a2a830e526'
ws_das.setChroot(
- data='foo\r', sha1sum='95e0c0e09be59e04eb0e312e5daa11a2a830e526')
+ data=b'foo\r', sha1sum='95e0c0e09be59e04eb0e312e5daa11a2a830e526')
self.assertEqual(sha1, das.getChroot().content.sha1)
def test_setChroot_removeChroot(self):
@@ -129,11 +129,11 @@ class TestDistroArchSeriesWebservice(TestCaseWithFactory):
webservice = launchpadlib_for("testing", user)
ws_das = ws_object(webservice, das)
sha1 = hashlib.sha1('abcxyz').hexdigest()
- ws_das.setChroot(data='abcxyz', sha1sum=sha1)
+ ws_das.setChroot(data=b'abcxyz', sha1sum=sha1)
self.assertTrue(ws_das.chroot_url.endswith(expected_file))
ws_das.removeChroot()
self.assertIsNone(ws_das.chroot_url)
- ws_das.setChroot(data='abcxyz', sha1sum=sha1)
+ ws_das.setChroot(data=b'abcxyz', sha1sum=sha1)
self.assertTrue(ws_das.chroot_url.endswith(expected_file))
def test_setChroot_removeChroot_pocket(self):
@@ -142,9 +142,9 @@ class TestDistroArchSeriesWebservice(TestCaseWithFactory):
webservice = launchpadlib_for("testing", user)
ws_das = ws_object(webservice, das)
sha1_1 = hashlib.sha1('abcxyz').hexdigest()
- ws_das.setChroot(data='abcxyz', sha1sum=sha1_1)
+ ws_das.setChroot(data=b'abcxyz', sha1sum=sha1_1)
sha1_2 = hashlib.sha1('123456').hexdigest()
- ws_das.setChroot(data='123456', sha1sum=sha1_2, pocket='Updates')
+ ws_das.setChroot(data=b'123456', sha1sum=sha1_2, pocket='Updates')
release_chroot = das.getChroot(pocket=PackagePublishingPocket.RELEASE)
self.assertEqual(sha1_1, release_chroot.content.sha1)
updates_chroot = das.getChroot(pocket=PackagePublishingPocket.UPDATES)
@@ -165,7 +165,7 @@ class TestDistroArchSeriesWebservice(TestCaseWithFactory):
release_chroot_url, ws_das.getChrootURL(pocket='Updates'))
self.assertEqual(
release_chroot_url, ws_das.getChrootURL(pocket='Proposed'))
- ws_das.setChroot(data='123456', sha1sum=sha1_2, pocket='Updates')
+ ws_das.setChroot(data=b'123456', sha1sum=sha1_2, pocket='Updates')
updates_chroot = das.getChroot(pocket=PackagePublishingPocket.UPDATES)
self.assertEqual(sha1_2, updates_chroot.content.sha1)
with person_logged_in(user):
@@ -183,9 +183,9 @@ class TestDistroArchSeriesWebservice(TestCaseWithFactory):
webservice = launchpadlib_for("testing", user)
ws_das = ws_object(webservice, das)
sha1_1 = hashlib.sha1('abcxyz').hexdigest()
- ws_das.setChroot(data='abcxyz', sha1sum=sha1_1)
+ ws_das.setChroot(data=b'abcxyz', sha1sum=sha1_1)
sha1_2 = hashlib.sha1('123456').hexdigest()
- ws_das.setChroot(data='123456', sha1sum=sha1_2, image_type='LXD image')
+ ws_das.setChroot(data=b'123456', sha1sum=sha1_2, image_type='LXD image')
chroot_image = das.getChroot(image_type=BuildBaseImageType.CHROOT)
self.assertEqual(sha1_1, chroot_image.content.sha1)
lxd_image = das.getChroot(image_type=BuildBaseImageType.LXD)
diff --git a/lib/lp/soyuz/model/distroarchseries.py b/lib/lp/soyuz/model/distroarchseries.py
index df0543b..aedbe7c 100644
--- a/lib/lp/soyuz/model/distroarchseries.py
+++ b/lib/lp/soyuz/model/distroarchseries.py
@@ -7,8 +7,8 @@ __all__ = [
'PocketChroot'
]
-from cStringIO import StringIO
import hashlib
+from io import BytesIO
from sqlobject import (
BoolCol,
@@ -204,7 +204,7 @@ class DistroArchSeries(SQLBase):
# the file content from the request, since the passed in one has been
# wrongly encoded.
data = get_raw_form_value_from_current_request(data, 'data')
- if isinstance(data, str):
+ if isinstance(data, bytes):
filecontent = data
else:
filecontent = data.read()
@@ -232,7 +232,7 @@ class DistroArchSeries(SQLBase):
self.distroseries.distribution.name, self.distroseries.name,
self.architecturetag)
lfa = getUtility(ILibraryFileAliasSet).create(
- name=filename, size=len(filecontent), file=StringIO(filecontent),
+ name=filename, size=len(filecontent), file=BytesIO(filecontent),
contentType='application/octet-stream')
if lfa.content.sha1 != sha1sum:
raise InvalidChrootUploaded("Chroot upload checksums do not match")