diff --git a/cloudevents/conversion.py b/cloudevents/conversion.py index 6b83cfe..731c114 100644 --- a/cloudevents/conversion.py +++ b/cloudevents/conversion.py @@ -16,12 +16,13 @@ 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 f3c0063..4a21a8b 100644 --- a/cloudevents/http/event.py +++ b/cloudevents/http/event.py @@ -17,9 +17,10 @@ import typing import uuid import cloudevents.exceptions as cloud_exceptions -from cloudevents import abstract from cloudevents.sdk.event import v1, v03 +from cloudevents import abstract + _required_by_version = { "1.0": v1.Event._ce_required_fields, "0.3": v03.Event._ce_required_fields, diff --git a/cloudevents/http/event_type.py b/cloudevents/http/event_type.py index 52259e1..d3c56fe 100644 --- a/cloudevents/http/event_type.py +++ b/cloudevents/http/event_type.py @@ -13,10 +13,9 @@ # 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 091c51b..6356616 100644 --- a/cloudevents/http/http_methods.py +++ b/cloudevents/http/http_methods.py @@ -14,14 +14,13 @@ 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 58e322c..8899361 100644 --- a/cloudevents/http/json_methods.py +++ b/cloudevents/http/json_methods.py @@ -14,13 +14,12 @@ 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 f44395e..56fbc34 100644 --- a/cloudevents/http/util.py +++ b/cloudevents/http/util.py @@ -13,11 +13,10 @@ # 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 bdf2aca..b028bac 100644 --- a/cloudevents/kafka/conversion.py +++ b/cloudevents/kafka/conversion.py @@ -15,12 +15,13 @@ 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 98c6136..18f95fd 100644 --- a/cloudevents/pydantic/v1/event.py +++ b/cloudevents/pydantic/v1/event.py @@ -32,10 +32,11 @@ 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 34a9b65..8afead7 100644 --- a/cloudevents/pydantic/v2/event.py +++ b/cloudevents/pydantic/v2/event.py @@ -17,10 +17,9 @@ 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 @@ -30,10 +29,11 @@ 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 0a20f4c..4b3fecc 100644 --- a/cloudevents/tests/test_backwards_compatability.py +++ b/cloudevents/tests/test_backwards_compatability.py @@ -12,7 +12,6 @@ # 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 8eb83d4..49a9894 100644 --- a/cloudevents/tests/test_base_events.py +++ b/cloudevents/tests/test_base_events.py @@ -12,9 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import pytest - import cloudevents.exceptions as cloud_exceptions +import pytest from cloudevents.sdk.event import v1, v03 diff --git a/cloudevents/tests/test_converters.py b/cloudevents/tests/test_converters.py index 50d783b..155d55b 100644 --- a/cloudevents/tests/test_converters.py +++ b/cloudevents/tests/test_converters.py @@ -13,7 +13,6 @@ # 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 02405a9..c745c5b 100644 --- a/cloudevents/tests/test_data_encaps_refs.py +++ b/cloudevents/tests/test_data_encaps_refs.py @@ -16,7 +16,6 @@ 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 a99f624..c4deecd 100644 --- a/cloudevents/tests/test_deprecated_functions.py +++ b/cloudevents/tests/test_deprecated_functions.py @@ -13,7 +13,6 @@ # 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 eea8edf..d50dc3a 100644 --- a/cloudevents/tests/test_event_extensions.py +++ b/cloudevents/tests/test_event_extensions.py @@ -15,7 +15,6 @@ 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 362b1ca..78d44ba 100644 --- a/cloudevents/tests/test_event_from_request_converter.py +++ b/cloudevents/tests/test_event_from_request_converter.py @@ -15,7 +15,6 @@ 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 dae3dc2..2b08b0c 100644 --- a/cloudevents/tests/test_event_pipeline.py +++ b/cloudevents/tests/test_event_pipeline.py @@ -15,7 +15,6 @@ 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 fd25be5..c101912 100644 --- a/cloudevents/tests/test_event_to_request_converter.py +++ b/cloudevents/tests/test_event_to_request_converter.py @@ -15,7 +15,6 @@ 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 6ad1537..113a8bb 100644 --- a/cloudevents/tests/test_http_cloudevent.py +++ b/cloudevents/tests/test_http_cloudevent.py @@ -12,9 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import pytest - import cloudevents.exceptions as cloud_exceptions +import pytest 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 3b9c671..e7072e9 100644 --- a/cloudevents/tests/test_http_conversions.py +++ b/cloudevents/tests/test_http_conversions.py @@ -17,7 +17,6 @@ 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 3d4c8d5..5045dc5 100644 --- a/cloudevents/tests/test_http_events.py +++ b/cloudevents/tests/test_http_events.py @@ -18,16 +18,15 @@ import io import json import typing -import pytest -from sanic import Sanic, response - import cloudevents.exceptions as cloud_exceptions +import pytest 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 584a05e..715aee8 100644 --- a/cloudevents/tests/test_kafka_conversions.py +++ b/cloudevents/tests/test_kafka_conversions.py @@ -17,8 +17,6 @@ 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 ( @@ -31,6 +29,8 @@ 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 6561418..2c9026e 100644 --- a/cloudevents/tests/test_marshaller.py +++ b/cloudevents/tests/test_marshaller.py @@ -14,9 +14,8 @@ import json -import pytest - import cloudevents.exceptions as cloud_exceptions +import pytest 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 aba812b..4815c56 100644 --- a/cloudevents/tests/test_options.py +++ b/cloudevents/tests/test_options.py @@ -13,7 +13,6 @@ # 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 87ac550..329cf93 100644 --- a/cloudevents/tests/test_pydantic_cloudevent.py +++ b/cloudevents/tests/test_pydantic_cloudevent.py @@ -15,14 +15,13 @@ 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 801b76b..44ff7ac 100644 --- a/cloudevents/tests/test_pydantic_conversions.py +++ b/cloudevents/tests/test_pydantic_conversions.py @@ -17,9 +17,6 @@ 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 @@ -28,6 +25,8 @@ 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 30ad1fe..98416cb 100644 --- a/cloudevents/tests/test_pydantic_events.py +++ b/cloudevents/tests/test_pydantic_events.py @@ -18,12 +18,8 @@ import io import json import typing -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 +import pytest 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 @@ -32,6 +28,9 @@ 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 026f55b..c433782 100644 --- a/cloudevents/tests/test_with_sanic.py +++ b/cloudevents/tests/test_with_sanic.py @@ -12,11 +12,10 @@ # 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 ee00394..d928de5 100644 --- a/samples/http-image-cloudevents/client.py +++ b/samples/http-image-cloudevents/client.py @@ -15,7 +15,6 @@ 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 da30302..fc1a637 100644 --- a/samples/http-image-cloudevents/image_sample_server.py +++ b/samples/http-image-cloudevents/image_sample_server.py @@ -14,11 +14,10 @@ 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 5fe6ec9..3460874 100644 --- a/samples/http-image-cloudevents/image_sample_test.py +++ b/samples/http-image-cloudevents/image_sample_test.py @@ -18,11 +18,10 @@ import json import pytest from client import image_bytes -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 +from image_sample_server import app +from PIL import Image 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 5ecc379..b1822a4 100644 --- a/samples/http-json-cloudevents/client.py +++ b/samples/http-json-cloudevents/client.py @@ -15,7 +15,6 @@ 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 c3a399e..ae0d912 100644 --- a/samples/http-json-cloudevents/json_sample_server.py +++ b/samples/http-json-cloudevents/json_sample_server.py @@ -12,9 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -from flask import Flask, request - from cloudevents.http import from_http +from flask import Flask, request app = Flask(__name__) diff --git a/samples/http-json-cloudevents/json_sample_test.py b/samples/http-json-cloudevents/json_sample_test.py index 1d92874..bb94331 100644 --- a/samples/http-json-cloudevents/json_sample_test.py +++ b/samples/http-json-cloudevents/json_sample_test.py @@ -13,10 +13,9 @@ # 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