Commit graph

41 commits

Author SHA1 Message Date
Protobuf Team Bot
02a9c9dec8 Fix messageset conformance for pure Python to match Py-C++ and Py-upb
MessageSet is a legacy affordance holdover from pre-proto2 days. Unlike the rest of Protobuf, it has first-wins instead of last-wins semantic in the case of duplicate ids or values within the same message set entry.

No serializer would ever write such sequences, but the same hypothetical byte sequence being parsed differently by two implementations is undesirable.

Note that other nonconformance fixes would commonly be held to breaking change releases to avoid any possible disruption of single-language users who may be relying on it as a load-bearing bug. However, the nature of this particular case is such that there is little reason to hold it back.

PiperOrigin-RevId: 964043226
2026-08-13 06:25:58 -07:00
Protobuf Team Bot
6cd6ca4116 Auto-format Py Proto python files.
PiperOrigin-RevId: 907755617
2026-04-29 13:40:58 -07:00
Jie Luo
b4c3fecb85 Add recursion guards for the following nested messages:
- map field for pure Python
- message_set_extension for Pure Python
- message_set_extension for UPB Python
https://github.com/protocolbuffers/protobuf/issues/25335

PiperOrigin-RevId: 868863633
2026-02-11 15:13:37 -08:00
Protobuf Team Bot
17838beda2 Add recursion depth limits to pure python
PiperOrigin-RevId: 758382549
2025-05-13 14:45:52 -07:00
Protobuf Team Bot
a6fa5799ff Internal pure python fixes
PiperOrigin-RevId: 733441339
2025-03-04 13:30:02 -08:00
Mike Kruskal
bc16fe8921 Treat -0.0 as consistently distinct from 0.0 in pure python
The previous treatment was a conformance violation, where implicit present float fields with a non-default value of -0.0 could get dropped.

PiperOrigin-RevId: 705728806
2024-12-12 20:34:44 -08:00
Mike Kruskal
1b0b1c9ba0 Remove decoder.SkipField.
This is only used in some narrow edge cases, and is a less-safe version of our unknown field decoders.  Switching to those reduces some duplication and improves error handling.

PiperOrigin-RevId: 704899254
2024-12-10 17:21:38 -08:00
Mike Kruskal
f69ea1cc48 Make Pure Python reject unmatched end-group tag in unknown fields
This brings it into conformance with our spec and other languages.

PiperOrigin-RevId: 704518974
2024-12-09 20:12:03 -08:00
Jie Luo
3a9f0743ea Nextgen Proto Pythonic API: “Add-on” proto for length prefixed serialize/parse
Added the following methods:
serialize_length_prefixed(message: Message, output: io.BytesIO) -> None
parse_length_prefixed(message_class: Type[Message], input_bytes: io.BytesIO) -> Message

The output of serialize_length_prefixed should be BytesIO or custom buffered IO that data should be written to. The output stream must be buffered, e.g. using
  https://docs.python.org/3/library/io.html#buffered-streams.

PiperOrigin-RevId: 638375900
2024-05-29 12:37:24 -07:00
Jie Luo
eee53125c4 internal change
PiperOrigin-RevId: 613982814
2024-03-08 10:55:53 -08:00
Joshua Haberman
9ef8f5cffc Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full.
PiperOrigin-RevId: 563897888
2023-09-08 18:50:27 -07:00
Jie Luo
c80e7efac7 Soft deprecate python MessageFactory
Soft deprecate python MessageFactory. Added new replacement APIs GetMessageClass(descriptor) and GetMessagesFromFiles(files, pool)

