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


Python ProtobufParse.parse方法代码示例

本文整理汇总了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)
开发者ID:alanpaulin,项目名称:pants,代码行数:28,代码来源:test_protobuf_parse.py

示例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
开发者ID:MathewJennings,项目名称:pants,代码行数:10,代码来源:protobuf_gen.py

示例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
开发者ID:arloherrine,项目名称:pants,代码行数:10,代码来源:protobuf_gen.py

示例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)
开发者ID:alanpaulin,项目名称:pants,代码行数:15,代码来源:test_protobuf_parse.py

示例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)
开发者ID:alanpaulin,项目名称:pants,代码行数:16,代码来源:test_protobuf_parse.py

示例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)
开发者ID:alanpaulin,项目名称:pants,代码行数:16,代码来源:test_protobuf_parse.py

示例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)
开发者ID:priyakoth,项目名称:pants,代码行数:18,代码来源:wire_gen.py

示例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)
开发者ID:alanpaulin,项目名称:pants,代码行数:21,代码来源:test_protobuf_parse.py

示例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)
开发者ID:alanpaulin,项目名称:pants,代码行数:22,代码来源:test_protobuf_parse.py

示例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)
开发者ID:amedina,项目名称:pants,代码行数:43,代码来源:test_protobuf_parse.py

示例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))
开发者ID:lcary,项目名称:pants,代码行数:6,代码来源:protobuf_gen.py


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