本文整理汇总了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
示例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
示例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
示例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
示例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
示例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)
示例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)
示例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)
示例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)
示例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)