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
3253634d
Commit
3253634d
authored
Aug 22, 2015
by
Joshua Haberman
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #711 from tamird/python3-prep
Remove Python 2.5 cruft
parents
3ff56252
87993d75
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
23 additions
and
39 deletions
+23
-39
descriptor_pool.py
python/google/protobuf/descriptor_pool.py
+2
-6
_parameterized.py
python/google/protobuf/internal/_parameterized.py
+4
-4
message_test.py
python/google/protobuf/internal/message_test.py
+7
-10
reflection_test.py
python/google/protobuf/internal/reflection_test.py
+3
-3
service_reflection_test.py
python/google/protobuf/internal/service_reflection_test.py
+1
-2
python_generator.cc
src/google/protobuf/compiler/python/python_generator.cc
+6
-14
No files found.
python/google/protobuf/descriptor_pool.py
View file @
3253634d
...
@@ -57,8 +57,6 @@ directly instead of this class.
...
@@ -57,8 +57,6 @@ directly instead of this class.
__author__
=
'matthewtoia@google.com (Matt Toia)'
__author__
=
'matthewtoia@google.com (Matt Toia)'
import
sys
from
google.protobuf
import
descriptor
from
google.protobuf
import
descriptor
from
google.protobuf
import
descriptor_database
from
google.protobuf
import
descriptor_database
from
google.protobuf
import
text_encoding
from
google.protobuf
import
text_encoding
...
@@ -192,8 +190,7 @@ class DescriptorPool(object):
...
@@ -192,8 +190,7 @@ class DescriptorPool(object):
try
:
try
:
file_proto
=
self
.
_internal_db
.
FindFileByName
(
file_name
)
file_proto
=
self
.
_internal_db
.
FindFileByName
(
file_name
)
except
KeyError
:
except
KeyError
as
error
:
_
,
error
,
_
=
sys
.
exc_info
()
#PY25 compatible for GAE.
if
self
.
_descriptor_db
:
if
self
.
_descriptor_db
:
file_proto
=
self
.
_descriptor_db
.
FindFileByName
(
file_name
)
file_proto
=
self
.
_descriptor_db
.
FindFileByName
(
file_name
)
else
:
else
:
...
@@ -228,8 +225,7 @@ class DescriptorPool(object):
...
@@ -228,8 +225,7 @@ class DescriptorPool(object):
try
:
try
:
file_proto
=
self
.
_internal_db
.
FindFileContainingSymbol
(
symbol
)
file_proto
=
self
.
_internal_db
.
FindFileContainingSymbol
(
symbol
)
except
KeyError
:
except
KeyError
as
error
:
_
,
error
,
_
=
sys
.
exc_info
()
#PY25 compatible for GAE.
if
self
.
_descriptor_db
:
if
self
.
_descriptor_db
:
file_proto
=
self
.
_descriptor_db
.
FindFileContainingSymbol
(
symbol
)
file_proto
=
self
.
_descriptor_db
.
FindFileContainingSymbol
(
symbol
)
else
:
else
:
...
...
python/google/protobuf/internal/_parameterized.py
View file @
3253634d
...
@@ -43,7 +43,7 @@ A simple example:
...
@@ -43,7 +43,7 @@ A simple example:
(4, 5, 9),
(4, 5, 9),
(1, 1, 3))
(1, 1, 3))
def testAddition(self, op1, op2, result):
def testAddition(self, op1, op2, result):
self.assertEqual
s
(result, op1 + op2)
self.assertEqual(result, op1 + op2)
Each invocation is a separate test case and properly isolated just
Each invocation is a separate test case and properly isolated just
...
@@ -60,7 +60,7 @@ or dictionaries (with named parameters):
...
@@ -60,7 +60,7 @@ or dictionaries (with named parameters):
{'op1': 4, 'op2': 5, 'result': 9},
{'op1': 4, 'op2': 5, 'result': 9},
)
)
def testAddition(self, op1, op2, result):
def testAddition(self, op1, op2, result):
self.assertEqual
s
(result, op1 + op2)
self.assertEqual(result, op1 + op2)
If a parameterized test fails, the error message will show the
If a parameterized test fails, the error message will show the
original test name (which is modified internally) and the arguments
original test name (which is modified internally) and the arguments
...
@@ -88,7 +88,7 @@ str()):
...
@@ -88,7 +88,7 @@ str()):
('EmptyPrefix', '', 'abc', True),
('EmptyPrefix', '', 'abc', True),
('BothEmpty', '', '', True))
('BothEmpty', '', '', True))
def testStartsWith(self, prefix, string, result):
def testStartsWith(self, prefix, string, result):
self.assertEqual
s
(result, strings.startswith(prefix))
self.assertEqual(result, strings.startswith(prefix))
Named tests also have the benefit that they can be run individually
Named tests also have the benefit that they can be run individually
from the command line:
from the command line:
...
@@ -127,7 +127,7 @@ the decorator. This iterable will be used to obtain the test cases:
...
@@ -127,7 +127,7 @@ the decorator. This iterable will be used to obtain the test cases:
c.op1, c.op2, c.result for c in testcases
c.op1, c.op2, c.result for c in testcases
)
)
def testAddition(self, op1, op2, result):
def testAddition(self, op1, op2, result):
self.assertEqual
s
(result, op1 + op2)
self.assertEqual(result, op1 + op2)
Single-Argument Test Methods
Single-Argument Test Methods
...
...
python/google/protobuf/internal/message_test.py
View file @
3253634d
...
@@ -683,9 +683,7 @@ class MessageTest(unittest.TestCase):
...
@@ -683,9 +683,7 @@ class MessageTest(unittest.TestCase):
in the value being converted to a Unicode string."""
in the value being converted to a Unicode string."""
m
=
message_module
.
TestAllTypes
()
m
=
message_module
.
TestAllTypes
()
m
.
optional_string
=
str
(
''
)
m
.
optional_string
=
str
(
''
)
self
.
assertTrue
(
isinstance
(
m
.
optional_string
,
six
.
text_type
))
self
.
assertIsInstance
(
m
.
optional_string
,
six
.
text_type
)
# TODO(haberman): why are these tests Google-internal only?
def
testLongValuedSlice
(
self
,
message_module
):
def
testLongValuedSlice
(
self
,
message_module
):
"""It should be possible to use long-valued indicies in slices
"""It should be possible to use long-valued indicies in slices
...
@@ -1071,14 +1069,13 @@ class Proto2Test(unittest.TestCase):
...
@@ -1071,14 +1069,13 @@ class Proto2Test(unittest.TestCase):
repeated_nested_enum
=
[
'FOO'
,
unittest_pb2
.
TestAllTypes
.
BAR
],
repeated_nested_enum
=
[
'FOO'
,
unittest_pb2
.
TestAllTypes
.
BAR
],
default_int32
=
800
,
default_int32
=
800
,
oneof_string
=
'y'
)
oneof_string
=
'y'
)
self
.
assert
True
(
isinstance
(
message
,
unittest_pb2
.
TestAllTypes
)
)
self
.
assert
IsInstance
(
message
,
unittest_pb2
.
TestAllTypes
)
self
.
assertEqual
(
100
,
message
.
optional_int32
)
self
.
assertEqual
(
100
,
message
.
optional_int32
)
self
.
assertEqual
(
200
,
message
.
optional_fixed32
)
self
.
assertEqual
(
200
,
message
.
optional_fixed32
)
self
.
assertEqual
(
300.5
,
message
.
optional_float
)
self
.
assertEqual
(
300.5
,
message
.
optional_float
)
self
.
assertEqual
(
b
'x'
,
message
.
optional_bytes
)
self
.
assertEqual
(
b
'x'
,
message
.
optional_bytes
)
self
.
assertEqual
(
400
,
message
.
optionalgroup
.
a
)
self
.
assertEqual
(
400
,
message
.
optionalgroup
.
a
)
self
.
assertTrue
(
isinstance
(
message
.
optional_nested_message
,
self
.
assertIsInstance
(
message
.
optional_nested_message
,
unittest_pb2
.
TestAllTypes
.
NestedMessage
)
unittest_pb2
.
TestAllTypes
.
NestedMessage
))
self
.
assertEqual
(
500
,
message
.
optional_nested_message
.
bb
)
self
.
assertEqual
(
500
,
message
.
optional_nested_message
.
bb
)
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
.
BAZ
,
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
.
BAZ
,
message
.
optional_nested_enum
)
message
.
optional_nested_enum
)
...
@@ -1236,7 +1233,7 @@ class Proto3Test(unittest.TestCase):
...
@@ -1236,7 +1233,7 @@ class Proto3Test(unittest.TestCase):
self
.
assertTrue
(
'abc'
in
msg
.
map_string_string
)
self
.
assertTrue
(
'abc'
in
msg
.
map_string_string
)
self
.
assertTrue
(
888
in
msg
.
map_int32_enum
)
self
.
assertTrue
(
888
in
msg
.
map_int32_enum
)
self
.
assert
True
(
isinstance
(
msg
.
map_string_string
[
'abc'
],
six
.
text_type
)
)
self
.
assert
IsInstance
(
msg
.
map_string_string
[
'abc'
],
six
.
text_type
)
# Accessing an unset key still throws TypeError of the type of the key
# Accessing an unset key still throws TypeError of the type of the key
# is incorrect.
# is incorrect.
...
@@ -1324,8 +1321,8 @@ class Proto3Test(unittest.TestCase):
...
@@ -1324,8 +1321,8 @@ class Proto3Test(unittest.TestCase):
self
.
assertEqual
(
key
,
unicode_obj
)
self
.
assertEqual
(
key
,
unicode_obj
)
self
.
assertEqual
(
value
,
unicode_obj
)
self
.
assertEqual
(
value
,
unicode_obj
)
self
.
assert
True
(
isinstance
(
key
,
six
.
text_type
)
)
self
.
assert
IsInstance
(
key
,
six
.
text_type
)
self
.
assert
True
(
isinstance
(
value
,
six
.
text_type
)
)
self
.
assert
IsInstance
(
value
,
six
.
text_type
)
def
testMessageMap
(
self
):
def
testMessageMap
(
self
):
msg
=
map_unittest_pb2
.
TestMap
()
msg
=
map_unittest_pb2
.
TestMap
()
...
@@ -1493,7 +1490,7 @@ class Proto3Test(unittest.TestCase):
...
@@ -1493,7 +1490,7 @@ class Proto3Test(unittest.TestCase):
submsg
=
msg
.
map_int32_foreign_message
[
111
]
submsg
=
msg
.
map_int32_foreign_message
[
111
]
self
.
assertIs
(
submsg
,
msg
.
map_int32_foreign_message
[
111
])
self
.
assertIs
(
submsg
,
msg
.
map_int32_foreign_message
[
111
])
self
.
assert
True
(
isinstance
(
submsg
,
unittest_pb2
.
ForeignMessage
)
)
self
.
assert
IsInstance
(
submsg
,
unittest_pb2
.
ForeignMessage
)
submsg
.
c
=
5
submsg
.
c
=
5
...
...
python/google/protobuf/internal/reflection_test.py
View file @
3253634d
...
@@ -614,10 +614,10 @@ class ReflectionTest(unittest.TestCase):
...
@@ -614,10 +614,10 @@ class ReflectionTest(unittest.TestCase):
def
TestGetAndDeserialize
(
field_name
,
value
,
expected_type
):
def
TestGetAndDeserialize
(
field_name
,
value
,
expected_type
):
proto
=
unittest_pb2
.
TestAllTypes
()
proto
=
unittest_pb2
.
TestAllTypes
()
setattr
(
proto
,
field_name
,
value
)
setattr
(
proto
,
field_name
,
value
)
self
.
assert
True
(
isinstance
(
getattr
(
proto
,
field_name
),
expected_type
)
)
self
.
assert
IsInstance
(
getattr
(
proto
,
field_name
),
expected_type
)
proto2
=
unittest_pb2
.
TestAllTypes
()
proto2
=
unittest_pb2
.
TestAllTypes
()
proto2
.
ParseFromString
(
proto
.
SerializeToString
())
proto2
.
ParseFromString
(
proto
.
SerializeToString
())
self
.
assert
True
(
isinstance
(
getattr
(
proto2
,
field_name
),
expected_type
)
)
self
.
assert
IsInstance
(
getattr
(
proto2
,
field_name
),
expected_type
)
TestGetAndDeserialize
(
'optional_int32'
,
1
,
int
)
TestGetAndDeserialize
(
'optional_int32'
,
1
,
int
)
TestGetAndDeserialize
(
'optional_int32'
,
1
<<
30
,
int
)
TestGetAndDeserialize
(
'optional_int32'
,
1
<<
30
,
int
)
...
@@ -903,7 +903,7 @@ class ReflectionTest(unittest.TestCase):
...
@@ -903,7 +903,7 @@ class ReflectionTest(unittest.TestCase):
self
.
assertTrue
(
proto
.
repeated_nested_message
)
self
.
assertTrue
(
proto
.
repeated_nested_message
)
self
.
assertEqual
(
2
,
len
(
proto
.
repeated_nested_message
))
self
.
assertEqual
(
2
,
len
(
proto
.
repeated_nested_message
))
self
.
assertListsEqual
([
m0
,
m1
],
proto
.
repeated_nested_message
)
self
.
assertListsEqual
([
m0
,
m1
],
proto
.
repeated_nested_message
)
self
.
assert
True
(
isinstance
(
m0
,
unittest_pb2
.
TestAllTypes
.
NestedMessage
)
)
self
.
assert
IsInstance
(
m0
,
unittest_pb2
.
TestAllTypes
.
NestedMessage
)
# Test out-of-bounds indices.
# Test out-of-bounds indices.
self
.
assertRaises
(
IndexError
,
proto
.
repeated_nested_message
.
__getitem__
,
self
.
assertRaises
(
IndexError
,
proto
.
repeated_nested_message
.
__getitem__
,
...
...
python/google/protobuf/internal/service_reflection_test.py
View file @
3253634d
...
@@ -128,8 +128,7 @@ class FooUnitTest(unittest.TestCase):
...
@@ -128,8 +128,7 @@ class FooUnitTest(unittest.TestCase):
# Invoke method.
# Invoke method.
stub
.
Foo
(
rpc_controller
,
request
,
MyCallback
)
stub
.
Foo
(
rpc_controller
,
request
,
MyCallback
)
self
.
assertTrue
(
isinstance
(
self
.
callback_response
,
self
.
assertIsInstance
(
self
.
callback_response
,
unittest_pb2
.
FooResponse
)
unittest_pb2
.
FooResponse
))
self
.
assertEqual
(
request
,
channel
.
request
)
self
.
assertEqual
(
request
,
channel
.
request
)
self
.
assertEqual
(
rpc_controller
,
channel
.
controller
)
self
.
assertEqual
(
rpc_controller
,
channel
.
controller
)
self
.
assertEqual
(
stub
.
GetDescriptor
()
.
methods
[
0
],
channel
.
method
)
self
.
assertEqual
(
stub
.
GetDescriptor
()
.
methods
[
0
],
channel
.
method
)
...
...
src/google/protobuf/compiler/python/python_generator.cc
View file @
3253634d
...
@@ -28,7 +28,6 @@
...
@@ -28,7 +28,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//#PY25 compatible generated code for GAE.
// Copyright 2007 Google Inc. All Rights Reserved.
// Copyright 2007 Google Inc. All Rights Reserved.
// Author: robinson@google.com (Will Robinson)
// Author: robinson@google.com (Will Robinson)
//
//
...
@@ -166,7 +165,6 @@ void PrintTopBoilerplate(
...
@@ -166,7 +165,6 @@ void PrintTopBoilerplate(
printer
->
Print
(
printer
->
Print
(
"# Generated by the protocol buffer compiler. DO NOT EDIT!
\n
"
"# Generated by the protocol buffer compiler. DO NOT EDIT!
\n
"
"# source: $filename$
\n
"
"# source: $filename$
\n
"
"
\n
import sys
\n
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))"
//##PY25
"
\n
"
,
"
\n
"
,
"filename"
,
file
->
name
());
"filename"
,
file
->
name
());
if
(
HasTopLevelEnums
(
file
))
{
if
(
HasTopLevelEnums
(
file
))
{
...
@@ -258,12 +256,9 @@ string StringifyDefaultValue(const FieldDescriptor& field) {
...
@@ -258,12 +256,9 @@ string StringifyDefaultValue(const FieldDescriptor& field) {
case
FieldDescriptor
:
:
CPPTYPE_ENUM
:
case
FieldDescriptor
:
:
CPPTYPE_ENUM
:
return
SimpleItoa
(
field
.
default_value_enum
()
->
number
());
return
SimpleItoa
(
field
.
default_value_enum
()
->
number
());
case
FieldDescriptor
:
:
CPPTYPE_STRING
:
case
FieldDescriptor
:
:
CPPTYPE_STRING
:
//##!PY25 return "b\"" + CEscape(field.default_value_string()) +
return
"b
\"
"
+
CEscape
(
field
.
default_value_string
())
+
//##!PY25 (field.type() != FieldDescriptor::TYPE_STRING ? "\"" :
(
field
.
type
()
!=
FieldDescriptor
::
TYPE_STRING
?
"
\"
"
:
//##!PY25 "\".decode('utf-8')");
"
\"
.decode('utf-8')"
);
return
"_b(
\"
"
+
CEscape
(
field
.
default_value_string
())
+
//##PY25
(
field
.
type
()
!=
FieldDescriptor
::
TYPE_STRING
?
"
\"
)"
:
//##PY25
"
\"
).decode('utf-8')"
);
//##PY25
case
FieldDescriptor
:
:
CPPTYPE_MESSAGE
:
case
FieldDescriptor
:
:
CPPTYPE_MESSAGE
:
return
"None"
;
return
"None"
;
}
}
...
@@ -389,8 +384,7 @@ void Generator::PrintFileDescriptor() const {
...
@@ -389,8 +384,7 @@ void Generator::PrintFileDescriptor() const {
printer_
->
Print
(
m
,
file_descriptor_template
);
printer_
->
Print
(
m
,
file_descriptor_template
);
printer_
->
Indent
();
printer_
->
Indent
();
printer_
->
Print
(
printer_
->
Print
(
//##!PY25 "serialized_pb=b'$value$'\n",
"serialized_pb=b'$value$'
\n
"
,
"serialized_pb=_b('$value$')
\n
"
,
//##PY25
"value"
,
strings
::
CHexEscape
(
file_descriptor_serialized_
));
"value"
,
strings
::
CHexEscape
(
file_descriptor_serialized_
));
if
(
file_
->
dependency_count
()
!=
0
)
{
if
(
file_
->
dependency_count
()
!=
0
)
{
printer_
->
Print
(
",
\n
dependencies=["
);
printer_
->
Print
(
",
\n
dependencies=["
);
...
@@ -1034,10 +1028,8 @@ string Generator::OptionsValue(
...
@@ -1034,10 +1028,8 @@ string Generator::OptionsValue(
return
"None"
;
return
"None"
;
}
else
{
}
else
{
string
full_class_name
=
"descriptor_pb2."
+
class_name
;
string
full_class_name
=
"descriptor_pb2."
+
class_name
;
//##!PY25 return "_descriptor._ParseOptions(" + full_class_name + "(), b'"
return
"_descriptor._ParseOptions("
+
full_class_name
+
"(), b'"
//##!PY25 + CEscape(serialized_options)+ "')";
+
CEscape
(
serialized_options
)
+
"')"
;
return
"_descriptor._ParseOptions("
+
full_class_name
+
"(), _b('"
//##PY25
+
CEscape
(
serialized_options
)
+
"'))"
;
//##PY25
}
}
}
}
...
...
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