Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
eef5f839
Commit
eef5f839
authored
Dec 23, 2009
by
kenton@google.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Same as r275 except for Python.
parent
35d2f017
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
2 deletions
+10
-2
text_format_test.py
python/google/protobuf/internal/text_format_test.py
+3
-1
text_format.py
python/google/protobuf/text_format.py
+7
-1
No files found.
python/google/protobuf/internal/text_format_test.py
View file @
eef5f839
...
...
@@ -191,7 +191,8 @@ class TextFormatTest(unittest.TestCase):
'repeated_double: 1.23e+22
\n
'
'repeated_double: 1.23e-18
\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
)
self
.
assertEqual
(
-
9223372036854775808
,
message
.
repeated_int64
[
0
])
...
...
@@ -201,6 +202,7 @@ class TextFormatTest(unittest.TestCase):
self
.
assertEqual
(
1.23e-18
,
message
.
repeated_double
[
2
])
self
.
assertEqual
(
'
\000\001\a\b\f\n\r\t\v\\\'\"
'
,
message
.
repeated_string
[
0
])
self
.
assertEqual
(
'foocorgegrault'
,
message
.
repeated_string
[
1
])
def
testMergeUnknownField
(
self
):
message
=
unittest_pb2
.
TestAllTypes
()
...
...
python/google/protobuf/text_format.py
View file @
eef5f839
...
...
@@ -298,7 +298,7 @@ class _Tokenizer(object):
'[a-zA-Z_][0-9a-zA-Z_+-]*|'
# an identifier
'[0-9+-][0-9a-zA-Z_.+-]*|'
# a number
'
\"
([^
\"\n\\\\
]|
\\\\
.)*(
\"
|
\\\\
?$)|'
# a double-quoted string
'
\'
([^
\
"
\n\\\\
]|
\\\\
.)*(
\'
|
\\\\
?$)'
)
# a single-quoted string
'
\'
([^
\
'
\n\\\\
]|
\\\\
.)*(
\'
|
\\\\
?$)'
)
# a single-quoted string
_IDENTIFIER
=
re
.
compile
(
'
\
w+'
)
_INTEGER_CHECKERS
=
[
type_checkers
.
Uint32ValueChecker
(),
type_checkers
.
Int32ValueChecker
(),
...
...
@@ -530,6 +530,12 @@ class _Tokenizer(object):
Raises:
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
if
len
(
text
)
<
1
or
text
[
0
]
not
in
(
'
\'
'
,
'"'
):
raise
self
.
_ParseError
(
'Exptected string.'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment