本文整理汇总了Python中pants.backend.codegen.tasks.protobuf_parse.ProtobufParse.parse方法的典型用法代码示例。如果您正苦于以下问题:Python ProtobufParse.parse方法的具体用法?Python ProtobufParse.parse怎么用?Python ProtobufParse.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pants.backend.codegen.tasks.protobuf_parse.ProtobufParse
的用法示例。
在下文中一共展示了ProtobufParse.parse方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_crazy_whitespace
# 需要导入模块: from pants.backend.codegen.tasks.protobuf_parse import ProtobufParse [as 别名]
# 或者: from pants.backend.codegen.tasks.protobuf_parse.ProtobufParse import parse [as 别名]
def test_crazy_whitespace(self):
with temporary_dir() as workdir:
filename = 'crazy_whitespace.proto'
with open(os.path.join(workdir, filename), 'w') as fd:
fd.write(dedent('''
package
org.pantsbuild.protos; option
java_multiple_files
= true; option java_package =
"com.example.foo.bar"; message
Foo
{
enum
Bar {
BAZ = 0; } } message
FooBar
{ }
'''))
fd.close()
proto_parse = ProtobufParse(fd.name, filename)
proto_parse.parse()
self.assertEqual('com.example.foo.bar', proto_parse.package)
self.assertEqual(set(['Bar']), proto_parse.enums)
self.assertEqual(set(['Foo', 'FooBar']), proto_parse.messages)
self.assertEqual(set(), proto_parse.services)
self.assertEqual('CrazyWhitespace', proto_parse.outer_class_name)
示例2: calculate_genfiles
# 需要导入模块: from pants.backend.codegen.tasks.protobuf_parse import ProtobufParse [as 别名]
# 或者: from pants.backend.codegen.tasks.protobuf_parse.ProtobufParse import parse [as 别名]
def calculate_genfiles(self, path, source):
protobuf_parse = ProtobufParse(path, source)
protobuf_parse.parse()
genfiles = defaultdict(set)
genfiles['py'].update(self.calculate_python_genfiles(source))
genfiles['java'].update(self.calculate_java_genfiles(protobuf_parse))
return genfiles
示例3: calculate_genfiles
# 需要导入模块: from pants.backend.codegen.tasks.protobuf_parse import ProtobufParse [as 别名]
# 或者: from pants.backend.codegen.tasks.protobuf_parse.ProtobufParse import parse [as 别名]
def calculate_genfiles(path, source, service_prefixes):
protobuf_parse = ProtobufParse(path, source)
protobuf_parse.parse()
genfiles = defaultdict(set)
genfiles['py'].update(calculate_python_genfiles(source))
genfiles['java'].update(calculate_java_genfiles(protobuf_parse, service_prefixes))
return genfiles
示例4: test_no_newline_at_all3
# 需要导入模块: from pants.backend.codegen.tasks.protobuf_parse import ProtobufParse [as 别名]
# 或者: from pants.backend.codegen.tasks.protobuf_parse.ProtobufParse import parse [as 别名]
def test_no_newline_at_all3(self):
with temporary_dir() as workdir:
filename = 'no_newline_at_all3.proto'
with open(os.path.join(workdir, filename), 'w') as fd:
fd.write('package org.pantsbuild.protos; option java_package = "com.example.foo.bar"; message Foo { }')
fd.close()
proto_parse = ProtobufParse(fd.name, filename)
proto_parse.parse()
self.assertEqual('com.example.foo.bar', proto_parse.package)
self.assertEqual(set(), proto_parse.enums)
self.assertEqual(set(['Foo', ]), proto_parse.messages)
self.assertEqual(set(), proto_parse.services)
self.assertEqual('NoNewlineAtAll3', proto_parse.outer_class_name)
示例5: test_no_newline_at_all2
# 需要导入模块: from pants.backend.codegen.tasks.protobuf_parse import ProtobufParse [as 别名]
# 或者: from pants.backend.codegen.tasks.protobuf_parse.ProtobufParse import parse [as 别名]
def test_no_newline_at_all2(self):
with temporary_dir() as workdir:
filename = 'no_newline_at_all2.proto'
with open(os.path.join(workdir, filename), 'w') as fd:
fd.write('package org.pantsbuild.protos; message Foo {'
+ 'enum Bar { BAZ = 0; } } message FooBar { }')
fd.close()
proto_parse = ProtobufParse(fd.name, filename)
proto_parse.parse()
self.assertEqual('org.pantsbuild.protos', proto_parse.package)
self.assertEqual(set(['Bar']), proto_parse.enums)
self.assertEqual(set(['Foo', 'FooBar']), proto_parse.messages)
self.assertEqual(set(), proto_parse.services)
self.assertEqual('NoNewlineAtAll2', proto_parse.outer_class_name)
示例6: test_extend
# 需要导入模块: from pants.backend.codegen.tasks.protobuf_parse import ProtobufParse [as 别名]
# 或者: from pants.backend.codegen.tasks.protobuf_parse.ProtobufParse import parse [as 别名]
def test_extend(self):
with temporary_dir() as workdir:
filename = 'testextend.proto'
with open(os.path.join(workdir, filename), 'w') as fd:
fd.write(dedent('''
package org.pantsbuild.protos;
extend Foo {
optional int32 bar = 126;
}
'''))
fd.close()
proto_parse = ProtobufParse(fd.name, filename)
proto_parse.parse()
self.assertEqual(set(['Foo']), proto_parse.extends)
示例7: calculate_genfiles
# 需要导入模块: from pants.backend.codegen.tasks.protobuf_parse import ProtobufParse [as 别名]
# 或者: from pants.backend.codegen.tasks.protobuf_parse.ProtobufParse import parse [as 别名]
def calculate_genfiles(self, path, source, service_writer):
protobuf_parse = ProtobufParse(path, source)
protobuf_parse.parse()
types = protobuf_parse.messages | protobuf_parse.enums
if service_writer:
types |= protobuf_parse.services
# Wire generates a single type for all of the 'extends' declarations in this file.
if protobuf_parse.extends:
types |= {"Ext_{0}".format(protobuf_parse.filename)}
java_files = self.calculate_java_genfiles(protobuf_parse.package, types)
logger.debug('Path {path} yielded types {types} got files {java_files}'
.format(path=path, types=types, java_files=java_files))
return set(java_files)
示例8: test_inner_class_no_newline
# 需要导入模块: from pants.backend.codegen.tasks.protobuf_parse import ProtobufParse [as 别名]
# 或者: from pants.backend.codegen.tasks.protobuf_parse.ProtobufParse import parse [as 别名]
def test_inner_class_no_newline(self):
with temporary_dir() as workdir:
filename = 'inner_class_no_newline.proto'
with open(os.path.join(workdir, filename), 'w') as fd:
fd.write(dedent('''
package org.pantsbuild.protos;
option java_multiple_files = true;
message Foo {
enum Bar { BAZ = 0; }
}
'''))
fd.close()
proto_parse = ProtobufParse(fd.name, filename)
proto_parse.parse()
self.assertEqual('org.pantsbuild.protos', proto_parse.package)
self.assertEqual(set(['Bar']), proto_parse.enums)
self.assertEqual(set(['Foo']), proto_parse.messages)
self.assertEqual(set(), proto_parse.services)
self.assertEqual('InnerClassNoNewline', proto_parse.outer_class_name)
示例9: test_parse_for
# 需要导入模块: from pants.backend.codegen.tasks.protobuf_parse import ProtobufParse [as 别名]
# 或者: from pants.backend.codegen.tasks.protobuf_parse.ProtobufParse import parse [as 别名]
def test_parse_for(self):
with temporary_dir() as workdir:
filename = 'temperatures.proto'
with open(os.path.join(workdir, filename), 'w') as fd:
fd.write(dedent('''
package org.pantsbuild.example.temperature;
message Temperature {
optional string unit = 1;
required int64 number = 2;
}
'''))
fd.close()
proto_parser = ProtobufParse(fd.name, filename)
proto_parser.parse()
self.assertEqual('org.pantsbuild.example.temperature', proto_parser.package)
self.assertEqual(set(), proto_parser.enums)
self.assertEqual(set(['Temperature']), proto_parser.messages)
self.assertEqual(set(), proto_parser.services)
self.assertEqual('Temperatures', proto_parser.outer_class_name)
示例10: test_whitespace
# 需要导入模块: from pants.backend.codegen.tasks.protobuf_parse import ProtobufParse [as 别名]
# 或者: from pants.backend.codegen.tasks.protobuf_parse.ProtobufParse import parse [as 别名]
def test_whitespace(self):
with temporary_dir() as workdir:
filename = 'jack_spratt_no_whitespace.proto'
with open(os.path.join(workdir, filename), 'w') as fd:
fd.write(
'''
package com.twitter.lean;
option java_multiple_files = true;
enum Jake { FOO=1;}
message joe_bob {}
'''
)
fd.close()
proto_parse_no_whitespace = ProtobufParse(fd.name, filename)
proto_parse_no_whitespace.parse()
self.assertEqual('com.twitter.lean', proto_parse_no_whitespace.package)
self.assertEqual(set(['Jake']), proto_parse_no_whitespace.enums)
self.assertEqual(set(['joe_bob']), proto_parse_no_whitespace.messages)
self.assertEqual(set(), proto_parse_no_whitespace.services)
self.assertEqual('JackSprattNoWhitespace', proto_parse_no_whitespace.outer_class_name)
filename = 'jack_spratt.proto'
with open(os.path.join(workdir, filename), 'w') as fd:
fd.write(
'''
package com.twitter.lean;
option java_multiple_files = true;
enum Jake { FOO=1;
}
message joe_bob {
}
'''
)
fd.close()
proto_parse_with_whitespace = ProtobufParse(fd.name, filename)
proto_parse_with_whitespace.parse()
self.assertEqual('com.twitter.lean', proto_parse_with_whitespace.package)
self.assertEqual(set(['Jake']), proto_parse_with_whitespace.enums)
self.assertEqual(set(['joe_bob']), proto_parse_with_whitespace.messages)
self.assertEqual('JackSpratt',proto_parse_with_whitespace.outer_class_name)
示例11: calculate_genfiles
# 需要导入模块: from pants.backend.codegen.tasks.protobuf_parse import ProtobufParse [as 别名]
# 或者: from pants.backend.codegen.tasks.protobuf_parse.ProtobufParse import parse [as 别名]
def calculate_genfiles(self, path, source):
protobuf_parse = ProtobufParse(path, source)
protobuf_parse.parse()
return OrderedSet(self.calculate_java_genfiles(protobuf_parse))