mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
Make escape_control_characters handle strings on Py2
This commit is contained in:
parent
bd58230178
commit
83a1cc5a9a
@ -57,8 +57,8 @@ def escape_control_characters(text, keep_spacing=True):
|
|||||||
Args:
|
Args:
|
||||||
keep_spacing: If True, tabs and newlines will not be replaced.
|
keep_spacing: If True, tabs and newlines will not be replaced.
|
||||||
"""
|
"""
|
||||||
# type: (six.text_type) -> six.text_type
|
# type: (six.string_types) -> six.text_type
|
||||||
if not isinstance(text, six.text_type):
|
if not isinstance(text, six.string_types):
|
||||||
raise ValueError("text type must be unicode but is {}".format(type(text).__name__))
|
raise ValueError("text type must be unicode but is {}".format(type(text).__name__))
|
||||||
|
|
||||||
trans = _control_char_trans_newline if keep_spacing else _control_char_trans
|
trans = _control_char_trans_newline if keep_spacing else _control_char_trans
|
||||||
|
@ -38,8 +38,9 @@ def test_escape_control_characters():
|
|||||||
u'=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~.'
|
u'=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~.'
|
||||||
)
|
)
|
||||||
|
|
||||||
with tutils.raises(ValueError):
|
if not six.PY2:
|
||||||
strutils.escape_control_characters(b"foo")
|
with tutils.raises(ValueError):
|
||||||
|
strutils.escape_control_characters(b"foo")
|
||||||
|
|
||||||
|
|
||||||
def test_bytes_to_escaped_str():
|
def test_bytes_to_escaped_str():
|
||||||
|
Loading…
Reference in New Issue
Block a user