PiperOrigin-RevId: 501802633
2023-01-13 03:18:24 -08:00
Jie Luo
3d3bebf8ab Internal change only
PiperOrigin-RevId: 491993057
2022-11-30 12:50:31 -08:00
Adam Cozzette
a336ba0346 Sync from Piper @435734090
PROTOBUF_SYNC_PIPER
2022-03-18 21:25:56 +00:00
Joshua Haberman
e5c570bb57 Sync from Piper @395706834
PROTOBUF_SYNC_PIPER
2021-09-09 08:21:42 -07:00
Joshua Haberman
f77065d4eb Sync from Piper @316511779
PROTOBUF_SYNC_PIPER
2020-06-15 11:48:47 -07:00
Joshua Haberman
c649397029
Set execute bit on files if and only if they begin with (#!). (#7347)
* Set execute bit on files if and only if they begin with (#!).

Git only tracks the 'x' (executable) bit on each file. Prior to this
CL, our files were a random mix of executable and non-executable.
This change imposes some order by making files executable if and only
if they have shebang (#!) lines at the beginning.

We don't have any executable binaries checked into the repo, so
we shouldn't need to worry about that case.

* Added fix_permissions.sh script to set +x iff a file begins with (#!).
2020-04-01 15:28:25 -07:00
Joshua Haberman
b99994d994 Sync from Piper @304070343
PROTOBUF_SYNC_PIPER
2020-03-31 16:25:37 -07:00
Rafi Kamal
6c92f9dff1 Down integrate to GitHub 2019-10-11 12:05:46 -07:00
Rafi Kamal
4f02f056b5 Down integrate to GitHub 2019-08-22 17:33:01 -07:00
Hao Nguyen
2f864fdfdf Down integrate to Github 2019-03-20 11:45:01 -07:00
Josh Haberman
d61aede89c Down-integrate from google3. 2018-09-04 10:58:54 -07:00
Jie Luo
ab09b2a2e2
Disable surrogate check for ucs2 (#5039)
* _SURROGATE_PATTERN check for ucs4
Skip some test for ucs2 by sys.maxunicode
2018-08-14 11:17:16 -07:00
Feng Xiao
6bbe197e9c Down-integrate from google3. 2018-08-08 17:00:41 -07:00
Juan Leni
08334f0908 Converting to immutable hashable types 2017-10-11 06:46:25 +02:00
Joshua Haberman
ffa71f8007 A few more cases for binary conformance tests. (#2500)
* A few more cases for binary conformance tests.

* over-encoded varints (encoded in more bytes than are necessary).
* truncated varints (>32 bits for 32-bit types).

* Fixed Python decoding bug with 32-bit varints.

* Fixed 1L -> 1LL for 32-bit platforms.
2017-01-06 16:58:21 -08:00
Adam Cozzette
5a76e633ea Integrated internal changes from Google 2016-11-17 16:59:59 -08:00
Jisi Liu
46e8ff63cb Down-integrate from google internal. 2015-10-05 11:59:43 -07:00
Dan O'Reilly
fe7d9379df Fixing some long/int bugs
Signed-off-by: Dan O'Reilly <oreilldf@gmail.com>
2015-08-14 15:26:33 -04:00
Dan O'Reilly
e47cdd5a55 Merge remote-tracking branch 'upstream/master' into py2_py3_straddle
Conflicts:
	python/google/protobuf/descriptor_pool.py
	python/google/protobuf/internal/api_implementation_default_test.py
	python/google/protobuf/internal/cpp_message.py
	python/google/protobuf/internal/descriptor_database_test.py
	python/google/protobuf/internal/descriptor_pool_test.py
	python/google/protobuf/internal/descriptor_python_test.py
	python/google/protobuf/internal/descriptor_test.py
	python/google/protobuf/internal/generator_test.py
	python/google/protobuf/internal/message_factory_python_test.py
	python/google/protobuf/internal/message_factory_test.py
	python/google/protobuf/internal/message_test.py
	python/google/protobuf/internal/proto_builder_test.py
	python/google/protobuf/internal/python_message.py
	python/google/protobuf/internal/reflection_test.py
	python/google/protobuf/internal/service_reflection_test.py
	python/google/protobuf/internal/symbol_database_test.py
	python/google/protobuf/internal/text_encoding_test.py
	python/google/protobuf/internal/text_format_test.py
	python/google/protobuf/internal/unknown_fields_test.py
	python/google/protobuf/internal/wire_format_test.py
	python/google/protobuf/pyext/descriptor_cpp2_test.py
	python/google/protobuf/pyext/message_factory_cpp2_test.py
	python/google/protobuf/pyext/reflection_cpp2_generated_test.py
	python/setup.py
	ruby/lib/google/protobuf/message_exts.rb
2015-08-12 23:57:46 -04:00
Bo Yang
5db217305f down-integrate internal changes 2015-05-21 19:32:02 -07:00
Jisi Liu
ada6556785 Down integrate from Google internal.
Change-Id: I34d301133eea9c6f3a822c47d1f91e136fd33145
2015-02-25 16:39:11 -08:00
Tres Seaver
f336d4b7a5 Prepare for Python2-Python3 straddle.
- Remove PY25 cruft.

- Selectively apply cleanups from 'python-modernize':

  - New exception syntax.
  - Use 'six' to handle module renames.
  - Use 'six' to handle text / binary stuff.

This PR covers most of the work from #66 which falls inside `python`
(rather than the Python code generation stuff in 'src').
2015-01-13 14:22:05 -05:00
Feng Xiao
e428862450 Replace links to code.google.com/protobuf with developers.google.com/protocol-buffers 2014-10-01 16:26:23 -07:00
jieluo@google.com
bde4a3254a down integrate python opensource to svn 2014-08-12 21:10:30 +00:00
xiaofeng@google.com
b55a20fa2c Down-integrate from internal branch 2012-09-22 02:40:50 +00:00
liujisi@google.com
33165fe0d5 Submit recent changes from internal branch. See CHANGES.txt for more details. 2010-11-02 13:14:58 +00:00
kenton@google.com
fccb146e3f Massive roll-up of changes. See CHANGES.txt. 2009-12-18 02:11:36 +00:00
kenton@google.com
80b1d62bfc Submit recent changes from internal branch, including "lite mode" for
C++ and Java.  See CHANGES.txt for more details.
2009-07-29 01:13:20 +00:00
kenton@google.com
24bf56fb3a Integrate changes from internal Google-internal branch.
General
  * License changed from Apache 2.0 to New BSD.
  * It is now possible to define custom "options", which are basically
    annotations which may be placed on definitions in a .proto file.
    For example, you might define a field option called "foo" like so:
      import "google/protobuf/descriptor.proto"
      extend google.protobuf.FieldOptions {
        optional string foo = 12345;
      }
    Then you annotate a field using the "foo" option:
      message MyMessage {
        optional int32 some_field = 1 [(foo) = "bar"]
      }
    The value of this option is then visible via the message's
    Descriptor:
      const FieldDescriptor* field =
        MyMessage::descriptor()->FindFieldByName("some_field");
      assert(field->options().GetExtension(foo) == "bar");
    This feature has been implemented and tested in C++ and Java.
    Other languages may or may not need to do extra work to support
    custom options, depending on how they construct descriptors.

  C++
  * Fixed some GCC warnings that only occur when using -pedantic.
  * Improved static initialization code, making ordering more
    predictable among other things.
  * TextFormat will no longer accept messages which contain multiple
    instances of a singular field.  Previously, the latter instance
    would overwrite the former.
  * Now works on systems that don't have hash_map.

  Python
  * Strings now use the "unicode" type rather than the "str" type.
    String fields may still be assigned ASCII "str" values; they will
    automatically be converted.
  * Adding a property to an object representing a repeated field now
    raises an exception.  For example:
      # No longer works (and never should have).
      message.some_repeated_field.foo = 1
2008-09-24 20:31:01 +00:00
temporal
40ee551715 Initial checkin. 2008-07-10 02:12:20 +00:00