Skip to content

Commit

Permalink
Revert "context: Implement asynchronous context manager"
Browse files Browse the repository at this point in the history
This reverts commit a456d7b as it broke
applications. Asynchronous context managers will be reinstated with a
new (possibly just `async with Context(server=...) as ctx:`) call at a
later time.

Closes: #271
  • Loading branch information
chrysn committed Aug 17, 2022
1 parent 0b35b6e commit 38a2f0b
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 65 deletions.
2 changes: 0 additions & 2 deletions aiocoap/cli/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
from pathlib import Path

from ..util import hostportsplit
from ..util.asyncio.coro_or_contextmanager import AwaitOrAenter
from ..protocol import Context
from ..credentials import CredentialsMap

Expand Down Expand Up @@ -104,7 +103,6 @@ def extract_server_arguments(namespace):

return server_arguments

@AwaitOrAenter.decorate
async def server_context_from_arguments(site, namespace, **kwargs):
"""Create a bound context like
:meth:`.aiocoap.Context.create_server_context`, but take the bind and TLS
Expand Down
28 changes: 0 additions & 28 deletions aiocoap/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from . import error
from .numbers import (INTERNAL_SERVER_ERROR, NOT_FOUND,
CONTINUE, OBSERVATION_RESET_TIME)
from .util.asyncio.coro_or_contextmanager import AwaitOrAenter
from .util.asyncio import py38args

import warnings
Expand Down Expand Up @@ -79,12 +78,6 @@ class Context(interfaces.RequestProvider):
:meth:`.shutdown()`, but typical applications will not need to because
they use the context for the full process lifetime.
The context creation functions also work as `asynchronous context
managers`__, shutting down the (aiocoap) context when the (Python) context
ends.
.. __: https://docs.python.org/3/reference/datamodel.html#async-context-managers
.. automethod:: create_client_context
.. automethod:: create_server_context
Expand Down Expand Up @@ -124,20 +117,6 @@ def __init__(self, loop=None, serversite=None, loggername="coap", client_credent
self.client_credentials = client_credentials or CredentialsMap()
self.server_credentials = server_credentials or CredentialsMap()

#
# Asynchronous context manager
#

async def __aenter__(self):
# Note that this is usually not called that way; the more common idiom
# is `async with Context.create_client_context()` which returns a
# future that also has an __aenter__ method.

return self

async def __aexit__(self, exc_type, exc, tb):
await self.shutdown()

#
# convenience methods for class instanciation
#
Expand All @@ -161,17 +140,11 @@ async def _append_tokenmanaged_transport(self, token_interface_constructor):
self.request_interfaces.append(tman)

@classmethod
@AwaitOrAenter.decorate
async def create_client_context(cls, *, loggername="coap", loop=None, transports: Optional[List[str]] = None):
"""Create a context bound to all addresses on a random listening port.
This is the easiest way to get a context suitable for sending client
requests.
Note that while this looks in the documentation like a function rather
than an asynchronous function, it does return an awaitable; the way it
is set up allows using the result as an asynchronous context manager as
well.
"""

if loop is None:
Expand Down Expand Up @@ -218,7 +191,6 @@ async def create_client_context(cls, *, loggername="coap", loop=None, transports
return self

@classmethod
@AwaitOrAenter.decorate
async def create_server_context(cls, site, bind=None, *, loggername="coap-server", loop=None, _ssl_context=None, multicast=[], server_credentials=None, transports: Optional[List[str]] = None):
"""Create a context, bound to all addresses on the CoAP port (unless
otherwise specified in the ``bind`` argument).
Expand Down
35 changes: 0 additions & 35 deletions aiocoap/util/asyncio/coro_or_contextmanager.py

This file was deleted.

0 comments on commit 38a2f0b

Please sign in to comment.