當前位置: 首頁>>代碼示例>>Python>>正文


Python text_format.MessageToString方法代碼示例

本文整理匯總了Python中google.protobuf.text_format.MessageToString方法的典型用法代碼示例。如果您正苦於以下問題:Python text_format.MessageToString方法的具體用法?Python text_format.MessageToString怎麽用?Python text_format.MessageToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在google.protobuf.text_format的用法示例。


在下文中一共展示了text_format.MessageToString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: RunSteps

# 需要導入模塊: from google.protobuf import text_format [as 別名]
# 或者: from google.protobuf.text_format import MessageToString [as 別名]
def RunSteps(api):
  text = text_format.MessageToString(api.buildbucket.build)
  api.step('build', ['echo'] + text.splitlines())
  api.step('hostname', ['echo', api.buildbucket.host])
  api.step('is_critical', ['echo', api.buildbucket.is_critical()])

  child_build_tags = [
      '%s:%s' % t
      for t in api.buildbucket.tags_for_child_build.iteritems()
  ]
  api.step('tags_for_child_build', ['echo'] + child_build_tags)

  api.assertions.assertEqual(
      api.buildbucket.bucket_v1,
      api.properties.get('expected_bucket_v1'))
  api.assertions.assertEqual(
      api.buildbucket.builder_name,
      api.buildbucket.build.builder.builder)
  api.assertions.assertEqual(
      api.buildbucket.gitiles_commit,
      api.buildbucket.build.input.gitiles_commit) 
開發者ID:luci,項目名稱:recipes-py,代碼行數:23,代碼來源:build.py

示例2: main

# 需要導入模塊: from google.protobuf import text_format [as 別名]
# 或者: from google.protobuf.text_format import MessageToString [as 別名]
def main(argv):
  if len(argv) != 2:
    sys.exit('One argument, a directory containing a font family')
  fontdir = argv[1]

  is_new = True
  old_metadata_file = os.path.join(fontdir, 'METADATA.pb')
  if os.path.isfile(old_metadata_file):
    is_new = False

  metadata = _MakeMetadata(fontdir, is_new)
  text_proto = text_format.MessageToString(metadata, as_utf8=True)

  desc = os.path.join(fontdir, 'DESCRIPTION.en_us.html')
  if os.path.isfile(desc):
    print('DESCRIPTION.en_us.html exists')
  else:
    _WriteTextFile(desc, 'N/A')

  _WriteTextFile(os.path.join(fontdir, 'METADATA.pb'), text_proto) 
開發者ID:googlefonts,項目名稱:gftools,代碼行數:22,代碼來源:gftools-add-font.py

示例3: save_pipeline_config

# 需要導入模塊: from google.protobuf import text_format [as 別名]
# 或者: from google.protobuf.text_format import MessageToString [as 別名]
def save_pipeline_config(pipeline_config, directory):
  """Saves a pipeline config text file to disk.

  Args:
    pipeline_config: A pipeline_pb2.TrainEvalPipelineConfig.
    directory: The model directory into which the pipeline config file will be
      saved.
  """
  if not file_io.file_exists(directory):
    file_io.recursive_create_dir(directory)
  pipeline_config_path = os.path.join(directory, "pipeline.config")
  config_text = text_format.MessageToString(pipeline_config)
  with tf.gfile.Open(pipeline_config_path, "wb") as f:
    tf.logging.info("Writing pipeline config file to %s",
                    pipeline_config_path)
    f.write(config_text) 
開發者ID:ahmetozlu,項目名稱:vehicle_counting_tensorflow,代碼行數:18,代碼來源:config_util.py

示例4: testPrintExotic

# 需要導入模塊: from google.protobuf import text_format [as 別名]
# 或者: from google.protobuf.text_format import MessageToString [as 別名]
def testPrintExotic(self, message_module):
    message = message_module.TestAllTypes()
    message.repeated_int64.append(-9223372036854775808)
    message.repeated_uint64.append(18446744073709551615)
    message.repeated_double.append(123.456)
    message.repeated_double.append(1.23e22)
    message.repeated_double.append(1.23e-18)
    message.repeated_string.append('\000\001\a\b\f\n\r\t\v\\\'"')
    message.repeated_string.append('\u00fc\ua71f')
    self.CompareToGoldenText(
        self.RemoveRedundantZeros(text_format.MessageToString(message)),
        'repeated_int64: -9223372036854775808\n'
        'repeated_uint64: 18446744073709551615\n'
        'repeated_double: 123.456\n'
        'repeated_double: 1.23e+22\n'
        'repeated_double: 1.23e-18\n'
        'repeated_string:'
        ' "\\000\\001\\007\\010\\014\\n\\r\\t\\013\\\\\\\'\\""\n'
        'repeated_string: "\\303\\274\\352\\234\\237"\n') 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:21,代碼來源:text_format_test.py

