launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #26402
[Merge] ~cjwatson/launchpad:py3-changes-changelog-copyright-bytes into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-changes-changelog-copyright-bytes into launchpad:master.
Commit message:
Read changes/changelog/copyright files in binary mode
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/398549
The data read from these is used as the input to functions that expect bytes.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-changes-changelog-copyright-bytes into launchpad:master.
diff --git a/lib/lp/archiveuploader/nascentupload.py b/lib/lp/archiveuploader/nascentupload.py
index 6602200..be9cdcc 100644
--- a/lib/lp/archiveuploader/nascentupload.py
+++ b/lib/lp/archiveuploader/nascentupload.py
@@ -715,12 +715,11 @@ class NascentUpload:
# very small, and at some point the script infrastructure will
# only send emails when the script exits successfully.
if notify:
- changes_file_object = open(self.changes.filepath, "r")
- self.queue_root.notify(
- summary_text=self.warning_message,
- changes_file_object=changes_file_object,
- logger=self.logger)
- changes_file_object.close()
+ with open(self.changes.filepath, "rb") as changes_file_object:
+ self.queue_root.notify(
+ summary_text=self.warning_message,
+ changes_file_object=changes_file_object,
+ logger=self.logger)
return True
except QueueInconsistentStateError as e:
@@ -762,7 +761,7 @@ class NascentUpload:
if not self.queue_root:
self.queue_root = self._createQueueEntry()
- with open(self.changes.filepath, "r") as changes_file_object:
+ with open(self.changes.filepath, "rb") as changes_file_object:
self.queue_root.notify(
status=PackageUploadStatus.REJECTED,
summary_text=self.rejection_message,
diff --git a/lib/lp/archiveuploader/tests/__init__.py b/lib/lp/archiveuploader/tests/__init__.py
index ff5da4d..e5abd8d 100644
--- a/lib/lp/archiveuploader/tests/__init__.py
+++ b/lib/lp/archiveuploader/tests/__init__.py
@@ -49,7 +49,7 @@ def insertFakeChangesFile(fileID, path=None):
"""
if path is None:
path = datadir("ed-0.2-21/ed_0.2-21_source.changes")
- with open(path, 'r') as changes_file_obj:
+ with open(path, 'rb') as changes_file_obj:
test_changes_file = changes_file_obj.read()
fillLibrarianFile(fileID, content=test_changes_file)
diff --git a/lib/lp/archiveuploader/tests/test_sync_notification.py b/lib/lp/archiveuploader/tests/test_sync_notification.py
index 45d6704..4eb00f0 100644
--- a/lib/lp/archiveuploader/tests/test_sync_notification.py
+++ b/lib/lp/archiveuploader/tests/test_sync_notification.py
@@ -54,7 +54,8 @@ class FakeChangesFile:
self.filename = os.path.basename(file_path)
self.architectures = ['i386']
self.suite_name = '-'.join([spph.distroseries.name, spph.pocket.name])
- self.raw_content = open(file_path).read()
+ with open(file_path, 'rb') as f:
+ self.raw_content = f.read()
self.signingkey = None
parseChanges = FakeMethod([])
diff --git a/lib/lp/soyuz/doc/distroseriesqueue-notify.txt b/lib/lp/soyuz/doc/distroseriesqueue-notify.txt
index 42cfdbc..1fb94fe 100644
--- a/lib/lp/soyuz/doc/distroseriesqueue-notify.txt
+++ b/lib/lp/soyuz/doc/distroseriesqueue-notify.txt
@@ -43,7 +43,7 @@ this doctest.
>>> changes_file_path = datadir(
... 'suite/netapplet_1.0-1/netapplet_1.0-1_source.changes')
- >>> changes_file = open(changes_file_path,'r')
+ >>> changes_file = open(changes_file_path, 'rb')
>>> from lp.services.log.logger import FakeLogger
>>> netapplet_upload.notify(
... changes_file_object=changes_file, logger=FakeLogger())
@@ -117,7 +117,7 @@ Now request the email:
>>> changes_file_path = datadir(
... 'suite/netapplet_1.0-1-signed/netapplet_1.0-1_source.changes')
- >>> changes_file = open(changes_file_path,'r')
+ >>> changes_file = open(changes_file_path, 'rb')
>>> netapplet_upload.setAccepted()
>>> netapplet_upload.notify(
... changes_file_object=changes_file, logger=FakeLogger())
@@ -217,7 +217,7 @@ parameter provided that everything is already committed to the database
demonstrates this usage:
>>> from lp.services.librarianserver.testing.server import fillLibrarianFile
- >>> changes_file = open(changes_file_path,"r")
+ >>> changes_file = open(changes_file_path, "rb")
>>> fillLibrarianFile(1, content=changes_file.read())
>>> changes_file.close()
>>> from lp.soyuz.enums import PackageUploadStatus
diff --git a/lib/lp/soyuz/model/sourcepackagerelease.py b/lib/lp/soyuz/model/sourcepackagerelease.py
index 03539e1..423e2a1 100644
--- a/lib/lp/soyuz/model/sourcepackagerelease.py
+++ b/lib/lp/soyuz/model/sourcepackagerelease.py
@@ -450,4 +450,4 @@ class SourcePackageRelease(SQLBase):
return None
output = "\n\n".join(chunks)
- return output.decode("utf-8", "replace")
+ return six.ensure_text(output, "utf-8", "replace")
diff --git a/lib/lp/soyuz/scripts/gina/handlers.py b/lib/lp/soyuz/scripts/gina/handlers.py
index 85f7fce..94aac78 100644
--- a/lib/lp/soyuz/scripts/gina/handlers.py
+++ b/lib/lp/soyuz/scripts/gina/handlers.py
@@ -20,7 +20,7 @@ __all__ = [
'DistroHandler',
]
-from cStringIO import StringIO
+import io
import os
import re
@@ -648,7 +648,7 @@ class SourcePackageHandler:
changelog_lfa = getUtility(ILibraryFileAliasSet).create(
"changelog",
len(src.changelog),
- StringIO(src.changelog),
+ io.BytesIO(src.changelog),
"text/x-debian-source-changelog")
spr.changelog = changelog_lfa
diff --git a/lib/lp/soyuz/scripts/gina/packages.py b/lib/lp/soyuz/scripts/gina/packages.py
index 504e907..861b81d 100644
--- a/lib/lp/soyuz/scripts/gina/packages.py
+++ b/lib/lp/soyuz/scripts/gina/packages.py
@@ -130,7 +130,7 @@ def read_dsc(package, version, component, distro_name, archive_root):
fullpath = os.path.join(source_dir, "debian", "changelog")
changelog = None
if os.path.exists(fullpath):
- with open(fullpath) as f:
+ with open(fullpath, "rb") as f:
changelog = f.read().strip()
else:
log.warning(
@@ -142,13 +142,13 @@ def read_dsc(package, version, component, distro_name, archive_root):
for fullpath in glob.glob(globpath):
if not os.path.exists(fullpath):
continue
- with open(fullpath) as f:
+ with open(fullpath, "rb") as f:
copyright = f.read().strip()
if copyright is None:
log.warning(
"No copyright file found for %s in %s" % (package, source_dir))
- copyright = ''
+ copyright = b''
finally:
shutil.rmtree(source_dir)