~verterok/ubuntu/lucid/protobuf/2.4.0a-backport

« back to all changes in this revision

Viewing changes to python/google/protobuf/descriptor.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2011-05-31 14:41:47 UTC
  • mfrom: (2.2.8 sid)
  • Revision ID: james.westby@ubuntu.com-20110531144147-s41g5fozgvyo462l
Tags: 2.4.0a-2ubuntu1
* Merge with Debian; remaining changes:
  - Fix linking with -lpthread.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
29
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
30
 
31
 
# TODO(robinson): We probably need to provide deep-copy methods for
32
 
# descriptor types.  When a FieldDescriptor is passed into
33
 
# Descriptor.__init__(), we should make a deep copy and then set
34
 
# containing_type on it.  Alternatively, we could just get
35
 
# rid of containing_type (iit's not needed for reflection.py, at least).
36
 
#
37
 
# TODO(robinson): Print method?
38
 
#
39
 
# TODO(robinson): Useful __repr__?
40
 
 
41
31
"""Descriptors essentially contain exactly the information found in a .proto
42
32
file, in types that make this information accessible in Python.
43
33
"""
45
35
__author__ = 'robinson@google.com (Will Robinson)'
46
36
 
47
37
 
 
38
from google.protobuf.internal import api_implementation
 
39
 
 
40
 
 
41
if api_implementation.Type() == 'cpp':
 
42
  from google.protobuf.internal import cpp_message
 
43
 
 
44
 
48
45
class Error(Exception):
49
46
  """Base error for this module."""
50
47
 
396
393
    self.enum_type = enum_type
397
394
    self.is_extension = is_extension
398
395
    self.extension_scope = extension_scope
 
396
    if api_implementation.Type() == 'cpp':
 
397
      if is_extension:
 
398
        self._cdescriptor = cpp_message.GetExtensionDescriptor(full_name)
 
399
      else:
 
400
        self._cdescriptor = cpp_message.GetFieldDescriptor(full_name)
 
401
    else:
 
402
      self._cdescriptor = None
399
403
 
400
404
 
401
405
class EnumDescriptor(_NestedDescriptorBase):
567
571
    """Constructor."""
568
572
    super(FileDescriptor, self).__init__(options, 'FileOptions')
569
573
 
 
574
    self.message_types_by_name = {}
570
575
    self.name = name
571
576
    self.package = package
572
577
    self.serialized_pb = serialized_pb
 
578
    if (api_implementation.Type() == 'cpp' and
 
579
        self.serialized_pb is not None):
 
580
      cpp_message.BuildFile(self.serialized_pb)
573
581
 
574
582
  def CopyToProto(self, proto):
575
583
    """Copies this to a descriptor_pb2.FileDescriptorProto.