Skip to content

Commit

Permalink
pylint changes
Browse files Browse the repository at this point in the history
  • Loading branch information
l0lawrence committed Jun 3, 2024
1 parent 5f1fce3 commit 27c493e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
Optional,
TypeVar,
Union,
overload,
TYPE_CHECKING,
)

Expand All @@ -28,7 +27,6 @@
from azure.core.tracing.decorator import distributed_trace
from azure.core.pipeline import PipelineResponse
from azure.core.rest import HttpRequest, HttpResponse
from azure.core.utils import case_insensitive_dict

from ._operations import (
EventGridPublisherClientOperationsMixin as PublisherOperationsMixin,
Expand Down Expand Up @@ -105,8 +103,6 @@ def send(
) -> None: # pylint: disable=docstring-should-be-keyword, docstring-missing-param
"""Send events to the Event Grid Service.
:param topic_name: The name of the topic to send the event to.
:type topic_name: str
:param events: The event to send.
:type events: CloudEvent or List[CloudEvent] or Dict[str, Any] or List[Dict[str, Any]]
or CNCFCloudEvent or List[CNCFCloudEvent] or EventGridEvent or List[EventGridEvent]
Expand Down Expand Up @@ -143,24 +139,24 @@ def send(
# Try to send via namespace
self._publish(self._namespace, _serialize_events(events), **kwargs)
except Exception as exception: # pylint: disable=broad-except
self._http_response_error_handler(exception, "Namespaces")
self._http_response_error_handler(exception)
raise exception
else:
kwargs["content_type"] = content_type if content_type else "application/json; charset=utf-8"
try:
self._publish(events, channel_name=channel_name, **kwargs)
except Exception as exception:
self._http_response_error_handler(exception, "Basic")
self._http_response_error_handler(exception)
raise exception

def _http_response_error_handler(self, exception, level):
def _http_response_error_handler(self, exception):
if isinstance(exception, HttpResponseError):
if exception.status_code == 400:
raise HttpResponseError("Invalid event data. Please check the data and try again.") from exception
if exception.status_code == 404:
raise ResourceNotFoundError(
"Resource not found. "
f"Please check that the tier you are using, corresponds to the correct "
"Please check that the tier you are using, corresponds to the correct "
"endpoint and/or topic name."
) from exception
raise exception
Expand Down
3 changes: 2 additions & 1 deletion sdk/eventgrid/azure-eventgrid/azure/eventgrid/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ def __init__(
)

def __repr__(self) -> str:
return f"<EventGridConsumerClient: namespace_topic={self._namespace}, subscription={self._subscription}, credential type={type(self._credential)}>"
return f"<EventGridConsumerClient: namespace_topic={self._namespace}, \
subscription={self._subscription}, credential type={type(self._credential)}>"


def patch_sdk():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from azure.core.pipeline import PipelineResponse
from azure.core.rest import HttpRequest, AsyncHttpResponse
from ...models._patch import ReceiveDetails
from ..._operations._patch import use_standard_only
from ._operations import (
EventGridPublisherClientOperationsMixin as PublisherOperationsMixin,
EventGridConsumerClientOperationsMixin as ConsumerOperationsMixin,
Expand All @@ -29,7 +28,7 @@
)

from ..._legacy import EventGridEvent
from ..._legacy._helpers import _is_eventgrid_event_format, _from_cncf_events
from ..._legacy._helpers import _is_eventgrid_event_format

if sys.version_info >= (3, 9):
from collections.abc import MutableMapping
Expand Down Expand Up @@ -65,8 +64,6 @@ async def send(
) -> None: # pylint: disable=docstring-should-be-keyword, docstring-missing-param
"""Send events to the Event Grid Service.
:param topic_name: The name of the topic to send the event to.
:type topic_name: str
:param events: The event to send.
:type events: CloudEvent or List[CloudEvent] or Dict[str, Any] or List[Dict[str, Any]]
or CNCFCloudEvent or List[CNCFCloudEvent] or EventGridEvent or List[EventGridEvent]
Expand Down Expand Up @@ -104,24 +101,24 @@ async def send(
# Try to send via namespace
await self._publish(self._namespace, _serialize_events(events), **kwargs)
except Exception as exception: # pylint: disable=broad-except
self._http_response_error_handler(exception, "Namespaces")
self._http_response_error_handler(exception)
raise exception
else:
kwargs["content_type"] = content_type if content_type else "application/json; charset=utf-8"
try:
await self._publish(events, channel_name=channel_name, **kwargs)
except Exception as exception:
self._http_response_error_handler(exception, "Basic")
self._http_response_error_handler(exception)
raise exception

def _http_response_error_handler(self, exception, level):
def _http_response_error_handler(self, exception):
if isinstance(exception, HttpResponseError):
if exception.status_code == 400:
raise HttpResponseError("Invalid event data. Please check the data and try again.") from exception
if exception.status_code == 404:
raise ResourceNotFoundError(
"Resource not found. "
f"Please check that the tier you are using, corresponds to the correct "
"Please check that the tier you are using, corresponds to the correct "
"endpoint and/or topic name."
) from exception
raise exception
Expand Down
3 changes: 2 additions & 1 deletion sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def __init__(
)

def __repr__(self) -> str:
return f"<EventGridConsumerClient: namespace_topic={self._namespace}, subscription={self._subscription}, credential type={type(self._credential)}>"
return f"<EventGridConsumerClient: namespace_topic={self._namespace}, \
subscription={self._subscription}, credential type={type(self._credential)}>"


def patch_sdk():
Expand Down

0 comments on commit 27c493e

Please sign in to comment.