launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #25581
[Merge] ~cjwatson/txpkgupload:py3-writefile-binary into txpkgupload:master
Colin Watson has proposed merging ~cjwatson/txpkgupload:py3-writefile-binary into txpkgupload:master.
Commit message:
Make UploadFileSystem.writefile open files in binary mode
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/txpkgupload/+git/txpkgupload/+merge/392997
txpkgupload doesn't know anything about the structure of the files being uploaded, so it doesn't make sense for it to assume text.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/txpkgupload:py3-writefile-binary into txpkgupload:master.
diff --git a/src/txpkgupload/filesystem.py b/src/txpkgupload/filesystem.py
index eccf4b7..7889628 100644
--- a/src/txpkgupload/filesystem.py
+++ b/src/txpkgupload/filesystem.py
@@ -213,14 +213,14 @@ class UploadFileSystem:
if start and end and end <= start:
return
if append:
- open_flag = 'a'
+ open_flag = 'ab'
elif start or end:
- open_flag = "r+"
+ open_flag = "r+b"
if not os.path.exists(full_path):
- open(full_path, 'w')
+ open(full_path, 'wb')
else:
- open_flag = 'w'
+ open_flag = 'wb'
outstream = open(full_path, open_flag)
if start:
outstream.seek(start)
diff --git a/src/txpkgupload/tests/filesystem.txt b/src/txpkgupload/tests/filesystem.txt
index e630558..d6e816e 100644
--- a/src/txpkgupload/tests/filesystem.txt
+++ b/src/txpkgupload/tests/filesystem.txt
@@ -284,7 +284,7 @@ file does not exist or is a directory.
>>> ufs.remove(testfile)
>>> os.path.exists(full_testfile)
False
- >>> open(full_testfile, 'w').write("contents of the file")
+ >>> open(full_testfile, 'wb').write(b"contents of the file")
>>> ufs.remove(testdir)
Traceback (most recent call last):
@@ -409,7 +409,7 @@ If `end` is None, then the file is truncated after the data are
written.
>>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 9)
- >>> open(full_testfile).read() == "contents MOO"
+ >>> open(full_testfile, "rb").read() == b"contents MOO"
True
>>> ufs.writefile(testfile, io.BytesIO(testfile_contents))