parameters: (field, cls)
docstring: Adds a public property for a nonrepeated, composite protocol message field.
    A composite field is a "group" or "message" field.
  
    Clients can use this property to get the value of the field, but cannot
    assign to the property directly.
  
    Args:
      field: A FieldDescriptor for this field.
      cls: The class we're constructing.
docstring_summary: Adds a public property for a nonrepeated, composite protocol message field.
    A composite field is a "group" or "message" field.
docstring_tokens: Adds a public property for a nonrepeated composite protocol message field . A composite field is a group or message field .
function: def _AddPropertiesForNonRepeatedCompositeField(field, cls):
    """Adds a public property for a nonrepeated, composite protocol message field.
    A composite field is a "group" or "message" field.
  
    Clients can use this property to get the value of the field, but cannot
    assign to the property directly.
  
    Args:
      field: A FieldDescriptor for this field.
      cls: The class we're constructing.
    """
    # TODO(robinson): Remove duplication with similar method
    # for non-repeated scalars.
    proto_field_name = field.name
    python_field_name = _ValueFieldName(proto_field_name)
    has_field_name = _HasFieldName(proto_field_name)
    property_name = _PropertyName(proto_field_name)
    message_type = field.message_type
  
    def getter(self):
      # TODO(robinson): Appropriately scary note about double-checked locking.
      field_value = getattr(self, python_field_name)
      if field_value is None:
        self._lock.acquire()
        try:
          field_value = getattr(self, python_field_name)
          if field_value is None:
            field_class = message_type._concrete_class
            field_value = field_class()
            field_value._SetListener(_Listener(self, has_field_name))
            setattr(self, python_field_name, field_value)
        finally:
          self._lock.release()
      return field_value
    getter.__module__ = None
    getter.__doc__ = 'Getter for %s.' % proto_field_name
  
    # We define a setter just so we can throw an exception with a more
    # helpful error message.
    def setter(self, new_value):
      raise AttributeError('Assignment not allowed to composite field '
                           '"%s" in protocol message object.' % proto_field_name)
  
    # Add a property to encapsulate the getter.
    doc = 'Magic attribute generated for "%s" proto field.' % proto_field_name
    setattr(cls, property_name, property(getter, setter, doc=doc))
function_tokens: def _AddPropertiesForNonRepeatedCompositeField ( field , cls ) : # TODO(robinson): Remove duplication with similar method # for non-repeated scalars. proto_field_name = field . name python_field_name = _ValueFieldName ( proto_field_name ) has_field_name = _HasFieldName ( proto_field_name ) property_name = _PropertyName ( proto_field_name ) message_type = field . message_type def getter ( self ) : # TODO(robinson): Appropriately scary note about double-checked locking. field_value = getattr ( self , python_field_name ) if field_value is None : self . _lock . acquire ( ) try : field_value = getattr ( self , python_field_name ) if field_value is None : field_class = message_type . _concrete_class field_value = field_class ( ) field_value . _SetListener ( _Listener ( self , has_field_name ) ) setattr ( self , python_field_name , field_value ) finally : self . _lock . release ( ) return field_value getter . __module__ = None getter . __doc__ = 'Getter for %s.' % proto_field_name # We define a setter just so we can throw an exception with a more # helpful error message. def setter ( self , new_value ) : raise AttributeError ( 'Assignment not allowed to composite field ' '"%s" in protocol message object.' % proto_field_name ) # Add a property to encapsulate the getter. doc = 'Magic attribute generated for "%s" proto field.' % proto_field_name setattr ( cls , property_name , property ( getter , setter , doc = doc ) )