_BINARY_MATCHER = re.compile(r'"([\da-f]*)"b')
+@_consume_leading_whitespace
def _binary_parser(s):
match = _BINARY_MATCHER.match(s)
def _make_utf_parser(encoding):
matcher = re.compile(r'"(.*?)"' + encoding)
- def parser(s):
+ @_consume_leading_whitespace
+ def utf_parser(s):
match = matcher.match(s)
if match:
return _shared._FAILED_PARSE_RESULT
- return parser
+ return utf_parser
def _prefix_with_comma(parser):
def wrapped(s):
string.deserialize('"deadbeef"b'),
)
+ def test_deserializes_binary_with_leading_whitespace(self):
+ self.assertEqual(
+ b'\xde\xad\xbe\xef',
+ string.deserialize(' \t\n"deadbeef"b'),
+ )
+
def test_deserializes_utf8(self):
self.assertEqual(
"Hello, world",
string.deserialize('"Hello, world"utf32'),
)
+ def test_deserializes_utf8_with_leading_whitespace(self):
+ self.assertEqual(
+ "Hello, world",
+ string.deserialize(' \t\n"Hello, world"utf8'),
+ )
+
+ def test_deserializes_utf16_with_leading_whitespace(self):
+ self.assertEqual(
+ "Hello, world",
+ string.deserialize(' \t\n"Hello, world"utf16'),
+ )
+
+ def test_deserializes_utf32_with_leading_whitespace(self):
+ self.assertEqual(
+ "Hello, world",
+ string.deserialize(' \t\n"Hello, world"utf32'),
+ )
+
def test_deserializes_list(self):
self.assertEqual(
[1,2,3,4,5],