comparison mercurial/obsolete.py @ 43106:d783f945a701

py3: finish porting iteritems() to pycompat and remove source transformer This commit finishes porting .iteritems() to pycompat.iteritems() for the mercurial package. The translation of .iteritems() to .items() was the last conversion performed by the source transformer. With the porting to pycompat complete, we no longer have a need for the source transformer. So the source transformer has been removed. Good riddance! The code base is now compatible with Python 2 and Python 3. For the record, as the person who introduced the source transformer, it brings me joy to delete it. It accomplished its goal to facilitate a port to Python 3 without overly burdening people on some painful low-level differences between Python 2 and 3. It is unfortunate we still have to wallpaper over many differences with the pycompat shim. But it is what it is. Differential Revision: https://phab.mercurial-scm.org/D7015
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 07 Oct 2019 00:04:04 -0400
parents c59eb1560c44
children 8ff1ecfadcd1
comparison
equal deleted inserted replaced
43105:649d3ac37a12 43106:d783f945a701
241 break 241 break
242 except TypeError: 242 except TypeError:
243 # if content cannot be translated to nodeid drop the data. 243 # if content cannot be translated to nodeid drop the data.
244 parents = None 244 parents = None
245 245
246 metadata = tuple(sorted(metadata.iteritems())) 246 metadata = tuple(sorted(pycompat.iteritems(metadata)))
247 247
248 yield (pre, sucs, flags, metadata, date, parents) 248 yield (pre, sucs, flags, metadata, date, parents)
249 249
250 250
251 def _fm0encodeonemarker(marker): 251 def _fm0encodeonemarker(marker):
271 271
272 def _fm0encodemeta(meta): 272 def _fm0encodemeta(meta):
273 """Return encoded metadata string to string mapping. 273 """Return encoded metadata string to string mapping.
274 274
275 Assume no ':' in key and no '\0' in both key and value.""" 275 Assume no ':' in key and no '\0' in both key and value."""
276 for key, value in meta.iteritems(): 276 for key, value in pycompat.iteritems(meta):
277 if b':' in key or b'\0' in key: 277 if b':' in key or b'\0' in key:
278 raise ValueError(b"':' and '\0' are forbidden in metadata key'") 278 raise ValueError(b"':' and '\0' are forbidden in metadata key'")
279 if b'\0' in value: 279 if b'\0' in value:
280 raise ValueError(b"':' is forbidden in metadata value'") 280 raise ValueError(b"':' is forbidden in metadata value'")
281 return b'\0'.join([b'%s:%s' % (k, meta[k]) for k in sorted(meta)]) 281 return b'\0'.join([b'%s:%s' % (k, meta[k]) for k in sorted(meta)])
642 if prec in succs: 642 if prec in succs:
643 raise ValueError( 643 raise ValueError(
644 r'in-marker cycle with %s' % pycompat.sysstr(node.hex(prec)) 644 r'in-marker cycle with %s' % pycompat.sysstr(node.hex(prec))
645 ) 645 )
646 646
647 metadata = tuple(sorted(metadata.iteritems())) 647 metadata = tuple(sorted(pycompat.iteritems(metadata)))
648 for k, v in metadata: 648 for k, v in metadata:
649 try: 649 try:
650 # might be better to reject non-ASCII keys 650 # might be better to reject non-ASCII keys
651 k.decode('utf-8') 651 k.decode('utf-8')
652 v.decode('utf-8') 652 v.decode('utf-8')