Package google :: Package protobuf :: Module text_format :: Class _Printer
[hide private]
[frames] | no frames]

Class _Printer

source code

object --+
         |
        _Printer

Text format printer for protocol message.

Instance Methods [hide private]
 
__init__(self, out, indent=0, as_utf8=False, as_one_line=False, use_short_repeated_primitives=False, pointy_brackets=False, use_index_order=False, float_format=None, double_format=None, use_field_number=False, descriptor_pool=None, message_formatter=None, print_unknown_fields=False)
Initialize the Printer.
source code
 
_TryPrintAsAnyMessage(self, message)
Serializes if message is a google.protobuf.Any field.
source code
 
_TryCustomFormatMessage(self, message) source code
 
PrintMessage(self, message)
Convert protobuf message to text format.
source code
 
_PrintUnknownFields(self, unknown_fields)
Print unknown fields.
source code
 
_PrintFieldName(self, field)
Print field name.
source code
 
PrintField(self, field, value)
Print a single field name/value pair.
source code
 
_PrintShortRepeatedPrimitivesValue(self, field, value) source code
 
_PrintMessageFieldValue(self, value) source code
 
PrintFieldValue(self, field, value)
Print a single field value (not including name).
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, out, indent=0, as_utf8=False, as_one_line=False, use_short_repeated_primitives=False, pointy_brackets=False, use_index_order=False, float_format=None, double_format=None, use_field_number=False, descriptor_pool=None, message_formatter=None, print_unknown_fields=False)
(Constructor)

source code 
Initialize the Printer.

Double values can be formatted compactly with 15 digits of precision
(which is the most that IEEE 754 "double" can guarantee) using
double_format='.15g'. To ensure that converting to text and back to a proto
will result in an identical value, double_format='.17g' should be used.

Args:
  out: To record the text format result.
  indent: The initial indent level for pretty print.
  as_utf8: Return unescaped Unicode for non-ASCII characters.
      In Python 3 actual Unicode characters may appear as is in strings.
      In Python 2 the return value will be valid UTF-8 rather than ASCII.
  as_one_line: Don't introduce newlines between fields.
  use_short_repeated_primitives: Use short repeated format for primitives.
  pointy_brackets: If True, use angle brackets instead of curly braces for
    nesting.
  use_index_order: If True, print fields of a proto message using the order
    defined in source code instead of the field number. By default, use the
    field number order.
  float_format: If set, use this to specify float field formatting
    (per the "Format Specification Mini-Language"); otherwise, 8 valid
    digits is used (default '.8g'). Also affect double field if
    double_format is not set but float_format is set.
  double_format: If set, use this to specify double field formatting
    (per the "Format Specification Mini-Language"); if it is not set but
    float_format is set, use float_format. Otherwise, str() is used.
  use_field_number: If True, print field numbers instead of names.
  descriptor_pool: A DescriptorPool used to resolve Any types.
  message_formatter: A function(message, indent, as_one_line): unicode|None
    to custom format selected sub-messages (usually based on message type).
    Use to pretty print parts of the protobuf for easier diffing.
  print_unknown_fields: If True, unknown fields will be printed.

Overrides: object.__init__

PrintMessage(self, message)

source code 
Convert protobuf message to text format.

Args:
  message: The protocol buffers message.

PrintFieldValue(self, field, value)

source code 
Print a single field value (not including name).

For repeated fields, the value should be a single element.

Args:
  field: The descriptor of the field to be printed.
  value: The value of the field.