parameters: (self)
return_statement: return encoded_value
docstring: Encode oneself.
  
          Returns:
              a string representing the encoded object.
docstring_summary: Encode oneself.
docstring_tokens: Encode oneself .
function: def encode(self):
          """Encode oneself.
  
          Returns:
              a string representing the encoded object.
          """
          # If we have a read-only object that we created from a serialized value
          # and never modified since, use the original cached value.
          #
          # This ensures that objects decoded in non-strict mode will retain their
          # original encoding.
          #
          # BUG: we do not cache tag and length encoding, so reencoding is broken
          # for objects that use indefinite length encoding.
          if self._serialized_value and not self.modified():
              encoded_value = self._serialized_value
          else:
              # We can only use the cached value if the object has never been
              # modified after birth. Since mutable objects cannot track when
              # their recursive subcomponents are modified, the modified flag,
              # once set, can never be unset.
              self._serialized_value = None
              encoded_value = self._encode_value()
          for t in self.tags:
              encoded_length = encode_length(len(encoded_value))
              encoded_value = t.value + encoded_length + encoded_value
          return encoded_value
function_tokens: def encode ( self ) : # If we have a read-only object that we created from a serialized value # and never modified since, use the original cached value. # # This ensures that objects decoded in non-strict mode will retain their # original encoding. # # BUG: we do not cache tag and length encoding, so reencoding is broken # for objects that use indefinite length encoding. if self . _serialized_value and not self . modified ( ) : encoded_value = self . _serialized_value else : # We can only use the cached value if the object has never been # modified after birth. Since mutable objects cannot track when # their recursive subcomponents are modified, the modified flag, # once set, can never be unset. self . _serialized_value = None encoded_value = self . _encode_value ( ) for t in self . tags : encoded_length = encode_length ( len ( encoded_value ) ) encoded_value = t . value + encoded_length + encoded_value return encoded_value