示例5: testPrintExoticAsOneLine

# 需要導入模塊: from google.protobuf import text_format [as 別名]
# 或者: from google.protobuf.text_format import MessageToString [as 別名]
def testPrintExoticAsOneLine(self, message_module):
    message = message_module.TestAllTypes()
    message.repeated_int64.append(-9223372036854775808)
    message.repeated_uint64.append(18446744073709551615)
    message.repeated_double.append(123.456)
    message.repeated_double.append(1.23e22)
    message.repeated_double.append(1.23e-18)
    message.repeated_string.append('\000\001\a\b\f\n\r\t\v\\\'"')
    message.repeated_string.append('\u00fc\ua71f')
    self.CompareToGoldenText(
        self.RemoveRedundantZeros(text_format.MessageToString(
            message, as_one_line=True)),
        'repeated_int64: -9223372036854775808'
        ' repeated_uint64: 18446744073709551615'
        ' repeated_double: 123.456'
        ' repeated_double: 1.23e+22'
        ' repeated_double: 1.23e-18'
        ' repeated_string: '
        '"\\000\\001\\007\\010\\014\\n\\r\\t\\013\\\\\\\'\\""'
        ' repeated_string: "\\303\\274\\352\\234\\237"') 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:22,代碼來源:text_format_test.py

示例6: testPrintMessageSet

# 需要導入模塊: from google.protobuf import text_format [as 別名]
# 或者: from google.protobuf.text_format import MessageToString [as 別名]
def testPrintMessageSet(self):
    message = unittest_mset_pb2.TestMessageSetContainer()
    ext1 = unittest_mset_pb2.TestMessageSetExtension1.message_set_extension
    ext2 = unittest_mset_pb2.TestMessageSetExtension2.message_set_extension
    message.message_set.Extensions[ext1].i = 23
    message.message_set.Extensions[ext2].str = 'foo'
    self.CompareToGoldenText(
        text_format.MessageToString(message), 'message_set {\n'
        '  [protobuf_unittest.TestMessageSetExtension1] {\n'
        '    i: 23\n'
        '  }\n'
        '  [protobuf_unittest.TestMessageSetExtension2] {\n'
        '    str: \"foo\"\n'
        '  }\n'
        '}\n')

    message = message_set_extensions_pb2.TestMessageSet()
    ext = message_set_extensions_pb2.message_set_extension3
    message.Extensions[ext].text = 'bar'
    self.CompareToGoldenText(
        text_format.MessageToString(message),
        '[google.protobuf.internal.TestMessageSetExtension3] {\n'
        '  text: \"bar\"\n'
        '}\n') 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:26,代碼來源:text_format_test.py

示例7: testPrintMessageSetAsOneLine

# 需要導入模塊: from google.protobuf import text_format [as 別名]
# 或者: from google.protobuf.text_format import MessageToString [as 別名]
def testPrintMessageSetAsOneLine(self):
    message = unittest_mset_pb2.TestMessageSetContainer()
    ext1 = unittest_mset_pb2.TestMessageSetExtension1.message_set_extension
    ext2 = unittest_mset_pb2.TestMessageSetExtension2.message_set_extension
    message.message_set.Extensions[ext1].i = 23
    message.message_set.Extensions[ext2].str = 'foo'
    self.CompareToGoldenText(
        text_format.MessageToString(message, as_one_line=True),
        'message_set {'
        ' [protobuf_unittest.TestMessageSetExtension1] {'
        ' i: 23'
        ' }'
        ' [protobuf_unittest.TestMessageSetExtension2] {'
        ' str: \"foo\"'
        ' }'
        ' }') 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:18,代碼來源:text_format_test.py

示例8: testPrintMessageExpandAnyRepeated

