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
3d5aa6ae
Commit
3d5aa6ae
authored
Aug 14, 2015
by
Dan O'Reilly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix some more Python 3 compat issues
Signed-off-by:
Dan O'Reilly
<
oreilldf@gmail.com
>
parent
fe7d9379
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
13 deletions
+24
-13
message_test.py
python/google/protobuf/internal/message_test.py
+15
-10
text_format_test.py
python/google/protobuf/internal/text_format_test.py
+1
-1
text_format.py
python/google/protobuf/text_format.py
+8
-2
No files found.
python/google/protobuf/internal/message_test.py
View file @
3d5aa6ae
...
...
@@ -49,6 +49,11 @@ import operator
import
pickle
import
sys
import
six
if
six
.
PY3
:
long
=
int
import
unittest
from
google.protobuf.internal
import
_parameterized
from
google.protobuf
import
map_unittest_pb2
...
...
@@ -675,7 +680,7 @@ class MessageTest(unittest.TestCase):
in the value being converted to a Unicode string."""
m
=
message_module
.
TestAllTypes
()
m
.
optional_string
=
str
(
''
)
self
.
assertTrue
(
isinstance
(
m
.
optional_string
,
unicod
e
))
self
.
assertTrue
(
isinstance
(
m
.
optional_string
,
six
.
text_typ
e
))
# TODO(haberman): why are these tests Google-internal only?
...
...
@@ -1228,7 +1233,7 @@ class Proto3Test(unittest.TestCase):
self
.
assertTrue
(
'abc'
in
msg
.
map_string_string
)
self
.
assertTrue
(
888
in
msg
.
map_int32_enum
)
self
.
assertTrue
(
isinstance
(
msg
.
map_string_string
[
'abc'
],
unicod
e
))
self
.
assertTrue
(
isinstance
(
msg
.
map_string_string
[
'abc'
],
six
.
text_typ
e
))
# Accessing an unset key still throws TypeError of the type of the key
# is incorrect.
...
...
@@ -1311,13 +1316,13 @@ class Proto3Test(unittest.TestCase):
msg
.
map_string_string
[
bytes_obj
]
=
bytes_obj
(
key
,
value
)
=
msg
.
map_string_string
.
items
(
)[
0
]
(
key
,
value
)
=
list
(
msg
.
map_string_string
.
items
()
)[
0
]
self
.
assertEqual
(
key
,
unicode_obj
)
self
.
assertEqual
(
value
,
unicode_obj
)
self
.
assertTrue
(
isinstance
(
key
,
unicod
e
))
self
.
assertTrue
(
isinstance
(
value
,
unicod
e
))
self
.
assertTrue
(
isinstance
(
key
,
six
.
text_typ
e
))
self
.
assertTrue
(
isinstance
(
value
,
six
.
text_typ
e
))
def
testMessageMap
(
self
):
msg
=
map_unittest_pb2
.
TestMap
()
...
...
@@ -1502,7 +1507,7 @@ class Proto3Test(unittest.TestCase):
def
testMapIteration
(
self
):
msg
=
map_unittest_pb2
.
TestMap
()
for
k
,
v
in
msg
.
map_int32_int32
.
ite
rite
ms
():
for
k
,
v
in
msg
.
map_int32_int32
.
items
():
# Should not be reached.
self
.
assertTrue
(
False
)
...
...
@@ -1512,7 +1517,7 @@ class Proto3Test(unittest.TestCase):
self
.
assertEqual
(
3
,
len
(
msg
.
map_int32_int32
))
matching_dict
=
{
2
:
4
,
3
:
6
,
4
:
8
}
self
.
assertMapIterEquals
(
msg
.
map_int32_int32
.
ite
rite
ms
(),
matching_dict
)
self
.
assertMapIterEquals
(
msg
.
map_int32_int32
.
items
(),
matching_dict
)
def
testMapIterationClearMessage
(
self
):
# Iterator needs to work even if message and map are deleted.
...
...
@@ -1522,7 +1527,7 @@ class Proto3Test(unittest.TestCase):
msg
.
map_int32_int32
[
3
]
=
6
msg
.
map_int32_int32
[
4
]
=
8
it
=
msg
.
map_int32_int32
.
ite
rite
ms
()
it
=
msg
.
map_int32_int32
.
items
()
del
msg
matching_dict
=
{
2
:
4
,
3
:
6
,
4
:
8
}
...
...
@@ -1550,7 +1555,7 @@ class Proto3Test(unittest.TestCase):
msg
.
ClearField
(
'map_int32_int32'
)
matching_dict
=
{
2
:
4
,
3
:
6
,
4
:
8
}
self
.
assertMapIterEquals
(
map
.
ite
rite
ms
(),
matching_dict
)
self
.
assertMapIterEquals
(
map
.
items
(),
matching_dict
)
def
testMapIterValidAfterFieldCleared
(
self
):
# Map iterator needs to work even if field is cleared.
...
...
@@ -1562,7 +1567,7 @@ class Proto3Test(unittest.TestCase):
msg
.
map_int32_int32
[
3
]
=
6
msg
.
map_int32_int32
[
4
]
=
8
it
=
msg
.
map_int32_int32
.
ite
rite
ms
()
it
=
msg
.
map_int32_int32
.
items
()
msg
.
ClearField
(
'map_int32_int32'
)
matching_dict
=
{
2
:
4
,
3
:
6
,
4
:
8
}
...
...
python/google/protobuf/internal/text_format_test.py
View file @
3d5aa6ae
...
...
@@ -101,7 +101,7 @@ class TextFormatTest(TextFormatBase):
'repeated_string: "
\\
303
\\
274
\\
352
\\
234
\\
237"
\n
'
)
def
testPrintExoticUnicodeSubclass
(
self
,
message_module
):
class
UnicodeSub
(
unicod
e
):
class
UnicodeSub
(
six
.
text_typ
e
):
pass
message
=
message_module
.
TestAllTypes
()
message
.
repeated_string
.
append
(
UnicodeSub
(
u'
\u00fc\ua71f
'
))
...
...
python/google/protobuf/text_format.py
View file @
3d5aa6ae
...
...
@@ -92,6 +92,9 @@ def MessageToString(message, as_utf8=False, as_one_line=False,
Returns:
A string of the text formatted protocol buffer message.
"""
if
as_utf8
:
out
=
io
.
BytesIO
()
else
:
out
=
io
.
BytesIO
()
PrintMessage
(
message
,
out
,
as_utf8
=
as_utf8
,
as_one_line
=
as_one_line
,
pointy_brackets
=
pointy_brackets
,
...
...
@@ -139,7 +142,6 @@ def PrintMessage(message, out, indent=0, as_utf8=False, as_one_line=False,
use_index_order
=
use_index_order
,
float_format
=
float_format
)
def
PrintField
(
field
,
value
,
out
,
indent
=
0
,
as_utf8
=
False
,
as_one_line
=
False
,
pointy_brackets
=
False
,
use_index_order
=
False
,
float_format
=
None
):
"""Print a single field name/value pair. For repeated fields, the value
...
...
@@ -160,7 +162,11 @@ def PrintField(field, value, out, indent=0, as_utf8=False, as_one_line=False,
# For groups, use the capitalized name.
out
.
write
(
field
.
message_type
.
name
)
else
:
out
.
write
(
field
.
name
)
if
isinstance
(
field
.
name
,
six
.
text_type
):
name
=
field
.
name
.
encode
(
'utf-8'
)
else
:
name
=
field
.
name
out
.
write
(
name
)
if
field
.
cpp_type
!=
descriptor
.
FieldDescriptor
.
CPPTYPE_MESSAGE
:
# The colon is optional in this case, but our cross-language golden files
...
...
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