Lines Matching +full:python +full:- +full:is +full:- +full:python3

1 #!/usr/bin/env python3
2 # kate: replace-tabs on; indent-width 4;
7 nanopb_version = "nanopb-1.0.0-dev"
20 # Python-protobuf breaks easily with protoc version differences if
21 # using the cpp or upb implementation. Force it to use pure Python
22 # implementation. Performance is not very important in the generator.
24 os.putenv("PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION", "python")
25 os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
28 # Make sure grpc_tools gets included in binary package if it is available
42 *** Could not import the Google protobuf Python libraries ***
44 *** Easiest solution is often to install the dependencies via pip: ***
45 *** pip install protobuf grpcio-tools ***
50 # GetMessageClass() is used by modern python-protobuf (around 5.x onwards)
51 # Retain compatibility with older python-protobuf versions.
59 # Depending on how this script is run, we may or may not have PEP366 package name
83 # Don't care, we will error out later if it is actually important.
86 # ---------------------------------------------------------------------------
88 # ---------------------------------------------------------------------------
199 word = re.sub(r"([A-Z]+)([A-Z][a-z])", r'\1_\2', word)
200 word = re.sub(r"([a-z\d])([A-Z])", r'\1_\2', word)
201 word = word.replace("-", "_")
251 raise NotImplementedError("Lookup of non-absolute type names is not supported")
257 max_value = 2**64 - max_value
263 assert varint_max_size(-1) == 10
332 return 2**32 - 1
347 path is a tuple containing integers (type, index, ...)
348 comments is a dictionary mapping between element path & SourceCodeInfo.Location
369 member_path is the proto path of an element or member (ex. [5 0] or [4 1 2 0])
370 leading_indent is a flag that indicates if leading comments should be indented
397 desc is EnumDescriptorProto
398 index is the index of this enum element inside the file
399 comments is a dictionary mapping between element path & SourceCodeInfo.Location
408 base_name = Names(names.parts[:-1])
460 if index == enum_length - 1:
495 Globals.naming_style.enum_entry(sorted_values[-1][0]))
504 Globals.naming_style.enum_entry(sorted_values[-1][0]))
541 Globals.naming_style.enum_entry(strname.parts[-1]))
574 self.worst = max(i for i in worst if i is not None)
594 '''desc is FieldDescriptorProto'''
613 # Before nanopb-0.3.8, fixed length bytes arrays were specified
647 if self.max_count is None:
660 # "null" status. For nanopb, that is implemented as has_ field.
674 # i.e. whether the data size is known.
675 if desc.type == FieldD.TYPE_STRING and self.max_size is None:
678 if desc.type == FieldD.TYPE_BYTES and self.max_size is None:
689 raise Exception("Field '%s' is defined as static, but max_size or "
690 "max_count is not given." % self.name)
692 if field_options.fixed_count and self.max_count is None:
693 raise Exception("Field '%s' is defined as fixed count, "
694 "but max_count is not given." % self.name)
719 if self.default is not None:
728 # -1 because of null terminator. Both pb_encode and pb_decode
730 self.enc_size = varint_max_size(self.max_size) + self.max_size - 1
735 if self.max_size is None:
736 raise Exception("Field '%s' is defined as fixed length, "
737 "but max_size is not given." % self.name)
751 self.enc_size = None # Needs to be filled in after the message type is available
837 if self.initializer is not None:
844 elif self.default is None or null_init:
857 data = codecs.escape_encode(self.default.encode('utf-8'))[0]
920 elif self.initializer is not None:
935 return '#define %-40s %d\n' % (identifier, self.tag)
939 Format is: X(a, ATYPE, HTYPE, LTYPE, field_name, tag)
958 return '%s(%s, %-9s %-9s %-9s %-16s %3d)' % (self.macro_x_param,
968 This is used to try to automatically pick right descriptor size.
969 If the estimate is wrong, it will result in compile time error and
984 size = 256 # Message is in other file, this is reasonable guess for most cases
995 elif self.data_item_size is not None:
1011 size += alignment - (size % alignment)
1039 if encsize is not None:
1043 # The dependency is from the same file and size cannot be
1048 if encsize is None:
1050 # This can occur if submessage is defined in different
1068 elif self.enc_size is None:
1099 start. Not necessarily all tags above this are extensions, it is merely
1154 return '#define %-40s %d\n' % (identifier, self.tag)
1160 msg +=' type of extension fields is currently supported. */\n'
1185 # ---------------------------------------------------------------------------
1187 # ---------------------------------------------------------------------------
1264 if size is None or size.value is None:
1298 # ---------------------------------------------------------------------------
1300 # ---------------------------------------------------------------------------
1317 if desc is not None:
1322 # Automatically assign a per-message callback if any field has
1345 sys.stderr.write('Note: This Python protobuf library has no OneOf support\n')
1481 '''Return X-macro declaration of all fields in this message.'''
1629 if fsize is None:
1648 # The iteration is done in reverse order to avoid remove() messing up iteration.
1652 if parsed_field is None or parsed_field.allocation != 'STATIC':
1667 … + "Try passing all source files to generator at once, or use -I option.")
1673 defvals = [v for n,v in enumtype.values if n.parts[-1] == field.default_value]
1675 # If no default is specified, the default is the first value.
1713 # ---------------------------------------------------------------------------
1715 # ---------------------------------------------------------------------------
1749 '''Returns True if message has a recursive dependency on root (or itself if root is None).'''
1791 '''Make #ifndef identifier that contains uppercase A-Z and digits 0-9'''
1831 if self.replacement_prefix is not None:
1848 new_name = Names(names.parts[-1])
1863 …# The styled name is mangled and needs extra mapping from unmangled to mangled. We just need to fi…
1865 …# This is required because enum dependencies are looked up from the reverse_name_mapping using nam…
1882 Argument is a string.
1885 return "." + typename.split(".")[-1]
1891 if self.strip_prefix is not None and typename.startswith(self.strip_prefix):
1892 if self.replacement_prefix is not None:
1988 needed. Currently this applies to map< > types when the field is ignored by options.
2065 # no %s specified - use whatever was passed in as options.libformat
2127 yield '#define %-40s %s\n' % (identifier, msg.get_initializer(False))
2134 yield '#define %-40s %s\n' % (identifier, msg.get_initializer(True))
2156 … yield '/* Defines for backwards compatibility with code written before nanopb-0.4.0 */\n'
2170 # around it to prevent compilation errors if the symbol is not actually available.
2171 local_defines = [identifier for identifier, msize in messagesizes if msize is not None]
2179 if msize is not None:
2193 if msize is not None:
2197 guards[cpp_guard].add('#define %-40s %s' % (
2201 guards[cpp_guard].add('#define %-40s %s' % (
2227 m = "-1"
2229 if msize is not None:
2240 # Check if there is any name mangling active
2289 # Check if any messages exceed the 64 kB limit of 16-bit pb_size_t
2311 # Generate enum_name function if enum_to_string option is defined
2315 # Generate enum_valid function if enum_valid option is defined
2340 yield '/* On some platforms (such as AVR), double is really float.\n'
2352 # ---------------------------------------------------------------------------
2354 # ---------------------------------------------------------------------------
2431 # ---------------------------------------------------------------------------
2433 # ---------------------------------------------------------------------------
2442 epilog = "Compile file.pb from file.proto by: 'protoc -ofile.pb file.proto'. " +
2444 optparser.add_option("-V", "--version", dest="version", action="store_true",
2445 help="Show version info and exit (add -v for protoc version info)")
2446 optparser.add_option("-x", dest="exclude", metavar="FILE", action="append", default=[],
2448 optparser.add_option("-e", "--extension", dest="extension", metavar="EXTENSION", default=".pb",
2450 optparser.add_option("-H", "--header-extension", dest="header_extension", metavar="EXTENSION", defa…
2452 optparser.add_option("-S", "--source-extension", dest="source_extension", metavar="EXTENSION", defa…
2454 optparser.add_option("-f", "--options-file", dest="options_file", metavar="FILE", default="%s.optio…
2456 optparser.add_option("-I", "--options-path", "--proto-path", dest="options_path", metavar="DIR",
2459 optparser.add_option("--error-on-unmatched", dest="error_on_unmatched", action="store_true", defaul…
2461 optparser.add_option("--no-error-on-unmatched", dest="error_on_unmatched", action="store_false", de…
2463 optparser.add_option("-D", "--output-dir", dest="output_dir",
2466 optparser.add_option("-Q", "--generated-include-format", dest="genformat",
2469 optparser.add_option("-L", "--library-include-format", dest="libformat",
2472 optparser.add_option("--strip-path", dest="strip_path", action="store_true", default=False,
2474 optparser.add_option("--no-strip-path", dest="strip_path", action="store_false",
2475 help="Opposite of --strip-path (default since 0.4.0)")
2476 optparser.add_option("--cpp-descriptors", action="store_true",
2478 optparser.add_option("-T", "--no-timestamp", dest="notimestamp", action="store_true", default=True,
2480 optparser.add_option("-t", "--timestamp", dest="notimestamp", action="store_false", default=True,
2482 optparser.add_option("-q", "--quiet", dest="quiet", action="store_true", default=False,
2484 optparser.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False,
2486 optparser.add_option("-s", dest="settings", metavar="OPTION:VALUE", action="append", default=[],
2488 optparser.add_option("--protoc-opt", dest="protoc_opts", action="append", default = [], metavar="OP…
2490 optparser.add_option("--protoc-insertion-points", dest="protoc_insertion_points", action="store_tru…
2492 optparser.add_option("-C", "--c-style", dest="c_style", action="store_true", default=False,
2503 optparser.add_option("--custom-style", dest="custom_style", type=str, metavar="MODULE.CLASS", actio…
2504 …ngStyle class to be overridden. When paired with the -C/--c-style option, the NamingStyleC class i…
2559 sys.stderr.write('Google Python protobuf library imported from %s, version %s\n'
2577 # Check if there is a separate .options file
2582 # No %s specified, use the filename as-is
2592 Globals.separate_options = read_options_file(open(optfilename, 'r', encoding = 'utf-8'))
2666 … sys.stderr.write("Use protoc --nanopb-out=-v:. to see a list of the field names.\n")
2682 include_path = ['-I%s' % p for p in options.options_path]
2691 args += ['--include_imports', '--include_source_info', '-o' + tmpname, filename]
2699 last_fdesc = fdescs[-1]
2731 with open(path, 'w', encoding='utf-8') as f:
2749 # Versions of Python prior to 2.7.3 do not support unicode
2755 if ',' not in params and ' -' in params:
2760 # This allows also giving --nanopb_opt option multiple times.
2767 …optparser.usage = "protoc --nanopb_out=outdir [--nanopb_opt=option] ['--nanopb_opt=option with spa…
2770 if '-h' in args or '--help' in args:
2812 if 'protoc-gen-' in sys.argv[0] or '--protoc-plugin' in sys.argv: