Skip to content

Commit 3ca7c5e

Browse files
committed
Fix tests to be single-source compatible
1 parent db7fa99 commit 3ca7c5e

File tree

5 files changed

+237
-229
lines changed

5 files changed

+237
-229
lines changed

regexlint/util.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def eval_char(c):
121121
return c
122122

123123
try:
124-
return ord(eval("'%s'" % c))
124+
return ord(eval("b'%s'" % c))
125125
except TypeError:
126126
# Probably a unicode escape.
127127
return ord(eval("u'%s'" % c))
@@ -132,11 +132,16 @@ class Break(Exception):
132132

133133

134134
ESC_SPECIAL = {
135-
'\r': '\\r',
136-
'\n': '\\n',
137-
'\t': '\\t',
138-
'\\': '\\\\',
139-
'\'': '\\\'',
135+
u'\r': '\\r',
136+
u'\n': '\\n',
137+
u'\t': '\\t',
138+
u'\\': '\\\\',
139+
u'\'': '\\\'',
140+
b'\r': '\\r',
141+
b'\n': '\\n',
142+
b'\t': '\\t',
143+
b'\\': '\\\\',
144+
b'\'': '\\\'',
140145
}
141146

142147

@@ -152,6 +157,8 @@ def esc(c, also_escape=(), esc_special=ESC_SPECIAL):
152157
elif c in also_escape:
153158
return '\\' + c
154159
else:
160+
if isinstance(c, bytes):
161+
return c.decode('latin-1')
155162
return c
156163

157164

@@ -164,11 +171,11 @@ def consistent_repr(s, escape=(), include_quotes=True):
164171
"""
165172
rep = []
166173
if include_quotes:
167-
if isinstance(s, type(u'')):
168-
rep.append('u')
174+
if isinstance(s, bytes):
175+
rep.append('b')
169176
rep.append('\'')
170-
for char in s:
171-
rep.append(esc(char, escape))
177+
for i in range(len(s)):
178+
rep.append(esc(s[i:i+1], escape))
172179
if include_quotes:
173180
rep.append('\'')
174181
return ''.join(rep)

0 commit comments

Comments
 (0)