diff --git a/.github/workflows/pypi-release.yml b/.github/workflows/pypi-release.yml index 50826f1..8a2bc61 100644 --- a/.github/workflows/pypi-release.yml +++ b/.github/workflows/pypi-release.yml @@ -3,7 +3,7 @@ name: PyPI-Release on: push: branches: - - master + - main jobs: build-and-publish: diff --git a/CHANGELOG.md b/CHANGELOG.md index 06c9f29..c40d496 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Malformed unicode buffer encoded in `base_64` json field no-longer fail CloudEvent + class construction ([#184]) +### Changed +- Default branch changed from `master` to `main` ([#180]) + + +## [1.4.0] — 2022-07-14 ### Added - Added `.get` accessor for even properties ([#165]) - Added type information for all event member functions ([#173]) @@ -22,7 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `docs` folder and related unused tooling ([#168]) -## [1.3.0] — 2022-09-07 +## [1.3.0] — 2022-07-09 ### Added - Python 3.9 support ([#144]) - Python 3.10 support ([#150]) @@ -108,6 +116,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Initial release +[1.4.0]: https://github.com/cloudevents/sdk-python/compare/1.3.0...1.4.0 [1.3.0]: https://github.com/cloudevents/sdk-python/compare/1.2.0...1.3.0 [1.2.0]: https://github.com/cloudevents/sdk-python/compare/1.1.0...1.2.0 [1.1.0]: https://github.com/cloudevents/sdk-python/compare/1.0.1...1.1.0 @@ -162,3 +171,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#170]: https://github.com/cloudevents/sdk-python/pull/170 [#172]: https://github.com/cloudevents/sdk-python/pull/172 [#173]: https://github.com/cloudevents/sdk-python/pull/173 +[#180]: https://github.com/cloudevents/sdk-python/pull/180 +[#184]: https://github.com/cloudevents/sdk-python/pull/184 diff --git a/RELEASING.md b/RELEASING.md index 52418ba..f6ca05b 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -7,11 +7,11 @@ To release a new CloudEvents SDK, contributors should bump `__version__` in [cloudevents](cloudevents/__init__.py) to reflect the new release version. On merge, the action will automatically build and release to PyPI using [this PyPI GitHub Action](https://github.com/pypa/gh-action-pypi-publish). This -action gets called on all pushes to master (such as a version branch being merged -into master), but only releases a new version when the version number has changed. Note, -this action assumes pushes to master are version updates. Consequently, +action gets called on all pushes to main (such as a version branch being merged +into main), but only releases a new version when the version number has changed. Note, +this action assumes pushes to main are version updates. Consequently, [pypi-release.yml](.github/workflows/pypi-release.yml) will fail if you attempt to -push to master without updating `__version__` in +push to main without updating `__version__` in [cloudevents](cloudevents/__init__.py) so don't forget to do so. After a version update is merged, the script [pypi_packaging.py](pypi_packaging.py) diff --git a/cloudevents/__init__.py b/cloudevents/__init__.py index c9162a5..c695db9 100644 --- a/cloudevents/__init__.py +++ b/cloudevents/__init__.py @@ -11,5 +11,17 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. -__version__ = "1.3.0" +__version__ = "1.4.0" diff --git a/cloudevents/http/util.py b/cloudevents/http/util.py index 337505f..c2727aa 100644 --- a/cloudevents/http/util.py +++ b/cloudevents/http/util.py @@ -25,10 +25,22 @@ def default_marshaller(content: any): return content -def _json_or_string(content: typing.Union[str, bytes]): +def _json_or_string( + content: typing.Optional[typing.AnyStr], +) -> typing.Optional[ + typing.Union[ + typing.Dict[typing.Any, typing.Any], + typing.List[typing.Any], + typing.AnyStr, + ] +]: + """ + Given an encoded JSON string MUST return decoded JSON object. + Otherwise, MUST return the given string as-is. + """ if content is None: return None try: return json.loads(content) - except (json.JSONDecodeError, TypeError): + except (json.JSONDecodeError, TypeError, UnicodeDecodeError): return content diff --git a/cloudevents/tests/test_http_cloudevent.py b/cloudevents/tests/test_http_cloudevent.py index fa4bd91..4f1b16b 100644 --- a/cloudevents/tests/test_http_cloudevent.py +++ b/cloudevents/tests/test_http_cloudevent.py @@ -168,8 +168,19 @@ def test_cloudevent_general_overrides(): assert len(event) == 0 -def test_none_json_or_string(): - assert _json_or_string(None) is None +@pytest.mark.parametrize( + "given, expected", + [ + (None, None), + ('{"hello": "world"}', {"hello": "world"}), + (b'{"hello": "world"}', {"hello": "world"}), + (b"Hello World", b"Hello World"), + ("Hello World", "Hello World"), + (b"\x00\x00\x11Hello World", b"\x00\x00\x11Hello World"), + ], +) +def test_json_or_string_match_golden_sample(given, expected): + assert _json_or_string(given) == expected def test_get_operation_on_non_existing_attribute_must_not_raise_exception( diff --git a/pypi_packaging.py b/pypi_packaging.py index 1aa7ae9..c81986d 100644 --- a/pypi_packaging.py +++ b/pypi_packaging.py @@ -11,6 +11,18 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. import os @@ -33,7 +45,7 @@ def createTag(): repo = Repo(os.getcwd()) repo.create_tag(pypi_config["version_target"]) - # Push git tag to remote master + # Push git tag to remote main origin = repo.remote() origin.push(pypi_config["version_target"])