# 需要導入模塊: from google.protobuf import text_format [as 別名]
# 或者: from google.protobuf.text_format import MessageToString [as 別名]
def testPrintMessageExpandAnyRepeated(self):
    packed_message = unittest_pb2.OneString()
    message = any_test_pb2.TestAny()
    packed_message.data = 'string0'
    message.repeated_any_value.add().Pack(packed_message)
    packed_message.data = 'string1'
    message.repeated_any_value.add().Pack(packed_message)
    self.assertEqual(
        text_format.MessageToString(message),
        'repeated_any_value {\n'
        '  [type.googleapis.com/protobuf_unittest.OneString] {\n'
        '    data: "string0"\n'
        '  }\n'
        '}\n'
        'repeated_any_value {\n'
        '  [type.googleapis.com/protobuf_unittest.OneString] {\n'
        '    data: "string1"\n'
        '  }\n'
        '}\n') 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:21,代碼來源:text_format_test.py

示例9: testPrettyPrintMultiLine

# 需要導入模塊: from google.protobuf import text_format [as 別名]
# 或者: from google.protobuf.text_format import MessageToString [as 別名]
def testPrettyPrintMultiLine(self, message_module):

    def printer(m, indent, as_one_line):
      if m.DESCRIPTOR == message_module.TestAllTypes.NestedMessage.DESCRIPTOR:
        line_deliminator = (' ' if as_one_line else '\n') + ' ' * indent
        return 'My lucky number is:%s%s' % (line_deliminator, m.bb)
      return None

    message = message_module.TestAllTypes()
    msg = message.repeated_nested_message.add()
    msg.bb = 42
    self.CompareToGoldenText(
        text_format.MessageToString(
            message, as_one_line=True, message_formatter=printer),
        'repeated_nested_message { My lucky number is: 42 }')
    self.CompareToGoldenText(
        text_format.MessageToString(
            message, as_one_line=False, message_formatter=printer),
        'repeated_nested_message {\n  My lucky number is:\n  42\n}\n') 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:21,代碼來源:text_format_test.py

示例10: testPrettyPrintMultipleParts

# 需要導入模塊: from google.protobuf import text_format [as 別名]
# 或者: from google.protobuf.text_format import MessageToString [as 別名]
def testPrettyPrintMultipleParts(self, message_module):

    def printer(m, indent, as_one_line):
      del indent, as_one_line
      if m.DESCRIPTOR == message_module.TestAllTypes.NestedMessage.DESCRIPTOR:
        return 'My lucky number is %s' % m.bb
      return None

    message = message_module.TestAllTypes()
    message.optional_int32 = 61
    msg = message.repeated_nested_message.add()
    msg.bb = 42
    msg = message.repeated_nested_message.add()
    msg.bb = 99
    msg = message.optional_nested_message
    msg.bb = 1
    self.CompareToGoldenText(
        text_format.MessageToString(
            message, as_one_line=True, message_formatter=printer),
        ('optional_int32: 61 '
         'optional_nested_message { My lucky number is 1 } '
         'repeated_nested_message { My lucky number is 42 } '
         'repeated_nested_message { My lucky number is 99 }')) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:25,代碼來源:text_format_test.py

示例11: visualize_embeddings

# 需要導入模塊: from google.protobuf import text_format [as 別名]
# 或者: from google.protobuf.text_format import MessageToString [as 別名]
def visualize_embeddings(summary_writer, config):
  """Stores a config file used by the embedding projector.

  Args:
    summary_writer: The summary writer used for writting events.
    config: `tf.contrib.tensorboard.plugins.projector.ProjectorConfig`
      proto that holds the configuration for the projector such as paths to
      checkpoint files and metadata files for the embeddings. If
      `config.model_checkpoint_path` is none, it defaults to the
      `logdir` used by the summary_writer.

  Raises:
    ValueError: If the summary writer does not have a `logdir`.
  """
  logdir = summary_writer.get_logdir()

  # Sanity checks.
  if logdir is None:
    raise ValueError('Summary writer must have a logdir')

  # Saving the config file in the logdir.
  config_pbtxt = text_format.MessageToString(config)
  file_io.write_string_to_file(
      os.path.join(logdir, projector_plugin.PROJECTOR_FILENAME), config_pbtxt) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:26,代碼來源:__init__.py

示例12: testPrintExotic

