← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pappacena/turnip:fix-bytes-str-mix into turnip:master

 

Thiago F. Pappacena has proposed merging ~pappacena/turnip:fix-bytes-str-mix into turnip:master with ~pappacena/turnip:make-target-py3-check as a prerequisite.

Commit message:
Fixing bytes/str confusions to make it more compatible with python3.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pappacena/turnip/+git/turnip/+merge/383912
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/turnip:fix-bytes-str-mix into turnip:master.
diff --git a/turnip/helpers.py b/turnip/helpers.py
index a423aff..77e12ed 100644
--- a/turnip/helpers.py
+++ b/turnip/helpers.py
@@ -9,12 +9,16 @@ from __future__ import (
 
 import os.path
 
+import six
+
 
 def compose_path(root, path):
     # Construct the full path, stripping any leading slashes so we
     # resolve absolute paths within the root.
+    root = six.ensure_binary(root, "utf-8")
     full_path = os.path.abspath(os.path.join(
-        root, path.lstrip(os.path.sep.encode('utf-8'))))
+        root,
+        path.lstrip(six.ensure_binary(os.path.sep, 'utf-8'))))
     if not full_path.startswith(os.path.abspath(root)):
         raise ValueError('Path not contained within root')
     return full_path
diff --git a/turnip/pack/tests/test_helpers.py b/turnip/pack/tests/test_helpers.py
index e01406b..a7a3870 100644
--- a/turnip/pack/tests/test_helpers.py
+++ b/turnip/pack/tests/test_helpers.py
@@ -125,7 +125,7 @@ class TestDecodeRequest(TestCase):
         req = b'git-upload-pack /test_repo\0host=git.launchpad.test\0\0'
         self.assertEqual(
             (b'git-upload-pack', b'/test_repo',
-                {b'host': 'git.launchpad.test'}),
+                {b'host': b'git.launchpad.test'}),
             helpers.decode_request(req))
 
     def test_without_parameters(self):
diff --git a/turnip/pack/tests/test_hooks.py b/turnip/pack/tests/test_hooks.py
index 746214e..cc785d8 100644
--- a/turnip/pack/tests/test_hooks.py
+++ b/turnip/pack/tests/test_hooks.py
@@ -283,11 +283,10 @@ class TestPostReceiveHook(HookTestMixin, TestCase):
             default_branch = subprocess.check_output(
                 ['git', 'symbolic-ref', 'HEAD']
                 ).rstrip(b'\n')
-            pushed_branch = str(default_branch + 'notdefault')
-            yield self.assertMergeProposalURLReceived([(
-                b'%s' % pushed_branch,
-                self.old_sha1, self.new_sha1)],
-                {b'%s' % pushed_branch: ['push']})
+            pushed_branch = default_branch + b'notdefault'
+            yield self.assertMergeProposalURLReceived(
+                [(pushed_branch, self.old_sha1, self.new_sha1)],
+                {pushed_branch: ['push']})
         finally:
             os.chdir(curdir)