Classes | |
class | _Parser |
class | _Printer |
class | Error |
class | ParseError |
class | TextWriter |
class | Tokenizer |
Functions | |
def | _BuildMessageFromTypeName (type_name, descriptor_pool) |
def | _ConsumeInt32 (tokenizer) |
def | _ConsumeInt64 (tokenizer) |
def | _ConsumeInteger (tokenizer, is_signed=False, is_long=False) |
def | _ConsumeUint32 (tokenizer) |
def | _ConsumeUint64 (tokenizer) |
def | _IsMapEntry (field) |
def | _ParseAbstractInteger (text, is_long=False) |
def | _SkipField (tokenizer) |
def | _SkipFieldContents (tokenizer) |
def | _SkipFieldMessage (tokenizer) |
def | _SkipFieldValue (tokenizer) |
def | _TryConsumeInt64 (tokenizer) |
def | _TryConsumeInteger (tokenizer, is_signed=False, is_long=False) |
def | _TryConsumeUint64 (tokenizer) |
def | Merge (text, message, allow_unknown_extension=False, allow_field_number=False, descriptor_pool=None, allow_unknown_field=False) |
def | MergeLines (lines, message, allow_unknown_extension=False, allow_field_number=False, descriptor_pool=None, allow_unknown_field=False) |
def | MessageToBytes (message, **kwargs) |
def | MessageToString (message, 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, indent=0, message_formatter=None, print_unknown_fields=False) |
def | Parse (text, message, allow_unknown_extension=False, allow_field_number=False, descriptor_pool=None, allow_unknown_field=False) |
def | ParseBool (text) |
def | ParseEnum (field, value) |
def | ParseFloat (text) |
def | ParseInteger (text, is_signed=False, is_long=False) |
def | ParseLines (lines, message, allow_unknown_extension=False, allow_field_number=False, descriptor_pool=None, allow_unknown_field=False) |
def | PrintField (field, value, 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, message_formatter=None, print_unknown_fields=False) |
def | PrintFieldValue (field, value, 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, message_formatter=None, print_unknown_fields=False) |
def | PrintMessage (message, 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) |
Variables | |
list | __all__ |
string | __author__ = 'kenton@google.com (Kenton Varda)' |
string | _ANY_FULL_TYPE_NAME = 'google.protobuf.Any' |
_FLOAT_INFINITY = re.compile('-?inf(?:inity)?f?$', re.IGNORECASE) | |
_FLOAT_NAN = re.compile('nanf?$', re.IGNORECASE) | |
tuple | _INTEGER_CHECKERS |
_QUOTES = frozenset(("'", '"')) | |
_Tokenizer = Tokenizer | |
long = int | |
int | WIRETYPE_LENGTH_DELIMITED = 2 |
int | WIRETYPE_START_GROUP = 3 |
|
private |
Returns a protobuf message instance. Args: type_name: Fully-qualified protobuf message type name string. descriptor_pool: DescriptorPool instance. Returns: A Message instance of type matching type_name, or None if the a Descriptor wasn't found matching type_name.
Definition at line 277 of file text_format.py.
|
private |
Consumes a signed 32bit integer number from tokenizer. Args: tokenizer: A tokenizer used to parse the number. Returns: The integer parsed. Raises: ParseError: If a signed 32bit integer couldn't be consumed.
Definition at line 1525 of file text_format.py.
|
private |
Consumes a signed 32bit integer number from tokenizer. Args: tokenizer: A tokenizer used to parse the number. Returns: The integer parsed. Raises: ParseError: If a signed 32bit integer couldn't be consumed.
Definition at line 1563 of file text_format.py.
|
private |
Consumes an integer number from tokenizer. Args: tokenizer: A tokenizer used to parse the number. is_signed: True if a signed integer must be parsed. is_long: True if a long integer must be parsed. Returns: The integer parsed. Raises: ParseError: If an integer with given characteristics couldn't be consumed.
Definition at line 1609 of file text_format.py.
|
private |
Consumes an unsigned 32bit integer number from tokenizer. Args: tokenizer: A tokenizer used to parse the number. Returns: The integer parsed. Raises: ParseError: If an unsigned 32bit integer couldn't be consumed.
Definition at line 1540 of file text_format.py.
|
private |
Consumes an unsigned 64bit integer number from tokenizer. Args: tokenizer: A tokenizer used to parse the number. Returns: The integer parsed. Raises: ParseError: If an unsigned 64bit integer couldn't be consumed.
Definition at line 1586 of file text_format.py.
|
private |
Definition at line 198 of file text_format.py.
|
private |
Parses an integer without checking size/signedness. Args: text: The text to parse. is_long: True if the value should be returned as a long integer. Returns: The integer value. Raises: ValueError: Thrown Iff the text is not a valid integer.
Definition at line 1654 of file text_format.py.
|
private |
Skips over a complete field (name and value/message). Args: tokenizer: A tokenizer to parse the field name and values.
Definition at line 1114 of file text_format.py.
|
private |
Skips over contents (value or message) of a field. Args: tokenizer: A tokenizer to parse the field name and values.
Definition at line 1095 of file text_format.py.
|
private |
Skips over a field message. Args: tokenizer: A tokenizer to parse the field name and values.
Definition at line 1137 of file text_format.py.
|
private |
Skips over a field value. Args: tokenizer: A tokenizer to parse the field name and values. Raises: ParseError: In case an invalid field value is found.
Definition at line 1156 of file text_format.py.
|
private |
Definition at line 1555 of file text_format.py.
|
private |
Definition at line 1601 of file text_format.py.
|
private |
Definition at line 1578 of file text_format.py.
def google.protobuf.text_format.Merge | ( | text, | |
message, | |||
allow_unknown_extension = False , |
|||
allow_field_number = False , |
|||
descriptor_pool = None , |
|||
allow_unknown_field = False |
|||
) |
Parses a text representation of a protocol message into a message. Like Parse(), but allows repeated values for a non-repeated field, and uses the last one. Args: text: Message text representation. message: A protocol buffer message to merge into. allow_unknown_extension: if True, skip over missing extensions and keep parsing allow_field_number: if True, both field number and field name are allowed. descriptor_pool: A DescriptorPool used to resolve Any types. allow_unknown_field: if True, skip over unknown field and keep parsing. Avoid to use this option if possible. It may hide some errors (e.g. spelling error on field name) Returns: The same message passed as argument. Raises: ParseError: On text parsing problems.
Definition at line 656 of file text_format.py.
def google.protobuf.text_format.MergeLines | ( | lines, | |
message, | |||
allow_unknown_extension = False , |
|||
allow_field_number = False , |
|||
descriptor_pool = None , |
|||
allow_unknown_field = False |
|||
) |
Parses a text representation of a protocol message into a message. Like ParseLines(), but allows repeated values for a non-repeated field, and uses the last one. Args: lines: An iterable of lines of a message's text representation. message: A protocol buffer message to merge into. allow_unknown_extension: if True, skip over missing extensions and keep parsing allow_field_number: if True, both field number and field name are allowed. descriptor_pool: A DescriptorPool used to resolve Any types. allow_unknown_field: if True, skip over unknown field and keep parsing. Avoid to use this option if possible. It may hide some errors (e.g. spelling error on field name) Returns: The same message passed as argument. Raises: ParseError: On text parsing problems.
Definition at line 725 of file text_format.py.
def google.protobuf.text_format.MessageToBytes | ( | message, | |
** | kwargs | ||
) |
Convert protobuf message to encoded text format. See MessageToString.
Definition at line 188 of file text_format.py.
def google.protobuf.text_format.MessageToString | ( | message, | |
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 , |
|||
indent = 0 , |
|||
message_formatter = None , |
|||
print_unknown_fields = False |
|||
) |
Convert protobuf message to text format. 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: message: The protocol buffers message. 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 only 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, fields of a proto message will be printed using the order defined in source code instead of the field number, extensions will be printed at the end of the message and their relative order is determined by the extension 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, use str() use_field_number: If True, print field numbers instead of names. descriptor_pool: A DescriptorPool used to resolve Any types. indent: The initial indent level, in terms of spaces, for pretty print. 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. Returns: A string of the text formatted protocol buffer message.
Definition at line 120 of file text_format.py.
def google.protobuf.text_format.Parse | ( | text, | |
message, | |||
allow_unknown_extension = False , |
|||
allow_field_number = False , |
|||
descriptor_pool = None , |
|||
allow_unknown_field = False |
|||
) |
Parses a text representation of a protocol message into a message. NOTE: for historical reasons this function does not clear the input message. This is different from what the binary msg.ParseFrom(...) does. Example a = MyProto() a.repeated_field.append('test') b = MyProto() text_format.Parse(repr(a), b) text_format.Parse(repr(a), b) # repeated_field contains ["test", "test"] # Binary version: b.ParseFromString(a.SerializeToString()) # repeated_field is now "test" Caller is responsible for clearing the message as needed. Args: text: Message text representation. message: A protocol buffer message to merge into. allow_unknown_extension: if True, skip over missing extensions and keep parsing allow_field_number: if True, both field number and field name are allowed. descriptor_pool: A DescriptorPool used to resolve Any types. allow_unknown_field: if True, skip over unknown field and keep parsing. Avoid to use this option if possible. It may hide some errors (e.g. spelling error on field name) Returns: The same message passed as argument. Raises: ParseError: On text parsing problems.
Definition at line 607 of file text_format.py.
def google.protobuf.text_format.ParseBool | ( | text | ) |
Parse a boolean value. Args: text: Text to parse. Returns: Boolean values parsed Raises: ValueError: If text is not a valid boolean.
Definition at line 1718 of file text_format.py.
def google.protobuf.text_format.ParseEnum | ( | field, | |
value | |||
) |
Parse an enum value. The value can be specified by a number (the enum value), or by a string literal (the enum name). Args: field: Enum field descriptor. value: String value. Returns: Enum value number. Raises: ValueError: If the enum value could not be parsed.
Definition at line 1738 of file text_format.py.
def google.protobuf.text_format.ParseFloat | ( | text | ) |
Parse a floating point number. Args: text: Text to parse. Returns: The number parsed. Raises: ValueError: If a floating point number couldn't be parsed.
Definition at line 1686 of file text_format.py.
def google.protobuf.text_format.ParseInteger | ( | text, | |
is_signed = False , |
|||
is_long = False |
|||
) |
Parses an integer. Args: text: The text to parse. is_signed: True if a signed integer must be parsed. is_long: True if a long integer must be parsed. Returns: The integer value. Raises: ValueError: Thrown Iff the text is not a valid integer.
Definition at line 1631 of file text_format.py.
def google.protobuf.text_format.ParseLines | ( | lines, | |
message, | |||
allow_unknown_extension = False , |
|||
allow_field_number = False , |
|||
descriptor_pool = None , |
|||
allow_unknown_field = False |
|||
) |
Parses a text representation of a protocol message into a message. Args: lines: An iterable of lines of a message's text representation. message: A protocol buffer message to merge into. allow_unknown_extension: if True, skip over missing extensions and keep parsing allow_field_number: if True, both field number and field name are allowed. descriptor_pool: A DescriptorPool used to resolve Any types. allow_unknown_field: if True, skip over unknown field and keep parsing. Avoid to use this option if possible. It may hide some errors (e.g. spelling error on field name) Returns: The same message passed as argument. Raises: ParseError: On text parsing problems.
Definition at line 693 of file text_format.py.
def google.protobuf.text_format.PrintField | ( | field, | |
value, | |||
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 , |
|||
message_formatter = None , |
|||
print_unknown_fields = False |
|||
) |
Print a single field name/value pair.
Definition at line 233 of file text_format.py.
def google.protobuf.text_format.PrintFieldValue | ( | field, | |
value, | |||
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 , |
|||
message_formatter = None , |
|||
print_unknown_fields = False |
|||
) |
Print a single field value (not including name).
Definition at line 255 of file text_format.py.
def google.protobuf.text_format.PrintMessage | ( | message, | |
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 |
|||
) |
Definition at line 204 of file text_format.py.
|
private |
Definition at line 59 of file text_format.py.
|
private |
Definition at line 43 of file text_format.py.
|
private |
Definition at line 69 of file text_format.py.
|
private |
Definition at line 66 of file text_format.py.
|
private |
Definition at line 67 of file text_format.py.
|
private |
Definition at line 62 of file text_format.py.
|
private |
Definition at line 68 of file text_format.py.
|
private |
Definition at line 1522 of file text_format.py.
google.protobuf.text_format.long = int |
Definition at line 51 of file text_format.py.
int google.protobuf.text_format.WIRETYPE_LENGTH_DELIMITED = 2 |
Definition at line 303 of file text_format.py.
int google.protobuf.text_format.WIRETYPE_START_GROUP = 3 |
Definition at line 304 of file text_format.py.