Commit eef5f839 authored by kenton@google.com's avatar kenton@google.com

Same as r275 except for Python.

parent 35d2f017
...@@ -191,7 +191,8 @@ class TextFormatTest(unittest.TestCase): ...@@ -191,7 +191,8 @@ class TextFormatTest(unittest.TestCase):
'repeated_double: 1.23e+22\n' 'repeated_double: 1.23e+22\n'
'repeated_double: 1.23e-18\n' 'repeated_double: 1.23e-18\n'
'repeated_string: \n' 'repeated_string: \n'
'\"\\000\\001\\007\\010\\014\\n\\r\\t\\013\\\\\\\'\\\"\"\n') '\"\\000\\001\\007\\010\\014\\n\\r\\t\\013\\\\\\\'\\\"\"\n'
'repeated_string: "foo" \'corge\' "grault"')
text_format.Merge(text, message) text_format.Merge(text, message)
self.assertEqual(-9223372036854775808, message.repeated_int64[0]) self.assertEqual(-9223372036854775808, message.repeated_int64[0])
...@@ -201,6 +202,7 @@ class TextFormatTest(unittest.TestCase): ...@@ -201,6 +202,7 @@ class TextFormatTest(unittest.TestCase):
self.assertEqual(1.23e-18, message.repeated_double[2]) self.assertEqual(1.23e-18, message.repeated_double[2])
self.assertEqual( self.assertEqual(
'\000\001\a\b\f\n\r\t\v\\\'\"', message.repeated_string[0]) '\000\001\a\b\f\n\r\t\v\\\'\"', message.repeated_string[0])
self.assertEqual('foocorgegrault', message.repeated_string[1])
def testMergeUnknownField(self): def testMergeUnknownField(self):
message = unittest_pb2.TestAllTypes() message = unittest_pb2.TestAllTypes()
......
...@@ -298,7 +298,7 @@ class _Tokenizer(object): ...@@ -298,7 +298,7 @@ class _Tokenizer(object):
'[a-zA-Z_][0-9a-zA-Z_+-]*|' # an identifier '[a-zA-Z_][0-9a-zA-Z_+-]*|' # an identifier
'[0-9+-][0-9a-zA-Z_.+-]*|' # a number '[0-9+-][0-9a-zA-Z_.+-]*|' # a number
'\"([^\"\n\\\\]|\\\\.)*(\"|\\\\?$)|' # a double-quoted string '\"([^\"\n\\\\]|\\\\.)*(\"|\\\\?$)|' # a double-quoted string
'\'([^\"\n\\\\]|\\\\.)*(\'|\\\\?$)') # a single-quoted string '\'([^\'\n\\\\]|\\\\.)*(\'|\\\\?$)') # a single-quoted string
_IDENTIFIER = re.compile('\w+') _IDENTIFIER = re.compile('\w+')
_INTEGER_CHECKERS = [type_checkers.Uint32ValueChecker(), _INTEGER_CHECKERS = [type_checkers.Uint32ValueChecker(),
type_checkers.Int32ValueChecker(), type_checkers.Int32ValueChecker(),
...@@ -530,6 +530,12 @@ class _Tokenizer(object): ...@@ -530,6 +530,12 @@ class _Tokenizer(object):
Raises: Raises:
ParseError: If a byte array value couldn't be consumed. ParseError: If a byte array value couldn't be consumed.
""" """
list = [self.ConsumeSingleByteString()]
while len(self.token) > 0 and self.token[0] in ('\'', '"'):
list.append(self.ConsumeSingleByteString())
return "".join(list)
def ConsumeSingleByteString(self):
text = self.token text = self.token
if len(text) < 1 or text[0] not in ('\'', '"'): if len(text) < 1 or text[0] not in ('\'', '"'):
raise self._ParseError('Exptected string.') raise self._ParseError('Exptected string.')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment