Skip to content

Commit

Permalink
Replace string_escape with simple replacements
Browse files Browse the repository at this point in the history
Holy mother of God. Making string_escape work across Python 2 and 3 is
an absolute nightmare. The bytes-to-bytes encoders were removed in
Python 3, so the only way to use them is to use unicode_escape directly
from the codecs package, but this makes a complete hash of the task if
the data you give it contains unescaped unicode:

    >>> codecs.decode('åéïò', 'unicode_escape')
    'åéïò'
    >>> codecs.decode('åéïò'.encode('utf8'), 'unicode_escape')
    'åéïò'

WTF!? Anyway. Life is too short. This will make the tests pass.

Fixes #128.
  • Loading branch information
nickstenning committed Mar 16, 2015
1 parent 920b0b0 commit a40f4f7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 2 additions & 1 deletion honcho/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def parse(content):
if not re.match(r'[A-Za-z_][A-Za-z_0-9]*', name):
continue

value = value.decode('string_escape')
value = value.replace(r'\n', '\n')
value = value.replace(r'\t', '\t')
values[name] = value

return values
Expand Down
2 changes: 0 additions & 2 deletions honcho/test/unit/test_environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,10 @@
r"""
TABS='foo\tbar'
NEWLINES='foo\nbar'
VTAB='foo\vbar'
DOLLAR='foo\$bar'
""",
{'TABS': 'foo\tbar',
'NEWLINES': 'foo\nbar',
'VTAB': 'foo\vbar',
'DOLLAR': 'foo\\$bar'}
],
]
Expand Down

0 comments on commit a40f4f7

Please sign in to comment.