diff --git a/cloudevents/conversion.py b/cloudevents/conversion.py index 731c114..6b83cfe 100644 --- a/cloudevents/conversion.py +++ b/cloudevents/conversion.py @@ -16,13 +16,12 @@ import enum import json import typing +from cloudevents import exceptions as cloud_exceptions from cloudevents.abstract import AnyCloudEvent from cloudevents.sdk import converters, marshaller, types from cloudevents.sdk.converters import is_binary from cloudevents.sdk.event import v1, v03 -from cloudevents import exceptions as cloud_exceptions - def _best_effort_serialize_to_json( # type: ignore[no-untyped-def] value: typing.Any, *args, **kwargs diff --git a/cloudevents/http/event.py b/cloudevents/http/event.py index 4a21a8b..f3c0063 100644 --- a/cloudevents/http/event.py +++ b/cloudevents/http/event.py @@ -17,9 +17,8 @@ import typing import uuid import cloudevents.exceptions as cloud_exceptions -from cloudevents.sdk.event import v1, v03 - from cloudevents import abstract +from cloudevents.sdk.event import v1, v03 _required_by_version = { "1.0": v1.Event._ce_required_fields, diff --git a/cloudevents/http/event_type.py b/cloudevents/http/event_type.py index d3c56fe..52259e1 100644 --- a/cloudevents/http/event_type.py +++ b/cloudevents/http/event_type.py @@ -13,9 +13,10 @@ # under the License. import typing +from deprecation import deprecated + from cloudevents.sdk.converters import is_binary as _moved_is_binary from cloudevents.sdk.converters import is_structured as _moved_is_structured -from deprecation import deprecated # THIS MODULE IS DEPRECATED, YOU SHOULD NOT ADD NEW FUNCTIONALLY HERE diff --git a/cloudevents/http/http_methods.py b/cloudevents/http/http_methods.py index 6356616..091c51b 100644 --- a/cloudevents/http/http_methods.py +++ b/cloudevents/http/http_methods.py @@ -14,13 +14,14 @@ import typing +from deprecation import deprecated + from cloudevents.abstract import AnyCloudEvent from cloudevents.conversion import to_binary as _moved_to_binary from cloudevents.conversion import to_structured as _moved_to_structured from cloudevents.http.conversion import from_http as _moved_from_http from cloudevents.http.event import CloudEvent from cloudevents.sdk import types -from deprecation import deprecated # THIS MODULE IS DEPRECATED, YOU SHOULD NOT ADD NEW FUNCTIONALLY HERE diff --git a/cloudevents/http/json_methods.py b/cloudevents/http/json_methods.py index 8899361..58e322c 100644 --- a/cloudevents/http/json_methods.py +++ b/cloudevents/http/json_methods.py @@ -14,12 +14,13 @@ import typing +from deprecation import deprecated + from cloudevents.abstract import AnyCloudEvent from cloudevents.conversion import to_json as _moved_to_json from cloudevents.http import CloudEvent from cloudevents.http.conversion import from_json as _moved_from_json from cloudevents.sdk import types -from deprecation import deprecated # THIS MODULE IS DEPRECATED, YOU SHOULD NOT ADD NEW FUNCTIONALLY HERE diff --git a/cloudevents/http/util.py b/cloudevents/http/util.py index 56fbc34..f44395e 100644 --- a/cloudevents/http/util.py +++ b/cloudevents/http/util.py @@ -13,10 +13,11 @@ # under the License. import typing +from deprecation import deprecated + from cloudevents.conversion import ( _best_effort_serialize_to_json as _moved_default_marshaller, ) -from deprecation import deprecated # THIS MODULE IS DEPRECATED, YOU SHOULD NOT ADD NEW FUNCTIONALLY HERE diff --git a/cloudevents/kafka/conversion.py b/cloudevents/kafka/conversion.py index b028bac..bdf2aca 100644 --- a/cloudevents/kafka/conversion.py +++ b/cloudevents/kafka/conversion.py @@ -15,13 +15,12 @@ import base64 import json import typing +from cloudevents import exceptions as cloud_exceptions +from cloudevents import http from cloudevents.abstract import AnyCloudEvent from cloudevents.kafka.exceptions import KeyMapperError from cloudevents.sdk import types -from cloudevents import exceptions as cloud_exceptions -from cloudevents import http - JSON_MARSHALLER: types.MarshallerType = json.dumps JSON_UNMARSHALLER: types.UnmarshallerType = json.loads IDENTITY_MARSHALLER = IDENTITY_UNMARSHALLER = lambda x: x diff --git a/cloudevents/pydantic/v1/event.py b/cloudevents/pydantic/v1/event.py index 18f95fd..98c6136 100644 --- a/cloudevents/pydantic/v1/event.py +++ b/cloudevents/pydantic/v1/event.py @@ -32,11 +32,10 @@ except ImportError: # pragma: no cover # hard to test "Install it using pip install cloudevents[pydantic]" ) +from cloudevents import abstract, conversion, http from cloudevents.exceptions import IncompatibleArgumentsError from cloudevents.sdk.event import attribute -from cloudevents import abstract, conversion, http - def _ce_json_dumps( # type: ignore[no-untyped-def] obj: typing.Dict[str, typing.Any], diff --git a/cloudevents/pydantic/v2/event.py b/cloudevents/pydantic/v2/event.py index 8afead7..34a9b65 100644 --- a/cloudevents/pydantic/v2/event.py +++ b/cloudevents/pydantic/v2/event.py @@ -17,9 +17,10 @@ import json import typing from typing import Any +from pydantic.deprecated import parse as _deprecated_parse + from cloudevents.exceptions import PydanticFeatureNotInstalled from cloudevents.pydantic.fields_docs import FIELD_DESCRIPTIONS -from pydantic.deprecated import parse as _deprecated_parse try: from pydantic import BaseModel, ConfigDict, Field, model_serializer @@ -29,11 +30,10 @@ except ImportError: # pragma: no cover # hard to test "Install it using pip install cloudevents[pydantic]" ) +from cloudevents import abstract, conversion from cloudevents.exceptions import IncompatibleArgumentsError from cloudevents.sdk.event import attribute -from cloudevents import abstract, conversion - class CloudEvent(abstract.CloudEvent, BaseModel): # type: ignore """ diff --git a/cloudevents/tests/test_backwards_compatability.py b/cloudevents/tests/test_backwards_compatability.py index 4b3fecc..0a20f4c 100644 --- a/cloudevents/tests/test_backwards_compatability.py +++ b/cloudevents/tests/test_backwards_compatability.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. import pytest + from cloudevents.conversion import _best_effort_serialize_to_json from cloudevents.http import CloudEvent diff --git a/cloudevents/tests/test_base_events.py b/cloudevents/tests/test_base_events.py index 49a9894..8eb83d4 100644 --- a/cloudevents/tests/test_base_events.py +++ b/cloudevents/tests/test_base_events.py @@ -12,8 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. -import cloudevents.exceptions as cloud_exceptions import pytest + +import cloudevents.exceptions as cloud_exceptions from cloudevents.sdk.event import v1, v03 diff --git a/cloudevents/tests/test_converters.py b/cloudevents/tests/test_converters.py index 155d55b..50d783b 100644 --- a/cloudevents/tests/test_converters.py +++ b/cloudevents/tests/test_converters.py @@ -13,6 +13,7 @@ # under the License. import pytest + from cloudevents.sdk import exceptions from cloudevents.sdk.converters import base, binary diff --git a/cloudevents/tests/test_data_encaps_refs.py b/cloudevents/tests/test_data_encaps_refs.py index c745c5b..02405a9 100644 --- a/cloudevents/tests/test_data_encaps_refs.py +++ b/cloudevents/tests/test_data_encaps_refs.py @@ -16,6 +16,7 @@ import json from uuid import uuid4 import pytest + from cloudevents.sdk import converters, marshaller from cloudevents.sdk.event import v1, v03 from cloudevents.tests import data diff --git a/cloudevents/tests/test_deprecated_functions.py b/cloudevents/tests/test_deprecated_functions.py index c4deecd..a99f624 100644 --- a/cloudevents/tests/test_deprecated_functions.py +++ b/cloudevents/tests/test_deprecated_functions.py @@ -13,6 +13,7 @@ # under the License. import pytest + from cloudevents.http import ( CloudEvent, to_binary, diff --git a/cloudevents/tests/test_event_extensions.py b/cloudevents/tests/test_event_extensions.py index d50dc3a..eea8edf 100644 --- a/cloudevents/tests/test_event_extensions.py +++ b/cloudevents/tests/test_event_extensions.py @@ -15,6 +15,7 @@ import json import pytest + from cloudevents.http import CloudEvent, from_http, to_binary, to_structured test_data = json.dumps({"data-key": "val"}) diff --git a/cloudevents/tests/test_event_from_request_converter.py b/cloudevents/tests/test_event_from_request_converter.py index 78d44ba..362b1ca 100644 --- a/cloudevents/tests/test_event_from_request_converter.py +++ b/cloudevents/tests/test_event_from_request_converter.py @@ -15,6 +15,7 @@ import json import pytest + from cloudevents.sdk import marshaller from cloudevents.sdk.converters import binary, structured from cloudevents.sdk.event import v1, v03 diff --git a/cloudevents/tests/test_event_pipeline.py b/cloudevents/tests/test_event_pipeline.py index 2b08b0c..dae3dc2 100644 --- a/cloudevents/tests/test_event_pipeline.py +++ b/cloudevents/tests/test_event_pipeline.py @@ -15,6 +15,7 @@ import json import pytest + from cloudevents.sdk import converters, marshaller from cloudevents.sdk.converters import structured from cloudevents.sdk.event import v1, v03 diff --git a/cloudevents/tests/test_event_to_request_converter.py b/cloudevents/tests/test_event_to_request_converter.py index c101912..fd25be5 100644 --- a/cloudevents/tests/test_event_to_request_converter.py +++ b/cloudevents/tests/test_event_to_request_converter.py @@ -15,6 +15,7 @@ import json import pytest + from cloudevents.sdk import converters, marshaller from cloudevents.sdk.event import v1, v03 from cloudevents.tests import data diff --git a/cloudevents/tests/test_http_cloudevent.py b/cloudevents/tests/test_http_cloudevent.py index 113a8bb..6ad1537 100644 --- a/cloudevents/tests/test_http_cloudevent.py +++ b/cloudevents/tests/test_http_cloudevent.py @@ -12,8 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. -import cloudevents.exceptions as cloud_exceptions import pytest + +import cloudevents.exceptions as cloud_exceptions from cloudevents.conversion import _json_or_string from cloudevents.http import CloudEvent diff --git a/cloudevents/tests/test_http_conversions.py b/cloudevents/tests/test_http_conversions.py index e7072e9..3b9c671 100644 --- a/cloudevents/tests/test_http_conversions.py +++ b/cloudevents/tests/test_http_conversions.py @@ -17,6 +17,7 @@ import datetime import json import pytest + from cloudevents.conversion import to_dict, to_json from cloudevents.http import CloudEvent, from_dict, from_json from cloudevents.sdk.event.attribute import SpecVersion diff --git a/cloudevents/tests/test_http_events.py b/cloudevents/tests/test_http_events.py index 5045dc5..3d4c8d5 100644 --- a/cloudevents/tests/test_http_events.py +++ b/cloudevents/tests/test_http_events.py @@ -18,15 +18,16 @@ import io import json import typing -import cloudevents.exceptions as cloud_exceptions import pytest +from sanic import Sanic, response + +import cloudevents.exceptions as cloud_exceptions from cloudevents.http import CloudEvent, from_http, to_binary, to_structured from cloudevents.http.event_type import is_binary as deprecated_is_binary from cloudevents.http.event_type import is_structured as deprecated_is_structured from cloudevents.sdk import converters from cloudevents.sdk.converters.binary import is_binary from cloudevents.sdk.converters.structured import is_structured -from sanic import Sanic, response invalid_test_headers = [ { diff --git a/cloudevents/tests/test_kafka_conversions.py b/cloudevents/tests/test_kafka_conversions.py index 715aee8..584a05e 100644 --- a/cloudevents/tests/test_kafka_conversions.py +++ b/cloudevents/tests/test_kafka_conversions.py @@ -17,6 +17,8 @@ import datetime import json import pytest + +from cloudevents import exceptions as cloud_exceptions from cloudevents.abstract.event import AnyCloudEvent from cloudevents.http import CloudEvent from cloudevents.kafka.conversion import ( @@ -29,8 +31,6 @@ from cloudevents.kafka.conversion import ( from cloudevents.kafka.exceptions import KeyMapperError from cloudevents.sdk import types -from cloudevents import exceptions as cloud_exceptions - def simple_serialize(data: dict) -> bytes: return bytes(json.dumps(data).encode("utf-8")) diff --git a/cloudevents/tests/test_marshaller.py b/cloudevents/tests/test_marshaller.py index 2c9026e..6561418 100644 --- a/cloudevents/tests/test_marshaller.py +++ b/cloudevents/tests/test_marshaller.py @@ -14,8 +14,9 @@ import json -import cloudevents.exceptions as cloud_exceptions import pytest + +import cloudevents.exceptions as cloud_exceptions from cloudevents.http import CloudEvent, from_http, to_binary, to_structured from cloudevents.sdk import exceptions, marshaller from cloudevents.sdk.converters import binary, structured diff --git a/cloudevents/tests/test_options.py b/cloudevents/tests/test_options.py index 4815c56..aba812b 100644 --- a/cloudevents/tests/test_options.py +++ b/cloudevents/tests/test_options.py @@ -13,6 +13,7 @@ # under the License. import pytest + from cloudevents.sdk.event.opt import Option diff --git a/cloudevents/tests/test_pydantic_cloudevent.py b/cloudevents/tests/test_pydantic_cloudevent.py index 329cf93..87ac550 100644 --- a/cloudevents/tests/test_pydantic_cloudevent.py +++ b/cloudevents/tests/test_pydantic_cloudevent.py @@ -15,13 +15,14 @@ import datetime from json import loads import pytest +from pydantic import ValidationError as PydanticV2ValidationError +from pydantic.v1 import ValidationError as PydanticV1ValidationError + from cloudevents.conversion import _json_or_string from cloudevents.exceptions import IncompatibleArgumentsError from cloudevents.pydantic.v1.event import CloudEvent as PydanticV1CloudEvent from cloudevents.pydantic.v2.event import CloudEvent as PydanticV2CloudEvent from cloudevents.sdk.event.attribute import SpecVersion -from pydantic import ValidationError as PydanticV2ValidationError -from pydantic.v1 import ValidationError as PydanticV1ValidationError _DUMMY_SOURCE = "dummy:source" _DUMMY_TYPE = "tests.cloudevents.override" diff --git a/cloudevents/tests/test_pydantic_conversions.py b/cloudevents/tests/test_pydantic_conversions.py index 44ff7ac..801b76b 100644 --- a/cloudevents/tests/test_pydantic_conversions.py +++ b/cloudevents/tests/test_pydantic_conversions.py @@ -17,6 +17,9 @@ import datetime import json import pytest +from pydantic import ValidationError as PydanticV2ValidationError +from pydantic.v1 import ValidationError as PydanticV1ValidationError + from cloudevents.conversion import to_json from cloudevents.pydantic.v1.conversion import from_dict as pydantic_v1_from_dict from cloudevents.pydantic.v1.conversion import from_json as pydantic_v1_from_json @@ -25,8 +28,6 @@ from cloudevents.pydantic.v2.conversion import from_dict as pydantic_v2_from_dic from cloudevents.pydantic.v2.conversion import from_json as pydantic_v2_from_json from cloudevents.pydantic.v2.event import CloudEvent as PydanticV2CloudEvent from cloudevents.sdk.event.attribute import SpecVersion -from pydantic import ValidationError as PydanticV2ValidationError -from pydantic.v1 import ValidationError as PydanticV1ValidationError test_data = json.dumps({"data-key": "val"}) test_attributes = { diff --git a/cloudevents/tests/test_pydantic_events.py b/cloudevents/tests/test_pydantic_events.py index 98416cb..30ad1fe 100644 --- a/cloudevents/tests/test_pydantic_events.py +++ b/cloudevents/tests/test_pydantic_events.py @@ -18,8 +18,12 @@ import io import json import typing -import cloudevents.exceptions as cloud_exceptions import pytest +from pydantic import ValidationError as PydanticV2ValidationError +from pydantic.v1 import ValidationError as PydanticV1ValidationError +from sanic import Sanic, response + +import cloudevents.exceptions as cloud_exceptions from cloudevents.conversion import to_binary, to_structured from cloudevents.pydantic.v1.conversion import from_http as pydantic_v1_from_http from cloudevents.pydantic.v1.event import CloudEvent as PydanticV1CloudEvent @@ -28,9 +32,6 @@ from cloudevents.pydantic.v2.event import CloudEvent as PydanticV2CloudEvent from cloudevents.sdk import converters, types from cloudevents.sdk.converters.binary import is_binary from cloudevents.sdk.converters.structured import is_structured -from pydantic import ValidationError as PydanticV2ValidationError -from pydantic.v1 import ValidationError as PydanticV1ValidationError -from sanic import Sanic, response if typing.TYPE_CHECKING: from typing_extensions import TypeAlias diff --git a/cloudevents/tests/test_with_sanic.py b/cloudevents/tests/test_with_sanic.py index c433782..026f55b 100644 --- a/cloudevents/tests/test_with_sanic.py +++ b/cloudevents/tests/test_with_sanic.py @@ -12,10 +12,11 @@ # License for the specific language governing permissions and limitations # under the License. +from sanic import Sanic, response + from cloudevents.sdk import converters, marshaller from cloudevents.sdk.event import v1 from cloudevents.tests import data as test_data -from sanic import Sanic, response m = marshaller.NewDefaultHTTPMarshaller() app = Sanic("test_with_sanic") diff --git a/samples/http-image-cloudevents/client.py b/samples/http-image-cloudevents/client.py index d928de5..ee00394 100644 --- a/samples/http-image-cloudevents/client.py +++ b/samples/http-image-cloudevents/client.py @@ -15,6 +15,7 @@ import sys import requests + from cloudevents.conversion import to_binary, to_structured from cloudevents.http import CloudEvent diff --git a/samples/http-image-cloudevents/image_sample_server.py b/samples/http-image-cloudevents/image_sample_server.py index fc1a637..da30302 100644 --- a/samples/http-image-cloudevents/image_sample_server.py +++ b/samples/http-image-cloudevents/image_sample_server.py @@ -14,10 +14,11 @@ import io -from cloudevents.http import from_http from flask import Flask, request from PIL import Image +from cloudevents.http import from_http + app = Flask(__name__) diff --git a/samples/http-image-cloudevents/image_sample_test.py b/samples/http-image-cloudevents/image_sample_test.py index 3460874..5fe6ec9 100644 --- a/samples/http-image-cloudevents/image_sample_test.py +++ b/samples/http-image-cloudevents/image_sample_test.py @@ -18,11 +18,12 @@ import json import pytest from client import image_bytes -from cloudevents.conversion import to_binary, to_structured -from cloudevents.http import CloudEvent, from_http from image_sample_server import app from PIL import Image +from cloudevents.conversion import to_binary, to_structured +from cloudevents.http import CloudEvent, from_http + image_fileobj = io.BytesIO(image_bytes) image_expected_shape = (1880, 363) diff --git a/samples/http-json-cloudevents/client.py b/samples/http-json-cloudevents/client.py index b1822a4..5ecc379 100644 --- a/samples/http-json-cloudevents/client.py +++ b/samples/http-json-cloudevents/client.py @@ -15,6 +15,7 @@ import sys import requests + from cloudevents.conversion import to_binary, to_structured from cloudevents.http import CloudEvent diff --git a/samples/http-json-cloudevents/json_sample_server.py b/samples/http-json-cloudevents/json_sample_server.py index ae0d912..c3a399e 100644 --- a/samples/http-json-cloudevents/json_sample_server.py +++ b/samples/http-json-cloudevents/json_sample_server.py @@ -12,9 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. -from cloudevents.http import from_http from flask import Flask, request +from cloudevents.http import from_http + app = Flask(__name__) diff --git a/samples/http-json-cloudevents/json_sample_test.py b/samples/http-json-cloudevents/json_sample_test.py index bb94331..1d92874 100644 --- a/samples/http-json-cloudevents/json_sample_test.py +++ b/samples/http-json-cloudevents/json_sample_test.py @@ -13,9 +13,10 @@ # under the License. import pytest +from json_sample_server import app + from cloudevents.conversion import to_binary, to_structured from cloudevents.http import CloudEvent -from json_sample_server import app @pytest.fixture