当前位置: 首页>>代码示例>>Python>>正文


Python text_format.ParseError方法代码示例

本文整理汇总了Python中google.protobuf.text_format.ParseError方法的典型用法代码示例。如果您正苦于以下问题:Python text_format.ParseError方法的具体用法?Python text_format.ParseError怎么用?Python text_format.ParseError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.protobuf.text_format的用法示例。


在下文中一共展示了text_format.ParseError方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_labelmap

# 需要导入模块: from google.protobuf import text_format [as 别名]
# 或者: from google.protobuf.text_format import ParseError [as 别名]
def load_labelmap(path):
  """Loads label map proto.

  Args:
    path: path to StringIntLabelMap proto text file.
  Returns:
    a StringIntLabelMapProto
  """
  with tf.gfile.GFile(path, 'r') as fid:
    label_map_string = fid.read()
    label_map = string_int_label_map_pb2.StringIntLabelMap()
    try:
      text_format.Merge(label_map_string, label_map)
    except text_format.ParseError:
      label_map.ParseFromString(label_map_string)
  _validate_label_map(label_map)
  return label_map 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:19,代码来源:label_map_util.py

示例2: load_labelmap

# 需要导入模块: from google.protobuf import text_format [as 别名]
# 或者: from google.protobuf.text_format import ParseError [as 别名]
def load_labelmap(path):
  """Loads label map proto.

  Args:
    path: path to StringIntLabelMap proto text file.
  Returns:
    a StringIntLabelMapProto
  """
  with tf.gfile.GFile(path, 'r') as fid:
    label_map_string = fid.read()
    label_map = string_int_label_map_pb2.StringIntLabelMap()
    try:
      text_format.Merge(label_map_string, label_map)
    except text_format.ParseError:
      label_map.ParseFromString(label_map_string)
  return label_map 
开发者ID:datitran,项目名称:object_detector_app,代码行数:18,代码来源:label_map_util.py

示例3: ParseCheckpoint

# 需要导入模块: from google.protobuf import text_format [as 别名]
# 或者: from google.protobuf.text_format import ParseError [as 别名]
def ParseCheckpoint(checkpoint):
  """Parse a checkpoint file.

  Args:
    checkpoint: Path to checkpoint. The checkpoint is either a serialized
      CheckpointState proto or an actual checkpoint file.

  Returns:
    The path to an actual checkpoint file.
  """
  warnings.warn(
      "ParseCheckpoint is deprecated. "
      "Will be removed in DeepChem 1.4.", DeprecationWarning)
  with open(checkpoint) as f:
    try:
      cp = checkpoint_state_pb2.CheckpointState()
      text_format.Merge(f.read(), cp)
      return cp.model_checkpoint_path
    except text_format.ParseError:
      return checkpoint 
开发者ID:deepchem,项目名称:deepchem,代码行数:22,代码来源:utils.py

示例4: load_labelmap

# 需要导入模块: from google.protobuf import text_format [as 别名]
# 或者: from google.protobuf.text_format import ParseError [as 别名]
def load_labelmap(path):
    """Loads label map proto.

    Args:
      path: path to StringIntLabelMap proto text file.
    Returns:
      a StringIntLabelMapProto
    """
    with tf.gfile.GFile(path, 'r') as fid:
        label_map_string = fid.read()
        label_map = string_int_label_map_pb2.StringIntLabelMap()
        try:
            text_format.Merge(label_map_string, label_map)
        except text_format.ParseError:
            label_map.ParseFromString(label_map_string)
    _validate_label_map(label_map)
    return label_map 
开发者ID:akshaybahadur21,项目名称:Emojinator,代码行数:19,代码来源:label_map_util.py

示例5: get_proto

# 需要导入模块: from google.protobuf import text_format [as 别名]
# 或者: from google.protobuf.text_format import ParseError [as 别名]
def get_proto(push_list, output_dir):
    bench_factory = aibench_pb2.BenchFactory()
    model_factory = aibench_pb2.ModelFactory()
    try:
        with open("aibench/proto/benchmark.meta", "rb") as fin:
            file_content = fin.read()
            text_format.Parse(file_content, bench_factory)
            filepath = output_dir + "/benchmark.pb"
            with open(filepath, "wb") as fout:
                fout.write(bench_factory.SerializeToString())
                push_list.append(filepath)
        with open("aibench/proto/model.meta", "rb") as fin:
            file_content = fin.read()
            text_format.Parse(file_content, model_factory)
            filepath = output_dir + "/model.pb"
            with open(filepath, "wb") as fout:
                fout.write(model_factory.SerializeToString())
                push_list.append(filepath)
    except text_format.ParseError as e:
        raise IOError("Cannot parse file.", e)

    return bench_factory, model_factory 
