Skip to content

Commit c3c3f7d

Browse files
committed
2nd try
1 parent bae62f8 commit c3c3f7d

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

frameworks/python/cw-2.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from __future__ import print_function
2-
import six
2+
import re, six
33

44
class AssertException(Exception):
55
pass
66

77

88
'''Fix the dreaded Unicode Error Trap'''
9-
def print(*args, **kwargs):
9+
def uni_print(*args, **kwargs):
1010
from sys import stdout
1111
sep = kwargs.get('sep', ' ')
1212
end = kwargs.get('end', '\n')
@@ -16,9 +16,10 @@ def _replace(c):
1616
if ord(c) >= 128: return u'&#{};'.format(ord(c))
1717
return c
1818
def _escape(s):
19-
if isinstance(s, six.string_types):
20-
return ''.join(_replace(c) for c in s)
21-
return s
19+
escaped = ''.join(_replace(c) for c in six.text_type(s))
20+
escaped = re.sub(r'\\u([\da-f]{4})', lambda m: '&#{};'.format(int(m.group(1), 16)), escaped)
21+
escaped = re.sub(r'\\U([\da-f]{8})', lambda m: '&#{};'.format(int(m.group(1), 16)), escaped)
22+
return escaped
2223

2324
six.print_(*map(_escape, args), sep=_escape(sep), end=_escape(end), file=file)
2425

test/runners/python_spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,12 @@ describe('Fixed and new features', function() {
329329
languageVersion: v,
330330
testFramework: 'cw-2',
331331
code: 'a = 1',
332-
fixture: 'print(1, "2", u"\\uac00")',
332+
fixture: 'test.uni_print(1, "a", u"\\uac00", [314159, "b", u"\\uac01"])',
333333
}, function(buffer) {
334-
expect(buffer.stdout).to.include('1 2 가');
334+
expect(buffer.stdout).to.include('1 a 가');
335+
expect(buffer.stdout).to.include('314159');
336+
expect(buffer.stdout).to.include('b');
337+
expect(buffer.stdout).to.include('각');
335338
done();
336339
});
337340
});

0 commit comments

Comments
 (0)