Index: third_party/protobuf/python/google/protobuf/descriptor_database.py |
diff --git a/third_party/protobuf/python/google/protobuf/descriptor_database.py b/third_party/protobuf/python/google/protobuf/descriptor_database.py |
index 8665d3c59d0a9d631c3f28d07fc3df8d3a87aa68..1333f9966e4cd55a24e349602db14150f5d4b5bb 100644 |
--- a/third_party/protobuf/python/google/protobuf/descriptor_database.py |
+++ b/third_party/protobuf/python/google/protobuf/descriptor_database.py |
@@ -1,6 +1,6 @@ |
# Protocol Buffers - Google's data interchange format |
# Copyright 2008 Google Inc. All rights reserved. |
-# http://code.google.com/p/protobuf/ |
+# https://developers.google.com/protocol-buffers/ |
# |
# Redistribution and use in source and binary forms, with or without |
# modification, are permitted provided that the following conditions are |
@@ -33,6 +33,14 @@ |
__author__ = 'matthewtoia@google.com (Matt Toia)' |
+class Error(Exception): |
+ pass |
+ |
+ |
+class DescriptorDatabaseConflictingDefinitionError(Error): |
+ """Raised when a proto is added with the same name & different descriptor.""" |
+ |
+ |
class DescriptorDatabase(object): |
"""A container accepting FileDescriptorProtos and maps DescriptorProtos.""" |
@@ -45,9 +53,19 @@ class DescriptorDatabase(object): |
Args: |
file_desc_proto: The FileDescriptorProto to add. |
+ Raises: |
+ DescriptorDatabaseException: if an attempt is made to add a proto |
+ with the same name but different definition than an exisiting |
+ proto in the database. |
""" |
- |
- self._file_desc_protos_by_file[file_desc_proto.name] = file_desc_proto |
+ proto_name = file_desc_proto.name |
+ if proto_name not in self._file_desc_protos_by_file: |
+ self._file_desc_protos_by_file[proto_name] = file_desc_proto |
+ elif self._file_desc_protos_by_file[proto_name] != file_desc_proto: |
+ raise DescriptorDatabaseConflictingDefinitionError( |
+ '%s already added, but with different descriptor.' % proto_name) |
+ |
+ # Add the top-level Message, Enum and Extension descriptors to the index. |
package = file_desc_proto.package |
for message in file_desc_proto.message_type: |
self._file_desc_protos_by_symbol.update( |
@@ -55,6 +73,9 @@ class DescriptorDatabase(object): |
for enum in file_desc_proto.enum_type: |
self._file_desc_protos_by_symbol[ |
'.'.join((package, enum.name))] = file_desc_proto |
+ for extension in file_desc_proto.extension: |
+ self._file_desc_protos_by_symbol[ |
+ '.'.join((package, extension.name))] = file_desc_proto |
def FindFileByName(self, name): |
"""Finds the file descriptor proto by file name. |
@@ -116,5 +137,5 @@ def _ExtractSymbols(desc_proto, package): |
for nested_type in desc_proto.nested_type: |
for symbol in _ExtractSymbols(nested_type, message_name): |
yield symbol |
- for enum_type in desc_proto.enum_type: |
- yield '.'.join((message_name, enum_type.name)) |
+ for enum_type in desc_proto.enum_type: |
+ yield '.'.join((message_name, enum_type.name)) |