Merge lp:~jelmer/brz/python3-xml into lp:brz
- python3-xml
- Merge into trunk
Proposed by
Jelmer Vernooij
Status: | Merged |
---|---|
Approved by: | Jelmer Vernooij |
Approved revision: | no longer in the source branch. |
Merged at revision: | 6982 |
Proposed branch: | lp:~jelmer/brz/python3-xml |
Merge into: | lp:brz |
Prerequisite: | lp:~jelmer/brz/python3-b |
Diff against target: |
400 lines (+100/-49) 4 files modified
breezy/bzr/xml8.py (+4/-8) breezy/bzr/xml_serializer.py (+12/-12) breezy/tests/test_xml.py (+30/-29) python3.passing (+54/-0) |
To merge this branch: | bzr merge lp:~jelmer/brz/python3-xml |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Martin Packman | Approve | ||
Review via email: mp+346434@code.launchpad.net |
Commit message
Port breezy.bzr.xml* to Python3.
Description of the change
Port breezy.bzr.xml* to Python3.
To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote : | # |
> I'm not sure on some of the bare encode() calls here, but it's probably on the
> caller if they pass non-ascii values?
Yeah; this should be ascii only. At some point perhaps we can all just make them regular strings.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'breezy/bzr/xml8.py' | |||
2 | --- breezy/bzr/xml8.py 2018-05-13 02:18:13 +0000 | |||
3 | +++ breezy/bzr/xml8.py 2018-05-22 02:02:43 +0000 | |||
4 | @@ -187,17 +187,15 @@ | |||
5 | 187 | # them. | 187 | # them. |
6 | 188 | decode_utf8 = cache_utf8.decode | 188 | decode_utf8 = cache_utf8.decode |
7 | 189 | revision_id = rev.revision_id | 189 | revision_id = rev.revision_id |
8 | 190 | if isinstance(revision_id, str): | ||
9 | 191 | revision_id = decode_utf8(revision_id) | ||
10 | 192 | format_num = self.format_num | 190 | format_num = self.format_num |
11 | 193 | if self.revision_format_num is not None: | 191 | if self.revision_format_num is not None: |
12 | 194 | format_num = self.revision_format_num | 192 | format_num = self.revision_format_num |
13 | 195 | root = Element('revision', | 193 | root = Element('revision', |
14 | 196 | committer = rev.committer, | 194 | committer = rev.committer, |
15 | 197 | timestamp = '%.3f' % rev.timestamp, | 195 | timestamp = '%.3f' % rev.timestamp, |
17 | 198 | revision_id = revision_id, | 196 | revision_id = decode_utf8(revision_id), |
18 | 199 | inventory_sha1 = rev.inventory_sha1, | 197 | inventory_sha1 = rev.inventory_sha1, |
20 | 200 | format=format_num, | 198 | format=format_num.decode(), |
21 | 201 | ) | 199 | ) |
22 | 202 | if rev.timezone is not None: | 200 | if rev.timezone is not None: |
23 | 203 | root.set('timezone', str(rev.timezone)) | 201 | root.set('timezone', str(rev.timezone)) |
24 | @@ -212,9 +210,7 @@ | |||
25 | 212 | _mod_revision.check_not_reserved_id(parent_id) | 210 | _mod_revision.check_not_reserved_id(parent_id) |
26 | 213 | p = SubElement(pelts, 'revision_ref') | 211 | p = SubElement(pelts, 'revision_ref') |
27 | 214 | p.tail = '\n' | 212 | p.tail = '\n' |
31 | 215 | if isinstance(parent_id, str): | 213 | p.set('revision_id', decode_utf8(parent_id)) |
29 | 216 | parent_id = decode_utf8(parent_id) | ||
30 | 217 | p.set('revision_id', parent_id) | ||
32 | 218 | if rev.properties: | 214 | if rev.properties: |
33 | 219 | self._pack_revision_properties(rev, root) | 215 | self._pack_revision_properties(rev, root) |
34 | 220 | return root | 216 | return root |
35 | @@ -248,7 +244,7 @@ | |||
36 | 248 | if self.revision_format_num is not None: | 244 | if self.revision_format_num is not None: |
37 | 249 | format_num = self.revision_format_num | 245 | format_num = self.revision_format_num |
38 | 250 | if format is not None: | 246 | if format is not None: |
40 | 251 | if format != format_num: | 247 | if format.encode() != format_num: |
41 | 252 | raise BzrError("invalid format version %r on revision" | 248 | raise BzrError("invalid format version %r on revision" |
42 | 253 | % format) | 249 | % format) |
43 | 254 | get_cached = get_utf8_or_ascii | 250 | get_cached = get_utf8_or_ascii |
44 | 255 | 251 | ||
45 | === modified file 'breezy/bzr/xml_serializer.py' | |||
46 | --- breezy/bzr/xml_serializer.py 2018-02-18 15:21:06 +0000 | |||
47 | +++ breezy/bzr/xml_serializer.py 2018-05-22 02:02:43 +0000 | |||
48 | @@ -100,7 +100,7 @@ | |||
49 | 100 | self._write_element(self._pack_revision(rev), f) | 100 | self._write_element(self._pack_revision(rev), f) |
50 | 101 | 101 | ||
51 | 102 | def write_revision_to_string(self, rev): | 102 | def write_revision_to_string(self, rev): |
53 | 103 | return tostring(self._pack_revision(rev)) + '\n' | 103 | return tostring(self._pack_revision(rev)) + b'\n' |
54 | 104 | 104 | ||
55 | 105 | def read_revision(self, f): | 105 | def read_revision(self, f): |
56 | 106 | return self._unpack_revision(self._read_element(f)) | 106 | return self._unpack_revision(self._read_element(f)) |
57 | @@ -110,7 +110,7 @@ | |||
58 | 110 | 110 | ||
59 | 111 | def _write_element(self, elt, f): | 111 | def _write_element(self, elt, f): |
60 | 112 | ElementTree(elt).write(f, 'utf-8') | 112 | ElementTree(elt).write(f, 'utf-8') |
62 | 113 | f.write('\n') | 113 | f.write(b'\n') |
63 | 114 | 114 | ||
64 | 115 | def _read_element(self, f): | 115 | def _read_element(self, f): |
65 | 116 | return ElementTree().parse(f) | 116 | return ElementTree().parse(f) |
66 | @@ -195,9 +195,9 @@ | |||
67 | 195 | decode back into Unicode, and then use the XML escape code. | 195 | decode back into Unicode, and then use the XML escape code. |
68 | 196 | """ | 196 | """ |
69 | 197 | try: | 197 | try: |
71 | 198 | return _map[match.group()] | 198 | return _map[match.group().decode('ascii', 'replace')].encode() |
72 | 199 | except KeyError: | 199 | except KeyError: |
74 | 200 | return ''.join('&#%d;' % ord(uni_chr) | 200 | return b''.join(b'&#%d;' % ord(uni_chr) |
75 | 201 | for uni_chr in match.group().decode('utf8')) | 201 | for uni_chr in match.group().decode('utf8')) |
76 | 202 | 202 | ||
77 | 203 | 203 | ||
78 | @@ -209,7 +209,7 @@ | |||
79 | 209 | # to check if None, rather than try/KeyError | 209 | # to check if None, rather than try/KeyError |
80 | 210 | text = _map.get(unicode_or_utf8_str) | 210 | text = _map.get(unicode_or_utf8_str) |
81 | 211 | if text is None: | 211 | if text is None: |
83 | 212 | if unicode_or_utf8_str.__class__ is text_type: | 212 | if isinstance(unicode_or_utf8_str, text_type): |
84 | 213 | # The alternative policy is to do a regular UTF8 encoding | 213 | # The alternative policy is to do a regular UTF8 encoding |
85 | 214 | # and then escape only XML meta characters. | 214 | # and then escape only XML meta characters. |
86 | 215 | # Performance is equivalent once you use cache_utf8. *However* | 215 | # Performance is equivalent once you use cache_utf8. *However* |
87 | @@ -217,7 +217,7 @@ | |||
88 | 217 | # of bzr. So no net gain. (Perhaps the read code would handle utf8 | 217 | # of bzr. So no net gain. (Perhaps the read code would handle utf8 |
89 | 218 | # better than entity escapes, but cElementTree seems to do just fine | 218 | # better than entity escapes, but cElementTree seems to do just fine |
90 | 219 | # either way) | 219 | # either way) |
92 | 220 | text = bytes(_unicode_re.sub(_unicode_escape_replace, unicode_or_utf8_str)) + b'"' | 220 | text = _unicode_re.sub(_unicode_escape_replace, unicode_or_utf8_str).encode() + b'"' |
93 | 221 | else: | 221 | else: |
94 | 222 | # Plain strings are considered to already be in utf-8 so we do a | 222 | # Plain strings are considered to already be in utf-8 so we do a |
95 | 223 | # slightly different method for escaping. | 223 | # slightly different method for escaping. |
96 | @@ -312,11 +312,11 @@ | |||
97 | 312 | parent_id) | 312 | parent_id) |
98 | 313 | ie.symlink_target = elt_get('symlink_target') | 313 | ie.symlink_target = elt_get('symlink_target') |
99 | 314 | elif kind == 'tree-reference': | 314 | elif kind == 'tree-reference': |
101 | 315 | file_id = elt.attrib['file_id'] | 315 | file_id = get_utf8_or_ascii(elt.attrib['file_id']) |
102 | 316 | name = elt.attrib['name'] | 316 | name = elt.attrib['name'] |
106 | 317 | parent_id = elt.attrib['parent_id'] | 317 | parent_id = get_utf8_or_ascii(elt.attrib['parent_id']) |
107 | 318 | revision = elt.get('revision') | 318 | revision = get_utf8_or_ascii(elt.get('revision')) |
108 | 319 | reference_revision = elt.get('reference_revision') | 319 | reference_revision = get_utf8_or_ascii(elt.get('reference_revision')) |
109 | 320 | ie = inventory.TreeReference(file_id, name, parent_id, revision, | 320 | ie = inventory.TreeReference(file_id, name, parent_id, revision, |
110 | 321 | reference_revision) | 321 | reference_revision) |
111 | 322 | else: | 322 | else: |
112 | @@ -346,7 +346,7 @@ | |||
113 | 346 | if elt.tag != 'inventory': | 346 | if elt.tag != 'inventory': |
114 | 347 | raise errors.UnexpectedInventoryFormat('Root tag is %r' % elt.tag) | 347 | raise errors.UnexpectedInventoryFormat('Root tag is %r' % elt.tag) |
115 | 348 | format = elt.get('format') | 348 | format = elt.get('format') |
117 | 349 | if format != format_num: | 349 | if format.encode() != format_num: |
118 | 350 | raise errors.UnexpectedInventoryFormat('Invalid format version %r' | 350 | raise errors.UnexpectedInventoryFormat('Invalid format version %r' |
119 | 351 | % format) | 351 | % format) |
120 | 352 | revision_id = elt.get('revision_id') | 352 | revision_id = elt.get('revision_id') |
121 | @@ -387,7 +387,7 @@ | |||
122 | 387 | b'text_sha1="%s" text_size="%d" />\n' % ( | 387 | b'text_sha1="%s" text_size="%d" />\n' % ( |
123 | 388 | executable, encode_and_escape(ie.file_id), | 388 | executable, encode_and_escape(ie.file_id), |
124 | 389 | encode_and_escape(ie.name), parent_str, parent_id, | 389 | encode_and_escape(ie.name), parent_str, parent_id, |
126 | 390 | encode_and_escape(ie.revision), ie.text_sha1, | 390 | encode_and_escape(ie.revision), ie.text_sha1.encode(), |
127 | 391 | ie.text_size)) | 391 | ie.text_size)) |
128 | 392 | else: | 392 | else: |
129 | 393 | append(b'<file%s file_id="%s name="%s%s%s />\n' % ( | 393 | append(b'<file%s file_id="%s name="%s%s%s />\n' % ( |
130 | 394 | 394 | ||
131 | === modified file 'breezy/tests/test_xml.py' | |||
132 | --- breezy/tests/test_xml.py 2018-03-25 11:39:36 +0000 | |||
133 | +++ breezy/tests/test_xml.py 2018-05-22 02:02:43 +0000 | |||
134 | @@ -27,6 +27,7 @@ | |||
135 | 27 | ) | 27 | ) |
136 | 28 | from ..sixish import ( | 28 | from ..sixish import ( |
137 | 29 | BytesIO, | 29 | BytesIO, |
138 | 30 | text_type, | ||
139 | 30 | ) | 31 | ) |
140 | 31 | from ..bzr.inventory import Inventory | 32 | from ..bzr.inventory import Inventory |
141 | 32 | from . import TestCase | 33 | from . import TestCase |
142 | @@ -208,7 +209,7 @@ | |||
143 | 208 | eq(len(rev.parent_ids), 1) | 209 | eq(len(rev.parent_ids), 1) |
144 | 209 | eq(rev.timezone, 36000) | 210 | eq(rev.timezone, 36000) |
145 | 210 | eq(rev.parent_ids[0], | 211 | eq(rev.parent_ids[0], |
147 | 211 | "mbp@sourcefrog.net-20050905063503-43948f59fa127d92") | 212 | b"mbp@sourcefrog.net-20050905063503-43948f59fa127d92") |
148 | 212 | 213 | ||
149 | 213 | def test_unpack_revision_5_utc(self): | 214 | def test_unpack_revision_5_utc(self): |
150 | 214 | inp = BytesIO(_revision_v5_utc) | 215 | inp = BytesIO(_revision_v5_utc) |
151 | @@ -219,7 +220,7 @@ | |||
152 | 219 | eq(len(rev.parent_ids), 1) | 220 | eq(len(rev.parent_ids), 1) |
153 | 220 | eq(rev.timezone, 0) | 221 | eq(rev.timezone, 0) |
154 | 221 | eq(rev.parent_ids[0], | 222 | eq(rev.parent_ids[0], |
156 | 222 | "mbp@sourcefrog.net-20050905063503-43948f59fa127d92") | 223 | b"mbp@sourcefrog.net-20050905063503-43948f59fa127d92") |
157 | 223 | 224 | ||
158 | 224 | def test_unpack_inventory_5(self): | 225 | def test_unpack_inventory_5(self): |
159 | 225 | """Unpack canned new-style inventory""" | 226 | """Unpack canned new-style inventory""" |
160 | @@ -227,9 +228,9 @@ | |||
161 | 227 | inv = breezy.bzr.xml5.serializer_v5.read_inventory(inp) | 228 | inv = breezy.bzr.xml5.serializer_v5.read_inventory(inp) |
162 | 228 | eq = self.assertEqual | 229 | eq = self.assertEqual |
163 | 229 | eq(len(inv), 4) | 230 | eq(len(inv), 4) |
165 | 230 | ie = inv.get_entry('bar-20050824000535-6bc48cfad47ed134') | 231 | ie = inv.get_entry(b'bar-20050824000535-6bc48cfad47ed134') |
166 | 231 | eq(ie.kind, 'file') | 232 | eq(ie.kind, 'file') |
168 | 232 | eq(ie.revision, 'mbp@foo-00') | 233 | eq(ie.revision, b'mbp@foo-00') |
169 | 233 | eq(ie.name, 'bar') | 234 | eq(ie.name, 'bar') |
170 | 234 | eq(inv.get_entry(ie.parent_id).kind, 'directory') | 235 | eq(inv.get_entry(ie.parent_id).kind, 'directory') |
171 | 235 | 236 | ||
172 | @@ -239,17 +240,17 @@ | |||
173 | 239 | inv = breezy.bzr.xml5.serializer_v5.read_inventory(inp) | 240 | inv = breezy.bzr.xml5.serializer_v5.read_inventory(inp) |
174 | 240 | eq = self.assertEqual | 241 | eq = self.assertEqual |
175 | 241 | eq(len(inv), 4) | 242 | eq(len(inv), 4) |
178 | 242 | eq(inv.revision_id, 'mbp@sourcefrog.net-20050905063503-43948f59fa127d92') | 243 | eq(inv.revision_id, b'mbp@sourcefrog.net-20050905063503-43948f59fa127d92') |
179 | 243 | ie = inv.get_entry('bar-20050824000535-6bc48cfad47ed134') | 244 | ie = inv.get_entry(b'bar-20050824000535-6bc48cfad47ed134') |
180 | 244 | eq(ie.kind, 'file') | 245 | eq(ie.kind, 'file') |
182 | 245 | eq(ie.revision, 'mbp@foo-00') | 246 | eq(ie.revision, b'mbp@foo-00') |
183 | 246 | eq(ie.name, 'bar') | 247 | eq(ie.name, 'bar') |
184 | 247 | eq(inv.get_entry(ie.parent_id).kind, 'directory') | 248 | eq(inv.get_entry(ie.parent_id).kind, 'directory') |
185 | 248 | 249 | ||
186 | 249 | def test_unpack_inventory_5a(self): | 250 | def test_unpack_inventory_5a(self): |
187 | 250 | inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_string( | 251 | inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_string( |
190 | 251 | _inventory_v5a, revision_id='test-rev-id') | 252 | _inventory_v5a, revision_id=b'test-rev-id') |
191 | 252 | self.assertEqual('test-rev-id', inv.root.revision) | 253 | self.assertEqual(b'test-rev-id', inv.root.revision) |
192 | 253 | 254 | ||
193 | 254 | def test_unpack_inventory_5a_cache_and_copy(self): | 255 | def test_unpack_inventory_5a_cache_and_copy(self): |
194 | 255 | # Passing an entry_cache should get populated with the objects | 256 | # Passing an entry_cache should get populated with the objects |
195 | @@ -257,7 +258,7 @@ | |||
196 | 257 | # False | 258 | # False |
197 | 258 | entry_cache = fifo_cache.FIFOCache() | 259 | entry_cache = fifo_cache.FIFOCache() |
198 | 259 | inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_string( | 260 | inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_string( |
200 | 260 | _inventory_v5a, revision_id='test-rev-id', | 261 | _inventory_v5a, revision_id=b'test-rev-id', |
201 | 261 | entry_cache=entry_cache, return_from_cache=False) | 262 | entry_cache=entry_cache, return_from_cache=False) |
202 | 262 | for entry in inv.iter_just_entries(): | 263 | for entry in inv.iter_just_entries(): |
203 | 263 | key = (entry.file_id, entry.revision) | 264 | key = (entry.file_id, entry.revision) |
204 | @@ -273,7 +274,7 @@ | |||
205 | 273 | # True | 274 | # True |
206 | 274 | entry_cache = fifo_cache.FIFOCache() | 275 | entry_cache = fifo_cache.FIFOCache() |
207 | 275 | inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_string( | 276 | inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_string( |
209 | 276 | _inventory_v5a, revision_id='test-rev-id', | 277 | _inventory_v5a, revision_id=b'test-rev-id', |
210 | 277 | entry_cache=entry_cache, return_from_cache=True) | 278 | entry_cache=entry_cache, return_from_cache=True) |
211 | 278 | for entry in inv.iter_just_entries(): | 279 | for entry in inv.iter_just_entries(): |
212 | 279 | key = (entry.file_id, entry.revision) | 280 | key = (entry.file_id, entry.revision) |
213 | @@ -285,8 +286,8 @@ | |||
214 | 285 | 286 | ||
215 | 286 | def test_unpack_inventory_5b(self): | 287 | def test_unpack_inventory_5b(self): |
216 | 287 | inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_string( | 288 | inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_string( |
219 | 288 | _inventory_v5b, revision_id='test-rev-id') | 289 | _inventory_v5b, revision_id=b'test-rev-id') |
220 | 289 | self.assertEqual('a-rev-id', inv.root.revision) | 290 | self.assertEqual(b'a-rev-id', inv.root.revision) |
221 | 290 | 291 | ||
222 | 291 | def test_repack_inventory_5(self): | 292 | def test_repack_inventory_5(self): |
223 | 292 | inp = BytesIO(_committed_inv_v5) | 293 | inp = BytesIO(_committed_inv_v5) |
224 | @@ -336,7 +337,7 @@ | |||
225 | 336 | outp = BytesIO() | 337 | outp = BytesIO() |
226 | 337 | breezy.bzr.xml5.serializer_v5.write_revision(rev, outp) | 338 | breezy.bzr.xml5.serializer_v5.write_revision(rev, outp) |
227 | 338 | outfile_contents = outp.getvalue() | 339 | outfile_contents = outp.getvalue() |
229 | 339 | self.assertEqual(outfile_contents[-1], '\n') | 340 | self.assertEqual(outfile_contents[-1:], b'\n') |
230 | 340 | self.assertEqualDiff(outfile_contents, breezy.bzr.xml5.serializer_v5.write_revision_to_string(rev)) | 341 | self.assertEqualDiff(outfile_contents, breezy.bzr.xml5.serializer_v5.write_revision_to_string(rev)) |
231 | 341 | self.assertEqualDiff(outfile_contents, _expected_rev_v5) | 342 | self.assertEqualDiff(outfile_contents, _expected_rev_v5) |
232 | 342 | 343 | ||
233 | @@ -459,13 +460,13 @@ | |||
234 | 459 | """Parsed revision_ids should all be utf-8 strings, not unicode.""" | 460 | """Parsed revision_ids should all be utf-8 strings, not unicode.""" |
235 | 460 | s_v5 = breezy.bzr.xml5.serializer_v5 | 461 | s_v5 = breezy.bzr.xml5.serializer_v5 |
236 | 461 | rev = s_v5.read_revision_from_string(_revision_utf8_v5) | 462 | rev = s_v5.read_revision_from_string(_revision_utf8_v5) |
240 | 462 | self.assertEqual('erik@b\xc3\xa5gfors-02', rev.revision_id) | 463 | self.assertEqual(b'erik@b\xc3\xa5gfors-02', rev.revision_id) |
241 | 463 | self.assertIsInstance(rev.revision_id, str) | 464 | self.assertIsInstance(rev.revision_id, bytes) |
242 | 464 | self.assertEqual(['erik@b\xc3\xa5gfors-01'], rev.parent_ids) | 465 | self.assertEqual([b'erik@b\xc3\xa5gfors-01'], rev.parent_ids) |
243 | 465 | for parent_id in rev.parent_ids: | 466 | for parent_id in rev.parent_ids: |
245 | 466 | self.assertIsInstance(parent_id, str) | 467 | self.assertIsInstance(parent_id, bytes) |
246 | 467 | self.assertEqual(u'Include \xb5nicode characters\n', rev.message) | 468 | self.assertEqual(u'Include \xb5nicode characters\n', rev.message) |
248 | 468 | self.assertIsInstance(rev.message, unicode) | 469 | self.assertIsInstance(rev.message, text_type) |
249 | 469 | 470 | ||
250 | 470 | # ie.revision should either be None or a utf-8 revision id | 471 | # ie.revision should either be None or a utf-8 revision id |
251 | 471 | inv = s_v5.read_inventory_from_string(_inventory_utf8_v5) | 472 | inv = s_v5.read_inventory_from_string(_inventory_utf8_v5) |
252 | @@ -481,21 +482,21 @@ | |||
253 | 481 | (u's\xb5bdir/b\xe5r', fid_bar2, fid_sub, rev_id_2), | 482 | (u's\xb5bdir/b\xe5r', fid_bar2, fid_sub, rev_id_2), |
254 | 482 | ] | 483 | ] |
255 | 483 | self.assertEqual(rev_id_2, inv.revision_id) | 484 | self.assertEqual(rev_id_2, inv.revision_id) |
257 | 484 | self.assertIsInstance(inv.revision_id, str) | 485 | self.assertIsInstance(inv.revision_id, bytes) |
258 | 485 | 486 | ||
259 | 486 | actual = list(inv.iter_entries_by_dir()) | 487 | actual = list(inv.iter_entries_by_dir()) |
260 | 487 | for ((exp_path, exp_file_id, exp_parent_id, exp_rev_id), | 488 | for ((exp_path, exp_file_id, exp_parent_id, exp_rev_id), |
261 | 488 | (act_path, act_ie)) in zip(expected, actual): | 489 | (act_path, act_ie)) in zip(expected, actual): |
262 | 489 | self.assertEqual(exp_path, act_path) | 490 | self.assertEqual(exp_path, act_path) |
264 | 490 | self.assertIsInstance(act_path, unicode) | 491 | self.assertIsInstance(act_path, text_type) |
265 | 491 | self.assertEqual(exp_file_id, act_ie.file_id) | 492 | self.assertEqual(exp_file_id, act_ie.file_id) |
267 | 492 | self.assertIsInstance(act_ie.file_id, str) | 493 | self.assertIsInstance(act_ie.file_id, bytes) |
268 | 493 | self.assertEqual(exp_parent_id, act_ie.parent_id) | 494 | self.assertEqual(exp_parent_id, act_ie.parent_id) |
269 | 494 | if exp_parent_id is not None: | 495 | if exp_parent_id is not None: |
271 | 495 | self.assertIsInstance(act_ie.parent_id, str) | 496 | self.assertIsInstance(act_ie.parent_id, bytes) |
272 | 496 | self.assertEqual(exp_rev_id, act_ie.revision) | 497 | self.assertEqual(exp_rev_id, act_ie.revision) |
273 | 497 | if exp_rev_id is not None: | 498 | if exp_rev_id is not None: |
275 | 498 | self.assertIsInstance(act_ie.revision, str) | 499 | self.assertIsInstance(act_ie.revision, bytes) |
276 | 499 | 500 | ||
277 | 500 | self.assertEqual(len(expected), len(actual)) | 501 | self.assertEqual(len(expected), len(actual)) |
278 | 501 | 502 | ||
279 | @@ -514,24 +515,24 @@ | |||
280 | 514 | # are being used in xml attributes, and by returning it now, we have to | 515 | # are being used in xml attributes, and by returning it now, we have to |
281 | 515 | # do fewer string operations later. | 516 | # do fewer string operations later. |
282 | 516 | val = breezy.bzr.xml_serializer.encode_and_escape('foo bar') | 517 | val = breezy.bzr.xml_serializer.encode_and_escape('foo bar') |
284 | 517 | self.assertEqual('foo bar"', val) | 518 | self.assertEqual(b'foo bar"', val) |
285 | 518 | # The second time should be cached | 519 | # The second time should be cached |
286 | 519 | val2 = breezy.bzr.xml_serializer.encode_and_escape('foo bar') | 520 | val2 = breezy.bzr.xml_serializer.encode_and_escape('foo bar') |
287 | 520 | self.assertIs(val2, val) | 521 | self.assertIs(val2, val) |
288 | 521 | 522 | ||
289 | 522 | def test_ascii_with_xml(self): | 523 | def test_ascii_with_xml(self): |
291 | 523 | self.assertEqual('&'"<>"', | 524 | self.assertEqual(b'&'"<>"', |
292 | 524 | breezy.bzr.xml_serializer.encode_and_escape('&\'"<>')) | 525 | breezy.bzr.xml_serializer.encode_and_escape('&\'"<>')) |
293 | 525 | 526 | ||
294 | 526 | def test_utf8_with_xml(self): | 527 | def test_utf8_with_xml(self): |
295 | 527 | # u'\xb5\xe5&\u062c' | 528 | # u'\xb5\xe5&\u062c' |
298 | 528 | utf8_str = '\xc2\xb5\xc3\xa5&\xd8\xac' | 529 | utf8_str = b'\xc2\xb5\xc3\xa5&\xd8\xac' |
299 | 529 | self.assertEqual('µå&ج"', | 530 | self.assertEqual(b'µå&ج"', |
300 | 530 | breezy.bzr.xml_serializer.encode_and_escape(utf8_str)) | 531 | breezy.bzr.xml_serializer.encode_and_escape(utf8_str)) |
301 | 531 | 532 | ||
302 | 532 | def test_unicode(self): | 533 | def test_unicode(self): |
303 | 533 | uni_str = u'\xb5\xe5&\u062c' | 534 | uni_str = u'\xb5\xe5&\u062c' |
305 | 534 | self.assertEqual('µå&ج"', | 535 | self.assertEqual(b'µå&ج"', |
306 | 535 | breezy.bzr.xml_serializer.encode_and_escape(uni_str)) | 536 | breezy.bzr.xml_serializer.encode_and_escape(uni_str)) |
307 | 536 | 537 | ||
308 | 537 | 538 | ||
309 | 538 | 539 | ||
310 | === modified file 'python3.passing' | |||
311 | --- python3.passing 2018-05-19 14:54:22 +0000 | |||
312 | +++ python3.passing 2018-05-22 02:02:43 +0000 | |||
313 | @@ -56,11 +56,35 @@ | |||
314 | 56 | breezy.plugins.upload.tests.test_upload.TestBranchUploadLocations.test_set_push_location(BranchReferenceFormat) | 56 | breezy.plugins.upload.tests.test_upload.TestBranchUploadLocations.test_set_push_location(BranchReferenceFormat) |
315 | 57 | breezy.plugins.upload.tests.test_upload.TestBranchUploadLocations.test_set_push_location(BzrBranchFormat7) | 57 | breezy.plugins.upload.tests.test_upload.TestBranchUploadLocations.test_set_push_location(BzrBranchFormat7) |
316 | 58 | breezy.plugins.weave_fmt.test_bzrdir.TestBranchFormat4.test_no_metadir_support | 58 | breezy.plugins.weave_fmt.test_bzrdir.TestBranchFormat4.test_no_metadir_support |
317 | 59 | breezy.plugins.weave_fmt.test_bzrdir.TestBranchFormat4.test_supports_bzrdir_6 | ||
318 | 60 | breezy.plugins.weave_fmt.test_bzrdir.TestFormat5.test_can_convert | ||
319 | 61 | breezy.plugins.weave_fmt.test_bzrdir.TestFormat5.test_needs_conversion | ||
320 | 62 | breezy.plugins.weave_fmt.test_bzrdir.TestFormat5.test_same_lockfiles_between_tree_repo_branch | ||
321 | 63 | breezy.plugins.weave_fmt.test_bzrdir.TestFormat6.test_can_convert | ||
322 | 64 | breezy.plugins.weave_fmt.test_bzrdir.TestFormat6.test_needs_conversion | ||
323 | 65 | breezy.plugins.weave_fmt.test_bzrdir.TestFormat6.test_same_lockfiles_between_tree_repo_branch | ||
324 | 66 | breezy.plugins.weave_fmt.test_bzrdir.V4WeaveBundleTester.test_crlf_bundle | ||
325 | 67 | breezy.plugins.weave_fmt.test_bzrdir.V4WeaveBundleTester.test_malformed | ||
326 | 68 | breezy.plugins.weave_fmt.test_bzrdir.V4WeaveBundleTester.test_non_bundle | ||
327 | 69 | breezy.plugins.weave_fmt.test_repository.TestFormat6.test_attribute__fetch_order | ||
328 | 70 | breezy.plugins.weave_fmt.test_repository.TestFormat6.test_attribute__fetch_reconcile | ||
329 | 71 | breezy.plugins.weave_fmt.test_repository.TestFormat6.test_attribute__fetch_uses_deltas | ||
330 | 72 | breezy.plugins.weave_fmt.test_repository.TestFormat6.test_no_ancestry_weave | ||
331 | 73 | breezy.plugins.weave_fmt.test_repository.TestFormat6.test_supports_external_lookups | ||
332 | 74 | breezy.plugins.weave_fmt.test_repository.TestFormat7.test_attribute__fetch_order | ||
333 | 75 | breezy.plugins.weave_fmt.test_repository.TestFormat7.test_attribute__fetch_reconcile | ||
334 | 76 | breezy.plugins.weave_fmt.test_repository.TestFormat7.test_attribute__fetch_uses_deltas | ||
335 | 77 | breezy.plugins.weave_fmt.test_repository.TestFormat7.test_creates_lockdir | ||
336 | 78 | breezy.plugins.weave_fmt.test_repository.TestFormat7.test_supports_external_lookups | ||
337 | 79 | breezy.plugins.weave_fmt.test_repository.TestFormat7.test_uses_lockdir | ||
338 | 59 | breezy.plugins.weave_fmt.test_repository.TestInterWeaveRepo.test_is_compatible_and_registered | 80 | breezy.plugins.weave_fmt.test_repository.TestInterWeaveRepo.test_is_compatible_and_registered |
339 | 81 | breezy.plugins.weave_fmt.test_repository.TestSerializer.test_canned_inventory | ||
340 | 60 | breezy.plugins.weave_fmt.test_repository.TestSerializer.test_registry | 82 | breezy.plugins.weave_fmt.test_repository.TestSerializer.test_registry |
341 | 83 | breezy.plugins.weave_fmt.test_repository.TestSerializer.test_unpack_revision | ||
342 | 61 | breezy.plugins.weave_fmt.test_store.TestCompressedTextStore.test_multiple_add | 84 | breezy.plugins.weave_fmt.test_store.TestCompressedTextStore.test_multiple_add |
343 | 62 | breezy.plugins.weave_fmt.test_store.TestCompressedTextStore.test_total_size | 85 | breezy.plugins.weave_fmt.test_store.TestCompressedTextStore.test_total_size |
344 | 63 | breezy.plugins.weave_fmt.test_store.TestInstrumentedTransportStore.test__add_records | 86 | breezy.plugins.weave_fmt.test_store.TestInstrumentedTransportStore.test__add_records |
345 | 87 | breezy.plugins.weave_fmt.test_store.TestMemoryStore.test_add_and_retrieve | ||
346 | 64 | breezy.plugins.weave_fmt.test_store.TestMemoryStore.test_adding_fails_when_present | 88 | breezy.plugins.weave_fmt.test_store.TestMemoryStore.test_adding_fails_when_present |
347 | 65 | breezy.plugins.weave_fmt.test_store.TestMemoryStore.test_missing_is_absent | 89 | breezy.plugins.weave_fmt.test_store.TestMemoryStore.test_missing_is_absent |
348 | 66 | breezy.plugins.weave_fmt.test_store.TestMemoryStore.test_total_size | 90 | breezy.plugins.weave_fmt.test_store.TestMemoryStore.test_total_size |
349 | @@ -79,6 +103,8 @@ | |||
350 | 79 | breezy.plugins.weave_fmt.test_store.TestTransportStore.test__relpath_simple | 103 | breezy.plugins.weave_fmt.test_store.TestTransportStore.test__relpath_simple |
351 | 80 | breezy.plugins.weave_fmt.test_store.TestTransportStore.test__relpath_simple_suffixed | 104 | breezy.plugins.weave_fmt.test_store.TestTransportStore.test__relpath_simple_suffixed |
352 | 81 | breezy.plugins.weave_fmt.test_store.TestTransportStore.test__relpath_unregister_suffixes | 105 | breezy.plugins.weave_fmt.test_store.TestTransportStore.test__relpath_unregister_suffixes |
353 | 106 | breezy.plugins.weave_fmt.test_store.TestVersionFileStore.test_get_weave_readonly_cant_write | ||
354 | 107 | breezy.plugins.weave_fmt.test_store.TestVersionFileStore.test_get_weave_registers_dirty_in_write | ||
355 | 82 | breezy.pyutils.get_named_object | 108 | breezy.pyutils.get_named_object |
356 | 83 | breezy.symbol_versioning.deprecated_in | 109 | breezy.symbol_versioning.deprecated_in |
357 | 84 | breezy.tests.commands.test_checkout.TestCheckout.test_checkout | 110 | breezy.tests.commands.test_checkout.TestCheckout.test_checkout |
358 | @@ -10513,6 +10539,7 @@ | |||
359 | 10513 | breezy.tests.test_ui.TestUIFactoryTests.test_test_ui_factory_progress | 10539 | breezy.tests.test_ui.TestUIFactoryTests.test_test_ui_factory_progress |
360 | 10514 | breezy.tests.test_ui.UITests.test_progress_construction | 10540 | breezy.tests.test_ui.UITests.test_progress_construction |
361 | 10515 | breezy.tests.test_ui.UITests.test_text_ui_non_terminal | 10541 | breezy.tests.test_ui.UITests.test_text_ui_non_terminal |
362 | 10542 | breezy.tests.test_upgrade.TestUpgrade.test_convert_knit_dirstate_content | ||
363 | 10516 | breezy.tests.test_upstream_import.TestImport.test_common_directory | 10543 | breezy.tests.test_upstream_import.TestImport.test_common_directory |
364 | 10517 | breezy.tests.test_upstream_import.TestImport.test_get_archive_type | 10544 | breezy.tests.test_upstream_import.TestImport.test_get_archive_type |
365 | 10518 | breezy.tests.test_upstream_import.TestImport.test_top_path | 10545 | breezy.tests.test_upstream_import.TestImport.test_top_path |
366 | @@ -10670,7 +10697,34 @@ | |||
367 | 10670 | breezy.tests.test_wsgi.TestWSGI.test_relpath_setter | 10697 | breezy.tests.test_wsgi.TestWSGI.test_relpath_setter |
368 | 10671 | breezy.tests.test_wsgi.TestWSGI.test_relpath_setter_bad_path_prefix | 10698 | breezy.tests.test_wsgi.TestWSGI.test_relpath_setter_bad_path_prefix |
369 | 10672 | breezy.tests.test_wsgi.TestWSGI.test_relpath_setter_bad_path_suffix | 10699 | breezy.tests.test_wsgi.TestWSGI.test_relpath_setter_bad_path_suffix |
370 | 10700 | breezy.tests.test_xml.TestEncodeAndEscape.test_ascii_with_xml | ||
371 | 10701 | breezy.tests.test_xml.TestEncodeAndEscape.test_simple_ascii | ||
372 | 10702 | breezy.tests.test_xml.TestEncodeAndEscape.test_unicode | ||
373 | 10703 | breezy.tests.test_xml.TestEncodeAndEscape.test_utf8_with_xml | ||
374 | 10673 | breezy.tests.test_xml.TestMisc.test_unescape_xml | 10704 | breezy.tests.test_xml.TestMisc.test_unescape_xml |
375 | 10705 | breezy.tests.test_xml.TestSerializer.test_empty_property_value | ||
376 | 10706 | breezy.tests.test_xml.TestSerializer.test_inventory_text_v8 | ||
377 | 10707 | breezy.tests.test_xml.TestSerializer.test_pack_revision_5 | ||
378 | 10708 | breezy.tests.test_xml.TestSerializer.test_repack_inventory_5 | ||
379 | 10709 | breezy.tests.test_xml.TestSerializer.test_repack_revision_5 | ||
380 | 10710 | breezy.tests.test_xml.TestSerializer.test_repack_revision_5_utc | ||
381 | 10711 | breezy.tests.test_xml.TestSerializer.test_revision_ids_are_utf8 | ||
382 | 10712 | breezy.tests.test_xml.TestSerializer.test_revision_text_v6 | ||
383 | 10713 | breezy.tests.test_xml.TestSerializer.test_revision_text_v7 | ||
384 | 10714 | breezy.tests.test_xml.TestSerializer.test_revision_text_v8 | ||
385 | 10715 | breezy.tests.test_xml.TestSerializer.test_roundtrip_inventory_v6 | ||
386 | 10716 | breezy.tests.test_xml.TestSerializer.test_roundtrip_inventory_v7 | ||
387 | 10717 | breezy.tests.test_xml.TestSerializer.test_roundtrip_inventory_v8 | ||
388 | 10718 | breezy.tests.test_xml.TestSerializer.tests_serialize_inventory_v5_with_root | ||
389 | 10719 | breezy.tests.test_xml.TestSerializer.test_tree_reference | ||
390 | 10720 | breezy.tests.test_xml.TestSerializer.test_unpack_basis_inventory_5 | ||
391 | 10721 | breezy.tests.test_xml.TestSerializer.test_unpack_inventory_5 | ||
392 | 10722 | breezy.tests.test_xml.TestSerializer.test_unpack_inventory_5a | ||
393 | 10723 | breezy.tests.test_xml.TestSerializer.test_unpack_inventory_5a_cache_and_copy | ||
394 | 10724 | breezy.tests.test_xml.TestSerializer.test_unpack_inventory_5a_cache_no_copy | ||
395 | 10725 | breezy.tests.test_xml.TestSerializer.test_unpack_inventory_5b | ||
396 | 10726 | breezy.tests.test_xml.TestSerializer.test_unpack_revision_5 | ||
397 | 10727 | breezy.tests.test_xml.TestSerializer.test_unpack_revision_5_utc | ||
398 | 10674 | breezy.tests.test_xml.TestSerializer.test_wrong_format_v7 | 10728 | breezy.tests.test_xml.TestSerializer.test_wrong_format_v7 |
399 | 10675 | breezy.timestamp.format_highres_date | 10729 | breezy.timestamp.format_highres_date |
400 | 10676 | breezy.transport.http.unhtml_roughly | 10730 | breezy.transport.http.unhtml_roughly |
I'm not sure on some of the bare encode() calls here, but it's probably on the caller if they pass non-ascii values?