aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2015-08-22 11:51:01 -0700
committerJoshua Haberman <jhaberman@gmail.com>2015-08-22 11:51:01 -0700
commit3253634dcb2cbd5917d10aebc1a18a7692b237a3 (patch)
treee59daa06f06c158c4376fb4f04cd8af17d0f6b4a
parent3ff5625231107957286b0cae82a9e760074bf2ee (diff)
parent87993d750790f158ecdce21493a7874197bbf3b2 (diff)
downloadprotobuf-3253634dcb2cbd5917d10aebc1a18a7692b237a3.tar.gz
protobuf-3253634dcb2cbd5917d10aebc1a18a7692b237a3.tar.bz2
protobuf-3253634dcb2cbd5917d10aebc1a18a7692b237a3.zip
Merge pull request #711 from tamird/python3-prep
Remove Python 2.5 cruft
-rw-r--r--python/google/protobuf/descriptor_pool.py8
-rwxr-xr-xpython/google/protobuf/internal/_parameterized.py8
-rwxr-xr-xpython/google/protobuf/internal/message_test.py19
-rwxr-xr-xpython/google/protobuf/internal/reflection_test.py6
-rwxr-xr-xpython/google/protobuf/internal/service_reflection_test.py5
-rw-r--r--src/google/protobuf/compiler/python/python_generator.cc20
6 files changed, 25 insertions, 41 deletions
diff --git a/python/google/protobuf/descriptor_pool.py b/python/google/protobuf/descriptor_pool.py
index 1244ba7c..6a1b4b5e 100644
--- a/python/google/protobuf/descriptor_pool.py
+++ b/python/google/protobuf/descriptor_pool.py
@@ -57,8 +57,6 @@ directly instead of this class.
__author__ = 'matthewtoia@google.com (Matt Toia)'
-import sys
-
from google.protobuf import descriptor
from google.protobuf import descriptor_database
from google.protobuf import text_encoding
@@ -192,8 +190,7 @@ class DescriptorPool(object):
try:
file_proto = self._internal_db.FindFileByName(file_name)
- except KeyError:
- _, error, _ = sys.exc_info() #PY25 compatible for GAE.
+ except KeyError as error:
if self._descriptor_db:
file_proto = self._descriptor_db.FindFileByName(file_name)
else:
@@ -228,8 +225,7 @@ class DescriptorPool(object):
try:
file_proto = self._internal_db.FindFileContainingSymbol(symbol)
- except KeyError:
- _, error, _ = sys.exc_info() #PY25 compatible for GAE.
+ except KeyError as error:
if self._descriptor_db:
file_proto = self._descriptor_db.FindFileContainingSymbol(symbol)
else:
diff --git a/python/google/protobuf/internal/_parameterized.py b/python/google/protobuf/internal/_parameterized.py
index 3821b916..dea3f199 100755
--- a/python/google/protobuf/internal/_parameterized.py
+++ b/python/google/protobuf/internal/_parameterized.py
@@ -43,7 +43,7 @@ A simple example:
(4, 5, 9),
(1, 1, 3))
def testAddition(self, op1, op2, result):
- self.assertEquals(result, op1 + op2)
+ self.assertEqual(result, op1 + op2)
Each invocation is a separate test case and properly isolated just
@@ -60,7 +60,7 @@ or dictionaries (with named parameters):
{'op1': 4, 'op2': 5, 'result': 9},
)
def testAddition(self, op1, op2, result):
- self.assertEquals(result, op1 + op2)
+ self.assertEqual(result, op1 + op2)
If a parameterized test fails, the error message will show the
original test name (which is modified internally) and the arguments
@@ -88,7 +88,7 @@ str()):
('EmptyPrefix', '', 'abc', True),
('BothEmpty', '', '', True))
def testStartsWith(self, prefix, string, result):
- self.assertEquals(result, strings.startswith(prefix))
+ self.assertEqual(result, strings.startswith(prefix))
Named tests also have the benefit that they can be run individually
from the command line:
@@ -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
)
def testAddition(self, op1, op2, result):
- self.assertEquals(result, op1 + op2)
+ self.assertEqual(result, op1 + op2)
Single-Argument Test Methods
diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py
index cf3fcfe9..c4c660ec 100755
--- a/python/google/protobuf/internal/message_test.py
+++ b/python/google/protobuf/internal/message_test.py
@@ -683,9 +683,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, six.text_type))
-
-# TODO(haberman): why are these tests Google-internal only?
+ self.assertIsInstance(m.optional_string, six.text_type)
def testLongValuedSlice(self, message_module):
"""It should be possible to use long-valued indicies in slices
@@ -1071,14 +1069,13 @@ class Proto2Test(unittest.TestCase):
repeated_nested_enum=['FOO', unittest_pb2.TestAllTypes.BAR],
default_int32=800,
oneof_string='y')
- self.assertTrue(isinstance(message, unittest_pb2.TestAllTypes))
+ self.assertIsInstance(message, unittest_pb2.TestAllTypes)
self.assertEqual(100, message.optional_int32)
self.assertEqual(200, message.optional_fixed32)
self.assertEqual(300.5, message.optional_float)
self.assertEqual(b'x', message.optional_bytes)
self.assertEqual(400, message.optionalgroup.a)
- self.assertTrue(isinstance(message.optional_nested_message,
- unittest_pb2.TestAllTypes.NestedMessage))
+ self.assertIsInstance(message.optional_nested_message, unittest_pb2.TestAllTypes.NestedMessage)
self.assertEqual(500, message.optional_nested_message.bb)
self.assertEqual(unittest_pb2.TestAllTypes.BAZ,
message.optional_nested_enum)
@@ -1236,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'], six.text_type))
+ self.assertIsInstance(msg.map_string_string['abc'], six.text_type)
# Accessing an unset key still throws TypeError of the type of the key
# is incorrect.
@@ -1315,7 +1312,7 @@ class Proto3Test(unittest.TestCase):
msg = map_unittest_pb2.TestMap()
unicode_obj = u'\u1234'
- bytes_obj = unicode_obj.encode('utf8')
+ bytes_obj = unicode_obj.encode('utf8')
msg.map_string_string[bytes_obj] = bytes_obj
@@ -1324,8 +1321,8 @@ class Proto3Test(unittest.TestCase):
self.assertEqual(key, unicode_obj)
self.assertEqual(value, unicode_obj)
- self.assertTrue(isinstance(key, six.text_type))
- self.assertTrue(isinstance(value, six.text_type))
+ self.assertIsInstance(key, six.text_type)
+ self.assertIsInstance(value, six.text_type)
def testMessageMap(self):
msg = map_unittest_pb2.TestMap()
@@ -1493,7 +1490,7 @@ class Proto3Test(unittest.TestCase):
submsg = msg.map_int32_foreign_message[111]
self.assertIs(submsg, msg.map_int32_foreign_message[111])
- self.assertTrue(isinstance(submsg, unittest_pb2.ForeignMessage))
+ self.assertIsInstance(submsg, unittest_pb2.ForeignMessage)
submsg.c = 5
diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py
index 1a162272..5d691bcf 100755
--- a/python/google/protobuf/internal/reflection_test.py
+++ b/python/google/protobuf/internal/reflection_test.py
@@ -614,10 +614,10 @@ class ReflectionTest(unittest.TestCase):
def TestGetAndDeserialize(field_name, value, expected_type):
proto = unittest_pb2.TestAllTypes()
setattr(proto, field_name, value)
- self.assertTrue(isinstance(getattr(proto, field_name), expected_type))
+ self.assertIsInstance(getattr(proto, field_name), expected_type)
proto2 = unittest_pb2.TestAllTypes()
proto2.ParseFromString(proto.SerializeToString())
- self.assertTrue(isinstance(getattr(proto2, field_name), expected_type))
+ self.assertIsInstance(getattr(proto2, field_name), expected_type)
TestGetAndDeserialize('optional_int32', 1, int)
TestGetAndDeserialize('optional_int32', 1 << 30, int)
@@ -903,7 +903,7 @@ class ReflectionTest(unittest.TestCase):
self.assertTrue(proto.repeated_nested_message)
self.assertEqual(2, len(proto.repeated_nested_message))
self.assertListsEqual([m0, m1], proto.repeated_nested_message)
- self.assertTrue(isinstance(m0, unittest_pb2.TestAllTypes.NestedMessage))
+ self.assertIsInstance(m0, unittest_pb2.TestAllTypes.NestedMessage)
# Test out-of-bounds indices.
self.assertRaises(IndexError, proto.repeated_nested_message.__getitem__,
diff --git a/python/google/protobuf/internal/service_reflection_test.py b/python/google/protobuf/internal/service_reflection_test.py
index d7cd591b..98614b77 100755
--- a/python/google/protobuf/internal/service_reflection_test.py
+++ b/python/google/protobuf/internal/service_reflection_test.py
@@ -83,7 +83,7 @@ class FooUnitTest(unittest.TestCase):
self.assertEqual('Method Bar not implemented.',
rpc_controller.failure_message)
self.assertEqual(None, self.callback_response)
-
+
class MyServiceImpl(unittest_pb2.TestService):
def Foo(self, rpc_controller, request, done):
self.foo_called = True
@@ -128,8 +128,7 @@ class FooUnitTest(unittest.TestCase):
# Invoke method.
stub.Foo(rpc_controller, request, MyCallback)
- self.assertTrue(isinstance(self.callback_response,
- unittest_pb2.FooResponse))
+ self.assertIsInstance(self.callback_response, unittest_pb2.FooResponse)
self.assertEqual(request, channel.request)
self.assertEqual(rpc_controller, channel.controller)
self.assertEqual(stub.GetDescriptor().methods[0], channel.method)
diff --git a/src/google/protobuf/compiler/python/python_generator.cc b/src/google/protobuf/compiler/python/python_generator.cc
index 7b3b5fa3..d4c4c405 100644
--- a/src/google/protobuf/compiler/python/python_generator.cc
+++ b/src/google/protobuf/compiler/python/python_generator.cc
@@ -28,7 +28,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// 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.
// Author: robinson@google.com (Will Robinson)
//
@@ -166,7 +165,6 @@ void PrintTopBoilerplate(
printer->Print(
"# Generated by the protocol buffer compiler. DO NOT EDIT!\n"
"# source: $filename$\n"
- "\nimport sys\n_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))" //##PY25
"\n",
"filename", file->name());
if (HasTopLevelEnums(file)) {
@@ -258,12 +256,9 @@ string StringifyDefaultValue(const FieldDescriptor& field) {
case FieldDescriptor::CPPTYPE_ENUM:
return SimpleItoa(field.default_value_enum()->number());
case FieldDescriptor::CPPTYPE_STRING:
-//##!PY25 return "b\"" + CEscape(field.default_value_string()) +
-//##!PY25 (field.type() != FieldDescriptor::TYPE_STRING ? "\"" :
-//##!PY25 "\".decode('utf-8')");
- return "_b(\"" + CEscape(field.default_value_string()) + //##PY25
- (field.type() != FieldDescriptor::TYPE_STRING ? "\")" : //##PY25
- "\").decode('utf-8')"); //##PY25
+ return "b\"" + CEscape(field.default_value_string()) +
+ (field.type() != FieldDescriptor::TYPE_STRING ? "\"" :
+ "\".decode('utf-8')");
case FieldDescriptor::CPPTYPE_MESSAGE:
return "None";
}
@@ -389,8 +384,7 @@ void Generator::PrintFileDescriptor() const {
printer_->Print(m, file_descriptor_template);
printer_->Indent();
printer_->Print(
-//##!PY25 "serialized_pb=b'$value$'\n",
- "serialized_pb=_b('$value$')\n", //##PY25
+ "serialized_pb=b'$value$'\n",
"value", strings::CHexEscape(file_descriptor_serialized_));
if (file_->dependency_count() != 0) {
printer_->Print(",\ndependencies=[");
@@ -1034,10 +1028,8 @@ string Generator::OptionsValue(
return "None";
} else {
string full_class_name = "descriptor_pb2." + class_name;
-//##!PY25 return "_descriptor._ParseOptions(" + full_class_name + "(), b'"
-//##!PY25 + CEscape(serialized_options)+ "')";
- return "_descriptor._ParseOptions(" + full_class_name + "(), _b('" //##PY25
- + CEscape(serialized_options)+ "'))"; //##PY25
+ return "_descriptor._ParseOptions(" + full_class_name + "(), b'"
+ + CEscape(serialized_options)+ "')";
}
}