Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
ec73729
[EGv2] Build Release (#30325)
l0lawrence May 19, 2023
c7188d3
Beta LiveTests (#30728)
l0lawrence Aug 25, 2023
7e5003c
[EGv2] Build Release (#30325)
l0lawrence May 19, 2023
951a9d8
fix merge
l0lawrence Oct 5, 2023
69d253b
dont go to generated before binary
l0lawrence Oct 5, 2023
000e3b3
update patch
l0lawrence Oct 12, 2023
97fb553
update patches
l0lawrence Oct 12, 2023
2e7bb32
eventgrid client patch
l0lawrence Oct 12, 2023
028484f
changes
l0lawrence Oct 12, 2023
503c9e8
add
l0lawrence Oct 12, 2023
92df675
update test
l0lawrence Oct 12, 2023
c2b9eed
update tyoe checking
l0lawrence Oct 13, 2023
31f0c02
pass through binary_mode for now --
l0lawrence Oct 13, 2023
67a7279
update patch aio
l0lawrence Oct 13, 2023
54b2c43
add async func
l0lawrence Oct 16, 2023
2bcb97f
update
l0lawrence Oct 16, 2023
7a650bb
sys
l0lawrence Oct 16, 2023
db034eb
update kwargs
l0lawrence Oct 16, 2023
e83ac70
add Todo and start adding more tests
l0lawrence Oct 17, 2023
0ec4a3a
update
l0lawrence Oct 17, 2023
8647028
differentiate between binary and not
l0lawrence Oct 17, 2023
2e3b639
update binary
l0lawrence Oct 17, 2023
3a1b72a
no base64 in binary mode
l0lawrence Oct 17, 2023
110f3f1
binary
l0lawrence Oct 17, 2023
015d1f4
try JSONEncoder on everything if not str/bytes
l0lawrence Oct 18, 2023
13f0ae3
update test
l0lawrence Oct 18, 2023
79dba1b
update test
l0lawrence Oct 20, 2023
47148f5
update changes
l0lawrence Oct 23, 2023
0a1307d
whitespace
l0lawrence Oct 23, 2023
9ca6f1d
space
l0lawrence Oct 23, 2023
52845d3
remove commented
l0lawrence Oct 23, 2023
fb53f33
str serialize extensions?
l0lawrence Oct 23, 2023
74c434d
xml test
l0lawrence Oct 23, 2023
cec8eaf
encode extensions as object
l0lawrence Oct 23, 2023
08eacb6
update test
l0lawrence Oct 23, 2023
fd002c1
update extension serialization for deserialize
l0lawrence Oct 23, 2023
dec4248
move flag to operation level
l0lawrence Oct 25, 2023
4eb1876
extra comma
l0lawrence Oct 25, 2023
60ff404
dont raise httpresponse
l0lawrence Oct 25, 2023
2b17321
update patch
l0lawrence Oct 25, 2023
6fe171d
accept dict cloud events
l0lawrence Oct 26, 2023
bb8ba88
spacing
l0lawrence Oct 26, 2023
633166e
remove content_type check
l0lawrence Oct 26, 2023
3b37f20
add live test
l0lawrence Oct 26, 2023
6b50b87
remove live test mark
l0lawrence Oct 27, 2023
bc997b2
update
l0lawrence Oct 27, 2023
efb5911
use env vars
l0lawrence Oct 27, 2023
4e046c8
update test
l0lawrence Oct 27, 2023
7db3968
only run live test
l0lawrence Oct 27, 2023
1d74cda
comment
l0lawrence Oct 30, 2023
0abd334
typo
l0lawrence Oct 31, 2023
9495362
error incorrect
l0lawrence Oct 31, 2023
58bd912
start comments
l0lawrence Nov 1, 2023
205758e
update test
l0lawrence Nov 1, 2023
67ac8d2
add sample
l0lawrence Nov 1, 2023
35ecda1
update tests
l0lawrence Nov 1, 2023
6611e67
update docstrings to add clarity
l0lawrence Nov 2, 2023
5016b76
update err message
l0lawrence Nov 2, 2023
1f07d6f
remove generated cloud event
l0lawrence Nov 2, 2023
dac9cf0
update sample
l0lawrence Nov 2, 2023
fc52a69
update
l0lawrence Nov 2, 2023
502c371
update samples to include dict
l0lawrence Nov 2, 2023
9a9c4b1
update patch
l0lawrence Nov 2, 2023
ba01c09
spacing
l0lawrence Nov 2, 2023
6bcbb77
add comments
l0lawrence Nov 2, 2023
464cd6b
formatting
l0lawrence Nov 2, 2023
8d0bbe6
update doc
l0lawrence Nov 2, 2023
ee013cc
update tests
l0lawrence Nov 2, 2023
5b0beac
update tests
l0lawrence Nov 2, 2023
3bf9dd2
tests
l0lawrence Nov 2, 2023
5c47708
skip tests for now
l0lawrence Nov 2, 2023
eeb1aaf
typo
l0lawrence Nov 3, 2023
df23b8b
add dict binary mode
l0lawrence Nov 3, 2023
b5b5236
update docstring
l0lawrence Nov 3, 2023
b21b5e6
update patch to allow throw error
l0lawrence Nov 3, 2023
11f9560
first pass at comments
l0lawrence Nov 3, 2023
89e889d
update patch eror
l0lawrence Nov 3, 2023
f3546d9
nit
l0lawrence Nov 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add async func
  • Loading branch information
l0lawrence committed Nov 2, 2023
commit 54b2c433f4c973651e6101af8049c0faed104ab0
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,27 @@
"""Customize generated code here.
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
"""
from typing import List, overload, Union, Any, Optional
from typing import List, overload, Union, Any, Optional, Callable, Dict, TypeVar
from azure.core.messaging import CloudEvent
from azure.core.exceptions import HttpResponseError
from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, map_error
from azure.core.tracing.decorator_async import distributed_trace_async
from azure.core.pipeline import PipelineResponse
from azure.core.rest import HttpRequest, AsyncHttpResponse
from azure.core.utils import case_insensitive_dict
from ...models._patch import ReceiveResult, ReceiveDetails
from ..._operations._patch import _cloud_event_to_generated, EventGridClient
from ..._operations._patch import _cloud_event_to_generated, _to_http_request
from ._operations import EventGridClientOperationsMixin as OperationsMixin

from .. import models as _models
from .._model_base import AzureJSONEncoder, _deserialize
from .._serialization import Serializer
from .._vendor import EventGridClientMixinABC
if sys.version_info >= (3, 9):
from collections.abc import MutableMapping
else:
from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports
JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object
T = TypeVar('T')
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]]

class EventGridClientOperationsMixin(OperationsMixin):
@overload
Expand Down Expand Up @@ -99,7 +112,7 @@ async def publish_cloud_events(
if isinstance(body, CloudEvent):
kwargs["content_type"] = "application/cloudevents+json; charset=utf-8"
if self._binary_mode:
EventGridClient._publish_binary_mode(topic_name, body, self._config.api_version, **kwargs)
self._publish_binary_mode(topic_name, body, self._config.api_version, **kwargs)
internal_body = _cloud_event_to_generated(body)
await self._publish_cloud_event(topic_name, internal_body, **kwargs)
else:
Expand Down Expand Up @@ -163,6 +176,68 @@ async def receive_cloud_events(
receive_result_deserialized = ReceiveResult(value=detail_items)
return receive_result_deserialized

def _publish_binary_mode(self, topic_name: str, event: Any, api_version, **kwargs: Any) -> None:

error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, 304: ResourceNotModifiedError
}
error_map.update(kwargs.pop('error_map', {}) or {})

_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
_params = kwargs.pop("params", {}) or {}

cls: ClsType[_models._models.PublishResult] = kwargs.pop( # pylint: disable=protected-access
'cls', None
)

content_type: str = kwargs.pop('content_type', _headers.pop('content-type', "application/cloudevents+json; charset=utf-8"))

# Given that we know the cloud event is binary mode, we can convert it to a HTTP request
http_request = _to_http_request(
topic_name=topic_name,
api_version=api_version,
headers=_headers,
params=_params,
content_type=content_type,
event=event,
**kwargs
)

_stream = kwargs.pop("stream", False)

path_format_arguments = {
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
http_request.url = self._client.format_url(http_request.url, **path_format_arguments)

# pipeline_response: PipelineResponse = self.send_request(http_request, **kwargs)
pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
http_request,
stream=_stream,
**kwargs
)

response = pipeline_response.http_response

if response.status_code not in [200]:
if _stream:
response.read() # Load the body in memory and close the socket
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)

if _stream:
deserialized = response.iter_bytes()
else:
deserialized = _deserialize(
_models._models.PublishResult, # pylint: disable=protected-access
response.json()
)

if cls:
return cls(pipeline_response, deserialized, {}) # type: ignore

return deserialized # type: ignore


__all__: List[str] = [
"EventGridClientOperationsMixin"
Expand Down