From e113cba8d0e73cd0f5c79cc12e6bd90c2854cd89 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Thu, 13 Aug 2020 15:02:49 -0400 Subject: [PATCH] Address review comments. --- src/allmydata/test/test_encodingutil.py | 4 +++- src/allmydata/util/encodingutil.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/allmydata/test/test_encodingutil.py b/src/allmydata/test/test_encodingutil.py index 4b93b834b..9d2c1cf5f 100644 --- a/src/allmydata/test/test_encodingutil.py +++ b/src/allmydata/test/test_encodingutil.py @@ -53,7 +53,9 @@ if __name__ == "__main__": for fname in TEST_FILENAMES: open(os.path.join(tmpdir, fname), 'w').close() - # Use Unicode API under Windows or MacOS X + # On Python 2, listing directories returns unicode under Windows or + # MacOS X if the input is unicode. On Python 3, it always returns + # Unicode. if PY2 and sys.platform in ('win32', 'darwin'): dirlist = os.listdir(unicode(tmpdir)) else: diff --git a/src/allmydata/util/encodingutil.py b/src/allmydata/util/encodingutil.py index 3e8ac7e2d..c29933620 100644 --- a/src/allmydata/util/encodingutil.py +++ b/src/allmydata/util/encodingutil.py @@ -214,6 +214,9 @@ def _unicode_escape(m, quote_newlines): return u'\\x%02x' % (codepoint,) def _str_escape(m, quote_newlines): # TODO rename to _bytes_escape + """ + Takes a re match on bytes, the result is escaped bytes of group(0). + """ c = m.group(0) if c == b'"' or c == b'$' or c == b'`' or c == b'\\': return b'\\' + c