diff options
author | Tres Seaver <tseaver@palladion.com> | 2015-01-13 14:21:29 -0500 |
---|---|---|
committer | Tres Seaver <tseaver@palladion.com> | 2015-01-13 14:22:05 -0500 |
commit | f336d4b7a5c1d369ed508e513d482c885705e939 (patch) | |
tree | 4d0b2d191780864b6c787780193e071f2ea7f434 /python/google/protobuf/message_factory.py | |
parent | 052e0205a76717f39fc65e303fd2b92ab1df3028 (diff) |
Prepare for Python2-Python3 straddle.
- Remove PY25 cruft.
- Selectively apply cleanups from 'python-modernize':
- New exception syntax.
- Use 'six' to handle module renames.
- Use 'six' to handle text / binary stuff.
This PR covers most of the work from #66 which falls inside `python`
(rather than the Python code generation stuff in 'src').
Diffstat (limited to 'python/google/protobuf/message_factory.py')
-rw-r--r-- | python/google/protobuf/message_factory.py | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/python/google/protobuf/message_factory.py b/python/google/protobuf/message_factory.py index 7fd7bec0..36062a56 100644 --- a/python/google/protobuf/message_factory.py +++ b/python/google/protobuf/message_factory.py @@ -28,8 +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 for GAE. -# # Copyright 2012 Google Inc. All Rights Reserved. """Provides a factory class for generating dynamic messages. @@ -43,7 +41,6 @@ my_proto_instance = message_classes['some.proto.package.MessageName']() __author__ = 'matthewtoia@google.com (Matt Toia)' -import sys ##PY25 from google.protobuf import descriptor_database from google.protobuf import descriptor_pool from google.protobuf import message @@ -75,8 +72,7 @@ class MessageFactory(object): """ if descriptor.full_name not in self._classes: descriptor_name = descriptor.name - if sys.version_info[0] < 3: ##PY25 -##!PY25 if str is bytes: # PY2 + if str is bytes: # PY2 descriptor_name = descriptor.name.encode('ascii', 'ignore') result_class = reflection.GeneratedProtocolMessageType( descriptor_name, @@ -111,7 +107,7 @@ class MessageFactory(object): result = {} for file_name in files: file_desc = self.pool.FindFileByName(file_name) - for name, msg in file_desc.message_types_by_name.iteritems(): + for name, msg in file_desc.message_types_by_name.items(): if file_desc.package: full_name = '.'.join([file_desc.package, name]) else: @@ -128,7 +124,7 @@ class MessageFactory(object): # ignore the registration if the original was the same, or raise # an error if they were different. - for name, extension in file_desc.extensions_by_name.iteritems(): + for name, extension in file_desc.extensions_by_name.items(): if extension.containing_type.full_name not in self._classes: self.GetPrototype(extension.containing_type) extended_class = self._classes[extension.containing_type.full_name] |