Show More
@@ -1563,17 +1563,9 b" def export(repo, revs, fntemplate='hg-%h" | |||||
1563 | if fo is not None: |
|
1563 | if fo is not None: | |
1564 | fo.close() |
|
1564 | fo.close() | |
1565 |
|
1565 | |||
1566 | class _regrettablereprbytes(bytes): |
|
|||
1567 | """Bytes subclass that makes the repr the same on Python 3 as Python 2. |
|
|||
1568 |
|
||||
1569 | This is a huge hack. |
|
|||
1570 | """ |
|
|||
1571 | def __repr__(self): |
|
|||
1572 | return repr(pycompat.sysstr(self)) |
|
|||
1573 |
|
||||
1574 | def _maybebytestr(v): |
|
1566 | def _maybebytestr(v): | |
1575 |
if |
|
1567 | if isinstance(v, bytes): | |
1576 |
return |
|
1568 | return pycompat.bytestr(v) | |
1577 | return v |
|
1569 | return v | |
1578 |
|
1570 | |||
1579 | def showmarker(fm, marker, index=None): |
|
1571 | def showmarker(fm, marker, index=None): |
@@ -88,7 +88,7 b' if ispy3:' | |||||
88 | """A bytes which mostly acts as a Python 2 str |
|
88 | """A bytes which mostly acts as a Python 2 str | |
89 |
|
89 | |||
90 | >>> bytestr(), bytestr(bytearray(b'foo')), bytestr(u'ascii'), bytestr(1) |
|
90 | >>> bytestr(), bytestr(bytearray(b'foo')), bytestr(u'ascii'), bytestr(1) | |
91 |
( |
|
91 | ('', 'foo', 'ascii', '1') | |
92 | >>> s = bytestr(b'foo') |
|
92 | >>> s = bytestr(b'foo') | |
93 | >>> assert s is bytestr(s) |
|
93 | >>> assert s is bytestr(s) | |
94 |
|
94 | |||
@@ -98,7 +98,7 b' if ispy3:' | |||||
98 | ... def __bytes__(self): |
|
98 | ... def __bytes__(self): | |
99 | ... return b'bytes' |
|
99 | ... return b'bytes' | |
100 | >>> bytestr(bytesable()) |
|
100 | >>> bytestr(bytesable()) | |
101 |
|
|
101 | 'bytes' | |
102 |
|
102 | |||
103 | There's no implicit conversion from non-ascii str as its encoding is |
|
103 | There's no implicit conversion from non-ascii str as its encoding is | |
104 | unknown: |
|
104 | unknown: | |
@@ -154,6 +154,9 b' if ispy3:' | |||||
154 | def __iter__(self): |
|
154 | def __iter__(self): | |
155 | return iterbytestr(bytes.__iter__(self)) |
|
155 | return iterbytestr(bytes.__iter__(self)) | |
156 |
|
156 | |||
|
157 | def __repr__(self): | |||
|
158 | return bytes.__repr__(self)[1:] # drop b'' | |||
|
159 | ||||
157 | def iterbytestr(s): |
|
160 | def iterbytestr(s): | |
158 | """Iterate bytes as if it were a str object of Python 2""" |
|
161 | """Iterate bytes as if it were a str object of Python 2""" | |
159 | return map(bytechr, s) |
|
162 | return map(bytechr, s) |
General Comments 0
You need to be logged in to leave comments.
Login now