Skip to content

Commit c017664

Browse files
committed
Cleanup Python 3 hack
1 parent 5eb33bd commit c017664

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

patch.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,15 @@
3535
import shutil
3636
import sys
3737

38+
39+
PY3K = sys.version_info >= (3, 0)
40+
3841
# PEP 3114
39-
if sys.version_info[0] == 2:
42+
if not PY3K:
4043
compat_next = lambda gen: gen.next()
4144
else:
4245
compat_next = lambda gen: gen.__next__()
4346

44-
# In Python 3 b'0' gives int 30 while b'0' in Python 3
45-
def compat_ord(c):
46-
if isinstance(c, int):
47-
return c
48-
return ord(c)
49-
5047

5148
#------------------------------------------------
5249
# Logging is controlled by logger named after the
@@ -960,9 +957,11 @@ def _reverse(self):
960957
h.startsrc, h.starttgt = h.starttgt, h.startsrc
961958
h.linessrc, h.linestgt = h.linestgt, h.linessrc
962959
for i,line in enumerate(h.text):
963-
if compat_ord(line[0]) == compat_ord(b'+'):
960+
# need to use line[0:1] here, because line[0]
961+
# returns int instead of bytes on Python 3
962+
if line[0:1] == b'+':
964963
h.text[i] = b'-' + line[1:]
965-
elif compat_ord(line[0]) == compat_ord(b'-'):
964+
elif line[0:1] == b'-':
966965
h.text[i] = b'+' +line[1:]
967966

968967
def revert(self, strip=0, root=None):

0 commit comments

Comments
 (0)