# 需要導入模塊: from google.protobuf import text_format [as 別名]
# 或者: from google.protobuf.text_format import MessageToString [as 別名]
def testPrintExotic(self, message_module):
    message = message_module.TestAllTypes()
    message.repeated_int64.append(-9223372036854775808)
    message.repeated_uint64.append(18446744073709551615)
    message.repeated_double.append(123.456)
    message.repeated_double.append(1.23e22)
    message.repeated_double.append(1.23e-18)
    message.repeated_string.append('\000\001\a\b\f\n\r\t\v\\\'"')
    message.repeated_string.append(u'\u00fc\ua71f')
    self.CompareToGoldenText(
        self.RemoveRedundantZeros(text_format.MessageToString(message)),
        'repeated_int64: -9223372036854775808\n'
        'repeated_uint64: 18446744073709551615\n'
        'repeated_double: 123.456\n'
        'repeated_double: 1.23e+22\n'
        'repeated_double: 1.23e-18\n'
        'repeated_string:'
        ' "\\000\\001\\007\\010\\014\\n\\r\\t\\013\\\\\\\'\\""\n'
        'repeated_string: "\\303\\274\\352\\234\\237"\n') 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:21,代碼來源:text_format_test.py

示例13: testPrintExoticAsOneLine

# 需要導入模塊: from google.protobuf import text_format [as 別名]
# 或者: from google.protobuf.text_format import MessageToString [as 別名]
def testPrintExoticAsOneLine(self, message_module):
    message = message_module.TestAllTypes()
    message.repeated_int64.append(-9223372036854775808)
    message.repeated_uint64.append(18446744073709551615)
    message.repeated_double.append(123.456)
    message.repeated_double.append(1.23e22)
    message.repeated_double.append(1.23e-18)
    message.repeated_string.append('\000\001\a\b\f\n\r\t\v\\\'"')
    message.repeated_string.append(u'\u00fc\ua71f')
    self.CompareToGoldenText(
        self.RemoveRedundantZeros(text_format.MessageToString(
            message, as_one_line=True)),
        'repeated_int64: -9223372036854775808'
        ' repeated_uint64: 18446744073709551615'
        ' repeated_double: 123.456'
        ' repeated_double: 1.23e+22'
        ' repeated_double: 1.23e-18'
        ' repeated_string: '
        '"\\000\\001\\007\\010\\014\\n\\r\\t\\013\\\\\\\'\\""'
        ' repeated_string: "\\303\\274\\352\\234\\237"') 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:22,代碼來源:text_format_test.py

示例14: testPrintInIndexOrder

# 需要導入模塊: from google.protobuf import text_format [as 別名]
# 或者: from google.protobuf.text_format import MessageToString [as 別名]
def testPrintInIndexOrder(self):
    message = unittest_pb2.TestFieldOrderings()
    message.my_string = '115'
    message.my_int = 101
    message.my_float = 111
    message.optional_nested_message.oo = 0
    message.optional_nested_message.bb = 1
    self.CompareToGoldenText(
        self.RemoveRedundantZeros(text_format.MessageToString(
            message, use_index_order=True)),
        'my_string: \"115\"\nmy_int: 101\nmy_float: 111\n'
        'optional_nested_message {\n  oo: 0\n  bb: 1\n}\n')
    self.CompareToGoldenText(
        self.RemoveRedundantZeros(text_format.MessageToString(message)),
        'my_int: 101\nmy_string: \"115\"\nmy_float: 111\n'
        'optional_nested_message {\n  bb: 1\n  oo: 0\n}\n') 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:18,代碼來源:text_format_test.py

示例15: testMapOrderSemantics

# 需要導入模塊: from google.protobuf import text_format [as 別名]
# 或者: from google.protobuf.text_format import MessageToString [as 別名]
def testMapOrderSemantics(self):
    golden_lines = self.ReadGolden('map_test_data.txt')
    # The C++ implementation emits defaulted-value fields, while the Python
    # implementation does not.  Adjusting for this is awkward, but it is
    # valuable to test against a common golden file.
    line_blacklist = ('  key: 0\n', '  value: 0\n', '  key: false\n',
                      '  value: false\n')
    golden_lines = [line for line in golden_lines if line not in line_blacklist]

    message = map_unittest_pb2.TestMap()
    text_format.ParseLines(golden_lines, message)
    candidate = text_format.MessageToString(message)
    # The Python implementation emits "1.0" for the double value that the C++
    # implementation emits as "1".
    candidate = candidate.replace('1.0', '1', 2)
    self.assertMultiLineEqual(candidate, ''.join(golden_lines))


# Tests of proto2-only features (MessageSet, extensions, etc.). 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:21,代碼來源:text_format_test.py


注:本文中的google.protobuf.text_format.MessageToString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。