diff --git a/sdk/cosmos/azure-cosmos/README.md b/sdk/cosmos/azure-cosmos/README.md index 9930ae0530a5..7c29d7a73df7 100644 --- a/sdk/cosmos/azure-cosmos/README.md +++ b/sdk/cosmos/azure-cosmos/README.md @@ -468,7 +468,7 @@ For more information on TTL, see [Time to Live for Azure Cosmos DB data][cosmos_ ### Using the asynchronous client (Preview) The asynchronous cosmos client is a separate client that looks and works in a similar fashion to the existing synchronous client. However, the async client needs to be imported separately and its methods need to be used with the async/await keywords. -The Async client needs to be initialized and closed after usage. The example below shows how to do so by using the client's __aenter__() and close() methods. +The Async client needs to be initialized and closed after usage, which can be done manually or with the use of a context manager. The example below shows how to do so manually. ```Python from azure.cosmos.aio import CosmosClient @@ -481,7 +481,6 @@ CONTAINER_NAME = 'products' async def create_products(): client = CosmosClient(URL, credential=KEY) - await client.__aenter__() database = client.get_database_client(DATABASE_NAME) container = database.get_container_client(CONTAINER_NAME) for i in range(10): diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py b/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py index aacafbd41458..b99a569fc1e9 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/_base.py @@ -242,7 +242,7 @@ def GetHeaders( # pylint: disable=too-many-statements,too-many-branches headers[http_constants.HttpHeaders.XDate] = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT") if cosmos_client_connection.master_key or cosmos_client_connection.resource_tokens: - authorization = auth.get_authorization_header( + authorization = auth._get_authorization_header( cosmos_client_connection, verb, path, resource_id, IsNameBased(resource_id), resource_type, headers ) # urllib.quote throws when the input parameter is None diff --git a/sdk/cosmos/azure-cosmos/azure/cosmos/auth.py b/sdk/cosmos/azure-cosmos/azure/cosmos/auth.py index 7c239ccec7ac..cca10023ca5f 100644 --- a/sdk/cosmos/azure-cosmos/azure/cosmos/auth.py +++ b/sdk/cosmos/azure-cosmos/azure/cosmos/auth.py @@ -36,11 +36,11 @@ def GetAuthorizationHeader( warnings.warn("This method has been deprecated and will be removed from the SDK in a future release.", DeprecationWarning) - return get_authorization_header( + return _get_authorization_header( cosmos_client_connection, verb, path, resource_id_or_fullname, is_name_based, resource_type, headers) -def get_authorization_header( +def _get_authorization_header( cosmos_client_connection, verb, path, resource_id_or_fullname, is_name_based, resource_type, headers ): """Gets the authorization header. diff --git a/sdk/cosmos/azure-cosmos/samples/examples_async.py b/sdk/cosmos/azure-cosmos/samples/examples_async.py index 97edcd7c9519..88a714fef0c4 100644 --- a/sdk/cosmos/azure-cosmos/samples/examples_async.py +++ b/sdk/cosmos/azure-cosmos/samples/examples_async.py @@ -19,16 +19,7 @@ async def examples_async(): # which can only be used within async methods like examples_async() here # Since this is an asynchronous client, in order to properly use it you also have to warm it up and close it down. - # One way to do it would be like below (all of these statements would be necessary if you want to do it this way). - - async_client = CosmosClient(url, key) - await async_client.__aenter__() - - # [CODE LOGIC HERE, CLOSING WITH THE STATEMENT BELOW WHEN DONE] - - await async_client.close() - - # Or better, you can use the `async with` keywords like below to start your clients - these keywords + # We recommend using the `async with` keywords like below to start your clients - these keywords # create a context manager that automatically warms up, initializes, and cleans up the client, so you don't have to. # [START create_client]