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


Python protobuf_parse.ProtobufParse类代码示例

本文整理汇总了Python中pants.backend.codegen.tasks.protobuf_parse.ProtobufParse的典型用法代码示例。如果您正苦于以下问题:Python ProtobufParse类的具体用法?Python ProtobufParse怎么用?Python ProtobufParse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_crazy_whitespace

 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,代码行数:26,代码来源:test_protobuf_parse.py

示例2: calculate_genfiles

  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,代码行数:8,代码来源:protobuf_gen.py

示例3: calculate_genfiles

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,代码行数:8,代码来源:protobuf_gen.py

示例4: test_no_newline_at_all3

 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,代码行数:13,代码来源:test_protobuf_parse.py

示例5: test_no_newline_at_all2

 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,代码行数:14,代码来源:test_protobuf_parse.py

示例6: test_extend

 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,代码行数:14,代码来源:test_protobuf_parse.py

示例7: calculate_genfiles

  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,代码行数:16,代码来源:wire_gen.py

示例8: test_update_type_list

  def test_update_type_list(self):
    match = ProtobufParse._message_parser_re().match('message Temperature {')

    expected_value = set()
    expected_value.add('Temperature')
    actual_value = set()
    update_type_list(match, 0, actual_value)
    self.assertEqual(expected_value, actual_value)
开发者ID:alanpaulin,项目名称:pants,代码行数:8,代码来源:test_protobuf_parse.py

示例9: test_inner_class_no_newline

 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,代码行数:19,代码来源:test_protobuf_parse.py

示例10: test_parse_for

  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,代码行数:20,代码来源:test_protobuf_parse.py

示例11: test_whitespace

  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,代码行数:41,代码来源:test_protobuf_parse.py

示例12: calculate_genfiles

 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,代码行数:4,代码来源:protobuf_gen.py


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