Merge lp:~ericsnowcurrently/landscape-client/fix-1681561-bytes-formatting into lp:~landscape/landscape-client/trunk

Proposed by Eric Snow
Status: Merged
Approved by: Eric Snow
Approved revision: 1014
Merged at revision: 1015
Proposed branch: lp:~ericsnowcurrently/landscape-client/fix-1681561-bytes-formatting
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 104 lines (+21/-13)
4 files modified
landscape/lib/bpickle.py (+13/-9)
landscape/lib/tests/test_bpickle.py (+3/-0)
landscape/package/skeleton.py (+4/-3)
landscape/package/tests/test_releaseupgrader.py (+1/-1)
To merge this branch: bzr merge lp:~ericsnowcurrently/landscape-client/fix-1681561-bytes-formatting
Reviewer Review Type Date Requested Status
Francis Ginther (community) Approve
Simon Poirier (community) Approve
🤖 Landscape Builder test results Approve
Review via email: mp+322316@code.launchpad.net

Commit message

Do not use bytes formatting.

(fixed lp:1681561)

It is not supported on Trusty (Python 3.4).

Description of the change

Do not use bytes formatting.

(fixed lp:1681561)

It is not supported on Trusty (Python 3.4).

Testing instructions:

./scripts/landscape-client -c root-client.conf

To post a comment you must log in.
Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: TRIAL_ARGS=-j4 make ci-check
Result: Fail
Revno: 1013
Branch: lp:~ericsnowcurrently/landscape-client/fix-1681561-bytes-formatting
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3869/

review: Needs Fixing (test results)
Revision history for this message
Simon Poirier (simpoir) :
review: Needs Fixing
1014. By Eric Snow

Do not assume bytes are always utf-8.

Revision history for this message
Eric Snow (ericsnowcurrently) :
Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: TRIAL_ARGS=-j4 make ci-check
Result: Success
Revno: 1014
Branch: lp:~ericsnowcurrently/landscape-client/fix-1681561-bytes-formatting
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3870/

review: Approve (test results)
Revision history for this message
Simon Poirier (simpoir) wrote :

+1 thanks for the fix

review: Approve
Revision history for this message
Francis Ginther (fginther) wrote :

Looks good, couldn't find any missing cases that needed conversion.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/lib/bpickle.py'
2--- landscape/lib/bpickle.py 2017-04-06 17:59:25 +0000
3+++ landscape/lib/bpickle.py 2017-04-11 14:13:49 +0000
4@@ -59,32 +59,36 @@
5
6
7 def dumps_bool(obj):
8- return b"b%d" % int(obj)
9+ return ("b%d" % int(obj)
10+ ).encode("utf-8")
11
12
13 def dumps_int(obj):
14- return b"i%d;" % obj
15+ return ("i%d;" % obj
16+ ).encode("utf-8")
17
18
19 def dumps_float(obj):
20- return b"f%r;" % obj
21+ return ("f%r;" % obj
22+ ).encode("utf-8")
23
24
25 def dumps_bytes(obj):
26- return b"s%d:%s" % (len(obj), obj)
27+ return ("s%d:" % (len(obj),)).encode("utf-8") + obj
28
29
30 def dumps_unicode(obj):
31- obj = obj.encode("utf-8")
32- return b"u%d:%s" % (len(obj), obj)
33+ bobj = obj.encode("utf-8")
34+ return ("u%d:%s" % (len(bobj), obj)
35+ ).encode("utf-8")
36
37
38 def dumps_list(obj, _dt=dumps_table):
39- return b"l%s;" % b"".join([_dt[type(val)](val) for val in obj])
40+ return b"l" + b"".join([_dt[type(val)](val) for val in obj]) + b";"
41
42
43 def dumps_tuple(obj, _dt=dumps_table):
44- return b"t%s;" % b"".join([_dt[type(val)](val) for val in obj])
45+ return b"t" + b"".join([_dt[type(val)](val) for val in obj]) + b";"
46
47
48 def dumps_dict(obj, _dt=dumps_table):
49@@ -96,7 +100,7 @@
50 val = obj[key]
51 append(_dt[type(key)](key))
52 append(_dt[type(val)](val))
53- return b"d%s;" % b"".join(res)
54+ return b"d" + b"".join(res) + b";"
55
56
57 def dumps_none(obj):
58
59=== modified file 'landscape/lib/tests/test_bpickle.py'
60--- landscape/lib/tests/test_bpickle.py 2017-04-06 14:56:07 +0000
61+++ landscape/lib/tests/test_bpickle.py 2017-04-11 14:13:49 +0000
62@@ -16,6 +16,9 @@
63 self.assertTrue("e" in repr(number))
64 self.assertAlmostEquals(bpickle.loads(bpickle.dumps(number)), number)
65
66+ def test_bytes(self):
67+ self.assertEqual(bpickle.loads(bpickle.dumps(b'foo')), b'foo')
68+
69 def test_string(self):
70 self.assertEqual(bpickle.loads(bpickle.dumps('foo')), 'foo')
71
72
73=== modified file 'landscape/package/skeleton.py'
74--- landscape/package/skeleton.py 2017-03-17 08:56:02 +0000
75+++ landscape/package/skeleton.py 2017-04-11 14:13:49 +0000
76@@ -52,12 +52,13 @@
77 return self._hash
78 # We use ascii here as encoding for backwards compatibility as it was
79 # default encoding for conversion from unicode to bytes in Python 2.7.
80- package_info = b"[%d %s %s]" % (
81- self.type, self.name.encode("ascii"), self.version.encode("ascii"))
82+ package_info = ("[%d %s %s]" % (self.type, self.name, self.version)
83+ ).encode("ascii")
84 digest = sha1(package_info)
85 self.relations.sort()
86 for pair in self.relations:
87- digest.update(b"[%d %s]" % (pair[0], pair[1].encode("ascii")))
88+ digest.update(("[%d %s]" % (pair[0], pair[1])
89+ ).encode("ascii"))
90 return digest.digest()
91
92 def set_hash(self, package_hash):
93
94=== modified file 'landscape/package/tests/test_releaseupgrader.py'
95--- landscape/package/tests/test_releaseupgrader.py 2017-03-30 00:18:42 +0000
96+++ landscape/package/tests/test_releaseupgrader.py 2017-04-11 14:13:49 +0000
97@@ -523,7 +523,7 @@
98 self.assertFalse(os.path.exists(upgrade_tool_directory))
99 self.assertEqual(
100 out,
101- b"--force-apt-update\n%s\n" % os.getcwd().encode("utf-8"))
102+ ("--force-apt-update\n%s\n" % os.getcwd()).encode("utf-8"))
103 self.assertEqual(err, b"")
104 self.assertEqual(code, 0)
105

Subscribers

People subscribed via source and target branches

to all changes: