launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #24344
[Merge] ~cjwatson/launchpad:bytes-to-tarfile into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:bytes-to-tarfile into launchpad:master.
Commit message:
Port lp.services.helpers.string_to_tarfile to Python 3
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/379471
I've renamed it to bytes_to_tarfile, since that's more explicit.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:bytes-to-tarfile into launchpad:master.
diff --git a/lib/lp/services/helpers.py b/lib/lp/services/helpers.py
index 8382275..a23baa8 100644
--- a/lib/lp/services/helpers.py
+++ b/lib/lp/services/helpers.py
@@ -12,8 +12,8 @@ __metaclass__ = type
from collections import OrderedDict
from difflib import unified_diff
+from io import BytesIO
import re
-from StringIO import StringIO
import subprocess
import tarfile
import warnings
@@ -87,10 +87,10 @@ def backslashreplace(str):
return str.decode('UTF-8').encode('ASCII', 'backslashreplace')
-def string_to_tarfile(s):
- """Convert a binary string containing a tar file into a tar file obj."""
+def bytes_to_tarfile(s):
+ """Convert a byte string containing a tar file into a tar file obj."""
- return tarfile.open('', 'r', StringIO(s))
+ return tarfile.open('', 'r', BytesIO(s))
def simple_popen2(command, input, env=None, in_bufsize=1024, out_bufsize=128):
diff --git a/lib/lp/translations/doc/poexport-language-pack.txt b/lib/lp/translations/doc/poexport-language-pack.txt
index d97524f..94b3624 100644
--- a/lib/lp/translations/doc/poexport-language-pack.txt
+++ b/lib/lp/translations/doc/poexport-language-pack.txt
@@ -10,7 +10,7 @@ Some initialization tasks:
>>> import pytz
>>> import transaction
>>> from lp.testing import login
- >>> from lp.services.helpers import string_to_tarfile
+ >>> from lp.services.helpers import bytes_to_tarfile
>>> from lp.app.interfaces.launchpad import ILaunchpadCelebrities
>>> from lp.translations.scripts.language_pack import (
... export_language_pack)
@@ -73,7 +73,7 @@ Check that the log looks ok.
# Get the generated tarball.
- >>> tarfile = string_to_tarfile(language_pack.file.read())
+ >>> tarfile = bytes_to_tarfile(language_pack.file.read())
The tarball has the right members.
@@ -210,7 +210,7 @@ We are now ready to get an exported language pack with XPI files.
We get other entries in language pack + en-US.xpi file and the
translations in .po file format.
- >>> tarfile = string_to_tarfile(language_pack.file.read())
+ >>> tarfile = bytes_to_tarfile(language_pack.file.read())
>>> examine_tarfile(tarfile)
| - | rosetta-grumpy
| 1 | rosetta-grumpy/mapping.txt
@@ -333,7 +333,7 @@ Check that the log looks ok.
# Get the generated tarball.
- >>> tarfile = string_to_tarfile(language_pack.file.read())
+ >>> tarfile = bytes_to_tarfile(language_pack.file.read())
>>> examine_tarfile(tarfile)
| - | rosetta-grumpy
| - | rosetta-grumpy/cy
@@ -428,7 +428,7 @@ should get only files that were updated after 2000-01-02.
# Get the generated tarball.
- >>> tarfile = string_to_tarfile(language_pack.file.read())
+ >>> tarfile = bytes_to_tarfile(language_pack.file.read())
Now, there is only one file exported for the 'test' domain, the one that
had the modification date after the last generated language pack. We
@@ -479,7 +479,7 @@ that was exported on 2000-01-03:
The Spanish translation has not changed since 2000-01-03, but the
template has. That's why we get both translations:
- >>> tarfile = string_to_tarfile(language_pack.file.read())
+ >>> tarfile = bytes_to_tarfile(language_pack.file.read())
>>> examine_tarfile(tarfile)
| - | rosetta-grumpy
| - | rosetta-grumpy/cy
diff --git a/lib/lp/translations/doc/poexport-request-productseries.txt b/lib/lp/translations/doc/poexport-request-productseries.txt
index 4e39210..1978e3e 100644
--- a/lib/lp/translations/doc/poexport-request-productseries.txt
+++ b/lib/lp/translations/doc/poexport-request-productseries.txt
@@ -85,8 +85,8 @@ The email contains a URL linking to where the exported file can be downloaded.
Let's download it and make sure the contents look ok.
>>> from six.moves.urllib.request import urlopen
- >>> from lp.services.helpers import string_to_tarfile
- >>> tarball = string_to_tarfile(urlopen(url).read())
+ >>> from lp.services.helpers import bytes_to_tarfile
+ >>> tarball = bytes_to_tarfile(urlopen(url).read())
>>> for name in sorted(tarball.getnames()):
... print(name)
evolution-2.2
diff --git a/lib/lp/translations/doc/poexport-request.txt b/lib/lp/translations/doc/poexport-request.txt
index a95d7c0..c87ec82 100644
--- a/lib/lp/translations/doc/poexport-request.txt
+++ b/lib/lp/translations/doc/poexport-request.txt
@@ -88,8 +88,8 @@ The email contains a URL linking to where the exported file can be downloaded.
Let's download it and make sure the contents look ok.
>>> from six.moves.urllib.request import urlopen
- >>> from lp.services.helpers import string_to_tarfile
- >>> tarball = string_to_tarfile(urlopen(url).read())
+ >>> from lp.services.helpers import bytes_to_tarfile
+ >>> tarball = bytes_to_tarfile(urlopen(url).read())
>>> for name in sorted(tarball.getnames()):
... print(name)
pmount
diff --git a/lib/lp/translations/doc/potemplate.txt b/lib/lp/translations/doc/potemplate.txt
index 5378fd6..d4abc2f 100644
--- a/lib/lp/translations/doc/potemplate.txt
+++ b/lib/lp/translations/doc/potemplate.txt
@@ -585,9 +585,9 @@ This includes the 'pt' POFile that was created earlier on the
'evolution' product as this is sharing translations with the source
package that this potemplate is from.
- >>> from lp.services.helpers import string_to_tarfile
- >>> tarfile_string = exported_translation_file.read()
- >>> tarfile = string_to_tarfile(tarfile_string)
+ >>> from lp.services.helpers import bytes_to_tarfile
+ >>> tarfile_bytes = exported_translation_file.read()
+ >>> tarfile = bytes_to_tarfile(tarfile_bytes)
>>> sorted(tarfile.getnames())
['evolution-2.2', 'evolution-2.2/evolution-2.2-es.po',
@@ -604,7 +604,7 @@ The *-es.po file is indeed the Spanish translation...
And GNU tar can cope with it.
>>> from lp.services.helpers import simple_popen2
- >>> contents = simple_popen2(['tar', 'ztf', '-'], tarfile_string)
+ >>> contents = simple_popen2(['tar', 'ztf', '-'], tarfile_bytes)
>>> for line in sorted(contents.splitlines()):
... print(line)
evolution-2.2/
@@ -617,6 +617,6 @@ And GNU tar can cope with it.
>>> pofile = simple_popen2(
... ['tar', 'zxfO', '-', 'evolution-2.2/evolution-2.2-es.po'],
- ... tarfile_string)
+ ... tarfile_bytes)
>>> pofile.split(b'\n')[0]
'# traducci\xc3\xb3n de es.po al Spanish'
diff --git a/lib/lp/translations/utilities/doc/gettext_mo_exporter.txt b/lib/lp/translations/utilities/doc/gettext_mo_exporter.txt
index 872a56e..a556fb8 100644
--- a/lib/lp/translations/utilities/doc/gettext_mo_exporter.txt
+++ b/lib/lp/translations/utilities/doc/gettext_mo_exporter.txt
@@ -10,7 +10,7 @@ You can read more about MO file format on:
http://www.gnu.org/software/gettext/manual/html_chapter/gettext_10.html#MO-Files
>>> from zope.interface.verify import verifyObject
- >>> from lp.services.helpers import string_to_tarfile
+ >>> from lp.services.helpers import bytes_to_tarfile
>>> from lp.translations.interfaces.translationexporter import (
... ITranslationFormatExporter)
>>> from lp.translations.utilities.gettext_mo_exporter import (
@@ -85,7 +85,7 @@ When we export more than one file, we get a tarball.
>>> file_content = exported_file.read()
>>> is_valid_mofile(file_content)
False
- >>> tarfile = string_to_tarfile(file_content)
+ >>> tarfile = bytes_to_tarfile(file_content)
>>> for member in tarfile.getmembers():
... if member.isreg():
... size = len(tarfile.extractfile(member).read())