Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
81 changes: 27 additions & 54 deletions sdk/cosmos/azure-cosmos/azure/cosmos/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ def GetHeaders( # pylint: disable=too-many-statements,too-many-branches
:param str resource_type:
:param dict options:
:param str partition_key_range_id:

:return:
The HTTP request headers.
:return: The HTTP request headers.
:rtype: dict
"""
headers = dict(default_headers)
Expand Down Expand Up @@ -302,9 +300,7 @@ def GetResourceIdOrFullNameFromLink(resource_link):
"""Gets resource id or full name from resource link.

:param str resource_link:

:return:
The resource id or full name from the resource link.
:return: The resource id or full name from the resource link.
:rtype: str
"""
# For named based, the resource link is the full name
Expand Down Expand Up @@ -354,9 +350,7 @@ def GetPathFromLink(resource_link, resource_type=""):

:param str resource_link:
:param str resource_type:

:return:
Path from resource link with resource type appended (if provided).
:return: Path from resource link with resource type appended (if provided).
:rtype: str
"""
resource_link = TrimBeginningAndEndingSlashes(resource_link)
Expand Down Expand Up @@ -427,11 +421,8 @@ def IsMasterResource(resourceType):
def IsDatabaseLink(link):
"""Finds whether the link is a database Self Link or a database ID based link

:param str link:
Link to analyze

:return:
True or False.
:param str link: Link to analyze
:return: True or False.
:rtype: boolean
"""
if not link:
Expand Down Expand Up @@ -460,11 +451,8 @@ def IsDatabaseLink(link):
def IsItemContainerLink(link): # pylint: disable=too-many-return-statements
"""Finds whether the link is a document colllection Self Link or a document colllection ID based link

:param str link:
Link to analyze

:return:
True or False.
:param str link: Link to analyze
:return: True or False.
:rtype: boolean
"""
if not link:
Expand Down Expand Up @@ -499,24 +487,21 @@ def IsItemContainerLink(link): # pylint: disable=too-many-return-statements


def GetItemContainerInfo(self_link, alt_content_path, id_from_response):
""" Given the self link and alt_content_path from the reponse header and result
extract the collection name and collection id
"""Given the self link and alt_content_path from the reponse header and
result extract the collection name and collection id.

Ever response header has alt-content-path that is the
owner's path in ascii. For document create / update requests, this can be used
to get the collection name, but for collection create response, we can't use it.
So we also rely on
Every response header has an alt-content-path that is the owner's path in
ASCII. For document create / update requests, this can be used to get the
collection name, but for collection create response, we can't use it.

:param str self_link:
Self link of the resource, as obtained from response result.
:param str alt_content_path:
Owner path of the resource, as obtained from response header.
:param str resource_id:
'id' as returned from the response result. This is only used if it is deduced that the
request was to create a collection.

:return:
tuple of (collection rid, collection name)
'id' as returned from the response result. This is only used if it is
deduced that the request was to create a collection.
:return: tuple of (collection rid, collection name)
:rtype: tuple
"""

Expand Down Expand Up @@ -545,15 +530,11 @@ def GetItemContainerInfo(self_link, alt_content_path, id_from_response):


def GetItemContainerLink(link):
"""Gets the document collection link

:param str link:
Resource link
"""Gets the document collection link.

:return:
Document collection link.
:param str link: Resource link
:return: Document collection link.
:rtype: str

"""
link = TrimBeginningAndEndingSlashes(link) + "/"

Expand All @@ -565,19 +546,13 @@ def GetItemContainerLink(link):


def IndexOfNth(s, value, n):
"""Gets the index of Nth occurance of a given character in a string
"""Gets the index of Nth occurance of a given character in a string.

:param str s:
Input string
:param char value:
Input char to be searched.
:param int n:
Nth occurrence of char to be searched.

:return:
Index of the Nth occurrence in the string.
:param str s: Input string
:param char value: Input char to be searched.
:param int n: Nth occurrence of char to be searched.
:return: Index of the Nth occurrence in the string.
:rtype: int

"""
remaining = n
for i, elt in enumerate(s):
Expand All @@ -589,13 +564,11 @@ def IndexOfNth(s, value, n):


def IsValidBase64String(string_to_validate):
"""Verifies if a string is a valid Base64 encoded string, after replacing '-' with '/'
"""Verifies if a string is a valid Base64 encoded string, after
replacing '-' with '/'

:param string string_to_validate:
String to validate.

:return:
Whether given string is a valid base64 string or not.
:param string string_to_validate: String to validate.
:return: Whether given string is a valid base64 string or not.
:rtype: str
"""
# '-' is not supported char for decoding in Python(same as C# and Java) which has
Expand Down
16 changes: 8 additions & 8 deletions sdk/cosmos/azure-cosmos/azure/cosmos/_consistent_hash_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,14 @@ def __init__(self, collection_links, partitions_per_node, hash_generator):
self.partitions = self._ConstructPartitions(self.collection_links, partitions_per_node)

def GetCollectionNode(self, partition_key):
"""Gets the SelfLink/ID based link of the collection node that maps to the partition key
based on the hashing algorithm used for finding the node in the ring.
"""Gets the SelfLink/ID based link of the collection node that maps to
the partition key based on the hashing algorithm used for finding the
node in the ring.

:param str partition_key:
The partition key to be used for finding the node in the ring.

:return:
The name of the collection mapped to that partition.
:return: The name of the collection mapped to that partition.
:rtype: str

"""
if partition_key is None:
raise ValueError("partition_key is None or empty.")
Expand All @@ -76,8 +74,9 @@ def GetCollectionNode(self, partition_key):
return self.partitions[partition_number].GetNode()

def _ConstructPartitions(self, collection_links, partitions_per_node):
"""Constructs the partitions in the consistent ring by assigning them to collection nodes
using the hashing algorithm and then finally sorting the partitions based on the hash value.
"""Constructs the partitions in the consistent ring by assigning them to
collection nodes using the hashing algorithm and then finally sorting
the partitions based on the hash value.
"""
collections_node_count = len(collection_links)
partitions = [_partition.Partition() for _ in xrange(0, partitions_per_node * collections_node_count)]
Expand All @@ -101,6 +100,7 @@ def _FindPartition(self, key):

def _GetSerializedPartitionList(self):
"""Gets the serialized version of the ConsistentRing.

Added this helper for the test code.
"""
partition_list = list()
Expand Down
27 changes: 14 additions & 13 deletions sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,14 @@ def __init__(

@property
def Session(self):
""" Gets the session object from the client """
"""Gets the session object from the client. """
return self.session

@Session.setter
def Session(self, session):
""" Sets a session object on the document client
This will override the existing session
"""Sets a session object on the document client.

This will override the existing session
"""
self.session = session

Expand Down Expand Up @@ -1305,7 +1306,7 @@ def ReadTrigger(self, trigger_link, options=None, **kwargs):
return self.Read(path, "triggers", trigger_id, None, options, **kwargs)

def ReadUserDefinedFunctions(self, collection_link, options=None, **kwargs):
"""Reads all user defined functions in a collection.
"""Reads all user-defined functions in a collection.

:param str collection_link:
The link to the document collection.
Expand All @@ -1324,7 +1325,7 @@ def ReadUserDefinedFunctions(self, collection_link, options=None, **kwargs):
return self.QueryUserDefinedFunctions(collection_link, None, options, **kwargs)

def QueryUserDefinedFunctions(self, collection_link, query, options=None, **kwargs):
"""Queries user defined functions in a collection.
"""Queries user-defined functions in a collection.

:param str collection_link:
The link to the collection.
Expand Down Expand Up @@ -1358,7 +1359,7 @@ def fetch_fn(options):
)

def CreateUserDefinedFunction(self, collection_link, udf, options=None, **kwargs):
"""Creates a user defined function in a collection.
"""Creates a user-defined function in a collection.

:param str collection_link:
The link to the collection.
Expand All @@ -1379,7 +1380,7 @@ def CreateUserDefinedFunction(self, collection_link, udf, options=None, **kwargs
return self.Create(udf, path, "udfs", collection_id, None, options, **kwargs)

def UpsertUserDefinedFunction(self, collection_link, udf, options=None, **kwargs):
"""Upserts a user defined function in a collection.
"""Upserts a user-defined function in a collection.

:param str collection_link:
The link to the collection.
Expand Down Expand Up @@ -1412,10 +1413,10 @@ def _GetContainerIdWithPathForUDF(self, collection_link, udf): # pylint: disabl
return collection_id, path, udf

def ReadUserDefinedFunction(self, udf_link, options=None, **kwargs):
"""Reads a user defined function.
"""Reads a user-defined function.

:param str udf_link:
The link to the user defined function.
The link to the user-defined function.
:param dict options:
The request options for the request.

Expand Down Expand Up @@ -1759,10 +1760,10 @@ def DeleteTrigger(self, trigger_link, options=None, **kwargs):
return self.DeleteResource(path, "triggers", trigger_id, None, options, **kwargs)

def ReplaceUserDefinedFunction(self, udf_link, udf, options=None, **kwargs):
"""Replaces a user defined function and returns it.
"""Replaces a user-defined function and returns it.

:param str udf_link:
The link to the user defined function.
The link to the user-defined function.
:param dict udf:
:param dict options:
The request options for the request.
Expand All @@ -1788,10 +1789,10 @@ def ReplaceUserDefinedFunction(self, udf_link, udf, options=None, **kwargs):
return self.Replace(udf, path, "udfs", udf_id, None, options, **kwargs)

def DeleteUserDefinedFunction(self, udf_link, options=None, **kwargs):
"""Deletes a user defined function.
"""Deletes a user-defined function.

:param str udf_link:
The link to the user defined function.
The link to the user-defined function.
:param dict options:
The request options for the request.

Expand Down
7 changes: 3 additions & 4 deletions sdk/cosmos/azure-cosmos/azure/cosmos/_default_retry_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""Internal class for connection reset retry policy implementation in the Azure Cosmos database service.
"""Internal class for connection reset retry policy implementation in the Azure
Cosmos database service.
"""
from . import http_constants

Expand Down Expand Up @@ -68,9 +69,7 @@ def ShouldRetry(self, exception):
"""Returns true if should retry based on the passed-in exception.

:param (exceptions.CosmosHttpResponseError instance) exception:

:rtype:
boolean
:rtype: boolean

"""
if (self.current_retry_attempt_count < self._max_retry_attempt_count) and self.needsRetry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""Internal class for endpoint discovery retry policy implementation in the Azure Cosmos database service.
"""Internal class for endpoint discovery retry policy implementation in the
Azure Cosmos database service.
"""

import logging
Expand Down Expand Up @@ -62,9 +63,7 @@ def ShouldRetry(self, exception): # pylint: disable=unused-argument
"""Returns true if should retry based on the passed-in exception.

:param (exceptions.CosmosHttpResponseError instance) exception:

:rtype:
boolean
:rtype: boolean

"""
if not self.connection_policy.EnableEndpointDiscovery:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""Internal class for aggregation queries implementation in the Azure Cosmos database service.
"""Internal class for aggregation queries implementation in the Azure Cosmos
database service.
"""
from abc import abstractmethod, ABCMeta
from azure.cosmos._execution_context.document_producer import _OrderByHelper
Expand Down
Loading