开发者ID:XiaoMi,项目名称:mobile-ai-bench,代码行数:24,代码来源:bench_engine.py

示例6: testConsumeByteString

# 需要导入模块: from google.protobuf import text_format [as 别名]
# 或者: from google.protobuf.text_format import ParseError [as 别名]
def testConsumeByteString(self):
    text = '"string1\''
    tokenizer = text_format.Tokenizer(text.splitlines())
    self.assertRaises(text_format.ParseError, tokenizer.ConsumeByteString)

    text = 'string1"'
    tokenizer = text_format.Tokenizer(text.splitlines())
    self.assertRaises(text_format.ParseError, tokenizer.ConsumeByteString)

    text = '\n"\\xt"'
    tokenizer = text_format.Tokenizer(text.splitlines())
    self.assertRaises(text_format.ParseError, tokenizer.ConsumeByteString)

    text = '\n"\\"'
    tokenizer = text_format.Tokenizer(text.splitlines())
    self.assertRaises(text_format.ParseError, tokenizer.ConsumeByteString)

    text = '\n"\\x"'
    tokenizer = text_format.Tokenizer(text.splitlines())
    self.assertRaises(text_format.ParseError, tokenizer.ConsumeByteString) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:22,代码来源:text_format_test.py

示例7: testParseBadEnumValue

# 需要导入模块: from google.protobuf import text_format [as 别名]
# 或者: from google.protobuf.text_format import ParseError [as 别名]
def testParseBadEnumValue(self, message_module):
    message = message_module.TestAllTypes()
    text = 'optional_nested_enum: BARR'
    six.assertRaisesRegex(self, 
        text_format.ParseError,
        (r'1:23 : Enum type "\w+.TestAllTypes.NestedEnum" '
         r'has no value named BARR.'),
        text_format.Parse, text, message)

    message = message_module.TestAllTypes()
    text = 'optional_nested_enum: 100'
    six.assertRaisesRegex(self, 
        text_format.ParseError,
        (r'1:23 : Enum type "\w+.TestAllTypes.NestedEnum" '
         r'has no value with number 100.'),
        text_format.Parse, text, message) 
开发者ID:sklearn-theano,项目名称:sklearn-theano,代码行数:18,代码来源:text_format_test.py

示例8: testParseInvalidUtf8

# 需要导入模块: from google.protobuf import text_format [as 别名]
# 或者: from google.protobuf.text_format import ParseError [as 别名]
def testParseInvalidUtf8(self, message_module):
    message = message_module.TestAllTypes()
    text = 'repeated_string: "\\xc3\\xc3"'
    with self.assertRaises(text_format.ParseError) as e:
      text_format.Parse(text, message)
    self.assertEqual(e.exception.GetLine(), 1)
    self.assertEqual(e.exception.GetColumn(), 28) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:9,代码来源:text_format_test.py

示例9: testParseSingleWord

# 需要导入模块: from google.protobuf import text_format [as 别名]
# 或者: from google.protobuf.text_format import ParseError [as 别名]
def testParseSingleWord(self, message_module):
    message = message_module.TestAllTypes()
    text = 'foo'
    six.assertRaisesRegex(self, text_format.ParseError, (
        r'1:1 : Message type "\w+.TestAllTypes" has no field named '
        r'"foo".'), text_format.Parse, text, message) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:8,代码来源:text_format_test.py

示例10: testParseUnknownField

# 需要导入模块: from google.protobuf import text_format [as 别名]
# 或者: from google.protobuf.text_format import ParseError [as 别名]
def testParseUnknownField(self, message_module):
    message = message_module.TestAllTypes()
    text = 'unknown_field: 8\n'
    six.assertRaisesRegex(self, text_format.ParseError, (
        r'1:1 : Message type "\w+.TestAllTypes" has no field named '
        r'"unknown_field".'), text_format.Parse, text, message) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:8,代码来源:text_format_test.py


注:本文中的google.protobuf.text_format.ParseError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。