id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
229,500
Azure/azure-cosmos-python
azure/cosmos/range_partition_resolver.py
RangePartitionResolver._GetContainingRange
def _GetContainingRange(self, partition_key): """Gets the containing range based on the partition key. """ for keyrange in self.partition_map.keys(): if keyrange.Contains(partition_key): return keyrange return None
python
def _GetContainingRange(self, partition_key): """Gets the containing range based on the partition key. """ for keyrange in self.partition_map.keys(): if keyrange.Contains(partition_key): return keyrange return None
[ "def", "_GetContainingRange", "(", "self", ",", "partition_key", ")", ":", "for", "keyrange", "in", "self", ".", "partition_map", ".", "keys", "(", ")", ":", "if", "keyrange", ".", "Contains", "(", "partition_key", ")", ":", "return", "keyrange", "return", "None" ]
Gets the containing range based on the partition key.
[ "Gets", "the", "containing", "range", "based", "on", "the", "partition", "key", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/range_partition_resolver.py#L87-L94
229,501
Azure/azure-cosmos-python
azure/cosmos/range_partition_resolver.py
RangePartitionResolver._GetIntersectingRanges
def _GetIntersectingRanges(self, partition_key): """Gets the intersecting ranges based on the partition key. """ partitionkey_ranges = set() intersecting_ranges = set() if partition_key is None: return list(self.partition_map.keys()) if isinstance(partition_key, prange.Range): partitionkey_ranges.add(partition_key) elif isinstance(partition_key, list): for key in partition_key: if key is None: return list(self.partition_map.keys()) elif isinstance(key, prange.Range): partitionkey_ranges.add(key) else: partitionkey_ranges.add(prange.Range(key, key)) else: partitionkey_ranges.add(prange.Range(partition_key, partition_key)) for partitionKeyRange in partitionkey_ranges: for keyrange in self.partition_map.keys(): if keyrange.Intersect(partitionKeyRange): intersecting_ranges.add(keyrange) return intersecting_ranges
python
def _GetIntersectingRanges(self, partition_key): """Gets the intersecting ranges based on the partition key. """ partitionkey_ranges = set() intersecting_ranges = set() if partition_key is None: return list(self.partition_map.keys()) if isinstance(partition_key, prange.Range): partitionkey_ranges.add(partition_key) elif isinstance(partition_key, list): for key in partition_key: if key is None: return list(self.partition_map.keys()) elif isinstance(key, prange.Range): partitionkey_ranges.add(key) else: partitionkey_ranges.add(prange.Range(key, key)) else: partitionkey_ranges.add(prange.Range(partition_key, partition_key)) for partitionKeyRange in partitionkey_ranges: for keyrange in self.partition_map.keys(): if keyrange.Intersect(partitionKeyRange): intersecting_ranges.add(keyrange) return intersecting_ranges
[ "def", "_GetIntersectingRanges", "(", "self", ",", "partition_key", ")", ":", "partitionkey_ranges", "=", "set", "(", ")", "intersecting_ranges", "=", "set", "(", ")", "if", "partition_key", "is", "None", ":", "return", "list", "(", "self", ".", "partition_map", ".", "keys", "(", ")", ")", "if", "isinstance", "(", "partition_key", ",", "prange", ".", "Range", ")", ":", "partitionkey_ranges", ".", "add", "(", "partition_key", ")", "elif", "isinstance", "(", "partition_key", ",", "list", ")", ":", "for", "key", "in", "partition_key", ":", "if", "key", "is", "None", ":", "return", "list", "(", "self", ".", "partition_map", ".", "keys", "(", ")", ")", "elif", "isinstance", "(", "key", ",", "prange", ".", "Range", ")", ":", "partitionkey_ranges", ".", "add", "(", "key", ")", "else", ":", "partitionkey_ranges", ".", "add", "(", "prange", ".", "Range", "(", "key", ",", "key", ")", ")", "else", ":", "partitionkey_ranges", ".", "add", "(", "prange", ".", "Range", "(", "partition_key", ",", "partition_key", ")", ")", "for", "partitionKeyRange", "in", "partitionkey_ranges", ":", "for", "keyrange", "in", "self", ".", "partition_map", ".", "keys", "(", ")", ":", "if", "keyrange", ".", "Intersect", "(", "partitionKeyRange", ")", ":", "intersecting_ranges", ".", "add", "(", "keyrange", ")", "return", "intersecting_ranges" ]
Gets the intersecting ranges based on the partition key.
[ "Gets", "the", "intersecting", "ranges", "based", "on", "the", "partition", "key", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/range_partition_resolver.py#L96-L123
229,502
Azure/azure-cosmos-python
azure/cosmos/query_iterable.py
QueryIterable._create_execution_context
def _create_execution_context(self): """instantiates the internal query execution context based. """ if hasattr(self, '_database_link'): # client side partitioning query return base_execution_context._MultiCollectionQueryExecutionContext(self._client, self._options, self._database_link, self._query, self._partition_key) else: # return execution_dispatcher._ProxyQueryExecutionContext(self._client, self._collection_link, self._query, self._options, self._fetch_function)
python
def _create_execution_context(self): """instantiates the internal query execution context based. """ if hasattr(self, '_database_link'): # client side partitioning query return base_execution_context._MultiCollectionQueryExecutionContext(self._client, self._options, self._database_link, self._query, self._partition_key) else: # return execution_dispatcher._ProxyQueryExecutionContext(self._client, self._collection_link, self._query, self._options, self._fetch_function)
[ "def", "_create_execution_context", "(", "self", ")", ":", "if", "hasattr", "(", "self", ",", "'_database_link'", ")", ":", "# client side partitioning query", "return", "base_execution_context", ".", "_MultiCollectionQueryExecutionContext", "(", "self", ".", "_client", ",", "self", ".", "_options", ",", "self", ".", "_database_link", ",", "self", ".", "_query", ",", "self", ".", "_partition_key", ")", "else", ":", "# ", "return", "execution_dispatcher", ".", "_ProxyQueryExecutionContext", "(", "self", ".", "_client", ",", "self", ".", "_collection_link", ",", "self", ".", "_query", ",", "self", ".", "_options", ",", "self", ".", "_fetch_function", ")" ]
instantiates the internal query execution context based.
[ "instantiates", "the", "internal", "query", "execution", "context", "based", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/query_iterable.py#L87-L95
229,503
Azure/azure-cosmos-python
azure/cosmos/retry_utility.py
_Execute
def _Execute(client, global_endpoint_manager, function, *args, **kwargs): """Exectutes the function with passed parameters applying all retry policies :param object client: Document client instance :param object global_endpoint_manager: Instance of _GlobalEndpointManager class :param function function: Function to be called wrapped with retries :param (non-keyworded, variable number of arguments list) *args: :param (keyworded, variable number of arguments list) **kwargs: """ # instantiate all retry policies here to be applied for each request execution endpointDiscovery_retry_policy = endpoint_discovery_retry_policy._EndpointDiscoveryRetryPolicy(client.connection_policy, global_endpoint_manager, *args) resourceThrottle_retry_policy = resource_throttle_retry_policy._ResourceThrottleRetryPolicy(client.connection_policy.RetryOptions.MaxRetryAttemptCount, client.connection_policy.RetryOptions.FixedRetryIntervalInMilliseconds, client.connection_policy.RetryOptions.MaxWaitTimeInSeconds) defaultRetry_policy = default_retry_policy._DefaultRetryPolicy(*args) sessionRetry_policy = session_retry_policy._SessionRetryPolicy(client.connection_policy.EnableEndpointDiscovery, global_endpoint_manager, *args) while True: try: if args: result = _ExecuteFunction(function, global_endpoint_manager, *args, **kwargs) else: result = _ExecuteFunction(function, *args, **kwargs) if not client.last_response_headers: client.last_response_headers = {} # setting the throttle related response headers before returning the result client.last_response_headers[HttpHeaders.ThrottleRetryCount] = resourceThrottle_retry_policy.current_retry_attempt_count client.last_response_headers[HttpHeaders.ThrottleRetryWaitTimeInMs] = resourceThrottle_retry_policy.cummulative_wait_time_in_milliseconds return result except errors.HTTPFailure as e: retry_policy = None if (e.status_code == StatusCodes.FORBIDDEN and e.sub_status == SubStatusCodes.WRITE_FORBIDDEN): retry_policy = endpointDiscovery_retry_policy elif e.status_code == StatusCodes.TOO_MANY_REQUESTS: retry_policy = resourceThrottle_retry_policy elif e.status_code == StatusCodes.NOT_FOUND and e.sub_status and e.sub_status == SubStatusCodes.READ_SESSION_NOTAVAILABLE: retry_policy = sessionRetry_policy else: retry_policy = defaultRetry_policy # If none of the retry policies applies or there is no retry needed, set the throttle related response hedaers and # re-throw the exception back # arg[0] is the request. It needs to be modified for write forbidden exception if not (retry_policy.ShouldRetry(e)): if not client.last_response_headers: client.last_response_headers = {} client.last_response_headers[HttpHeaders.ThrottleRetryCount] = resourceThrottle_retry_policy.current_retry_attempt_count client.last_response_headers[HttpHeaders.ThrottleRetryWaitTimeInMs] = resourceThrottle_retry_policy.cummulative_wait_time_in_milliseconds if len(args) > 0 and args[0].should_clear_session_token_on_session_read_failure: client.session.clear_session_token(client.last_response_headers) raise else: # Wait for retry_after_in_milliseconds time before the next retry time.sleep(retry_policy.retry_after_in_milliseconds / 1000.0)
python
def _Execute(client, global_endpoint_manager, function, *args, **kwargs): """Exectutes the function with passed parameters applying all retry policies :param object client: Document client instance :param object global_endpoint_manager: Instance of _GlobalEndpointManager class :param function function: Function to be called wrapped with retries :param (non-keyworded, variable number of arguments list) *args: :param (keyworded, variable number of arguments list) **kwargs: """ # instantiate all retry policies here to be applied for each request execution endpointDiscovery_retry_policy = endpoint_discovery_retry_policy._EndpointDiscoveryRetryPolicy(client.connection_policy, global_endpoint_manager, *args) resourceThrottle_retry_policy = resource_throttle_retry_policy._ResourceThrottleRetryPolicy(client.connection_policy.RetryOptions.MaxRetryAttemptCount, client.connection_policy.RetryOptions.FixedRetryIntervalInMilliseconds, client.connection_policy.RetryOptions.MaxWaitTimeInSeconds) defaultRetry_policy = default_retry_policy._DefaultRetryPolicy(*args) sessionRetry_policy = session_retry_policy._SessionRetryPolicy(client.connection_policy.EnableEndpointDiscovery, global_endpoint_manager, *args) while True: try: if args: result = _ExecuteFunction(function, global_endpoint_manager, *args, **kwargs) else: result = _ExecuteFunction(function, *args, **kwargs) if not client.last_response_headers: client.last_response_headers = {} # setting the throttle related response headers before returning the result client.last_response_headers[HttpHeaders.ThrottleRetryCount] = resourceThrottle_retry_policy.current_retry_attempt_count client.last_response_headers[HttpHeaders.ThrottleRetryWaitTimeInMs] = resourceThrottle_retry_policy.cummulative_wait_time_in_milliseconds return result except errors.HTTPFailure as e: retry_policy = None if (e.status_code == StatusCodes.FORBIDDEN and e.sub_status == SubStatusCodes.WRITE_FORBIDDEN): retry_policy = endpointDiscovery_retry_policy elif e.status_code == StatusCodes.TOO_MANY_REQUESTS: retry_policy = resourceThrottle_retry_policy elif e.status_code == StatusCodes.NOT_FOUND and e.sub_status and e.sub_status == SubStatusCodes.READ_SESSION_NOTAVAILABLE: retry_policy = sessionRetry_policy else: retry_policy = defaultRetry_policy # If none of the retry policies applies or there is no retry needed, set the throttle related response hedaers and # re-throw the exception back # arg[0] is the request. It needs to be modified for write forbidden exception if not (retry_policy.ShouldRetry(e)): if not client.last_response_headers: client.last_response_headers = {} client.last_response_headers[HttpHeaders.ThrottleRetryCount] = resourceThrottle_retry_policy.current_retry_attempt_count client.last_response_headers[HttpHeaders.ThrottleRetryWaitTimeInMs] = resourceThrottle_retry_policy.cummulative_wait_time_in_milliseconds if len(args) > 0 and args[0].should_clear_session_token_on_session_read_failure: client.session.clear_session_token(client.last_response_headers) raise else: # Wait for retry_after_in_milliseconds time before the next retry time.sleep(retry_policy.retry_after_in_milliseconds / 1000.0)
[ "def", "_Execute", "(", "client", ",", "global_endpoint_manager", ",", "function", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# instantiate all retry policies here to be applied for each request execution", "endpointDiscovery_retry_policy", "=", "endpoint_discovery_retry_policy", ".", "_EndpointDiscoveryRetryPolicy", "(", "client", ".", "connection_policy", ",", "global_endpoint_manager", ",", "*", "args", ")", "resourceThrottle_retry_policy", "=", "resource_throttle_retry_policy", ".", "_ResourceThrottleRetryPolicy", "(", "client", ".", "connection_policy", ".", "RetryOptions", ".", "MaxRetryAttemptCount", ",", "client", ".", "connection_policy", ".", "RetryOptions", ".", "FixedRetryIntervalInMilliseconds", ",", "client", ".", "connection_policy", ".", "RetryOptions", ".", "MaxWaitTimeInSeconds", ")", "defaultRetry_policy", "=", "default_retry_policy", ".", "_DefaultRetryPolicy", "(", "*", "args", ")", "sessionRetry_policy", "=", "session_retry_policy", ".", "_SessionRetryPolicy", "(", "client", ".", "connection_policy", ".", "EnableEndpointDiscovery", ",", "global_endpoint_manager", ",", "*", "args", ")", "while", "True", ":", "try", ":", "if", "args", ":", "result", "=", "_ExecuteFunction", "(", "function", ",", "global_endpoint_manager", ",", "*", "args", ",", "*", "*", "kwargs", ")", "else", ":", "result", "=", "_ExecuteFunction", "(", "function", ",", "*", "args", ",", "*", "*", "kwargs", ")", "if", "not", "client", ".", "last_response_headers", ":", "client", ".", "last_response_headers", "=", "{", "}", "# setting the throttle related response headers before returning the result", "client", ".", "last_response_headers", "[", "HttpHeaders", ".", "ThrottleRetryCount", "]", "=", "resourceThrottle_retry_policy", ".", "current_retry_attempt_count", "client", ".", "last_response_headers", "[", "HttpHeaders", ".", "ThrottleRetryWaitTimeInMs", "]", "=", "resourceThrottle_retry_policy", ".", "cummulative_wait_time_in_milliseconds", "return", "result", "except", "errors", ".", "HTTPFailure", "as", "e", ":", "retry_policy", "=", "None", "if", "(", "e", ".", "status_code", "==", "StatusCodes", ".", "FORBIDDEN", "and", "e", ".", "sub_status", "==", "SubStatusCodes", ".", "WRITE_FORBIDDEN", ")", ":", "retry_policy", "=", "endpointDiscovery_retry_policy", "elif", "e", ".", "status_code", "==", "StatusCodes", ".", "TOO_MANY_REQUESTS", ":", "retry_policy", "=", "resourceThrottle_retry_policy", "elif", "e", ".", "status_code", "==", "StatusCodes", ".", "NOT_FOUND", "and", "e", ".", "sub_status", "and", "e", ".", "sub_status", "==", "SubStatusCodes", ".", "READ_SESSION_NOTAVAILABLE", ":", "retry_policy", "=", "sessionRetry_policy", "else", ":", "retry_policy", "=", "defaultRetry_policy", "# If none of the retry policies applies or there is no retry needed, set the throttle related response hedaers and ", "# re-throw the exception back", "# arg[0] is the request. It needs to be modified for write forbidden exception", "if", "not", "(", "retry_policy", ".", "ShouldRetry", "(", "e", ")", ")", ":", "if", "not", "client", ".", "last_response_headers", ":", "client", ".", "last_response_headers", "=", "{", "}", "client", ".", "last_response_headers", "[", "HttpHeaders", ".", "ThrottleRetryCount", "]", "=", "resourceThrottle_retry_policy", ".", "current_retry_attempt_count", "client", ".", "last_response_headers", "[", "HttpHeaders", ".", "ThrottleRetryWaitTimeInMs", "]", "=", "resourceThrottle_retry_policy", ".", "cummulative_wait_time_in_milliseconds", "if", "len", "(", "args", ")", ">", "0", "and", "args", "[", "0", "]", ".", "should_clear_session_token_on_session_read_failure", ":", "client", ".", "session", ".", "clear_session_token", "(", "client", ".", "last_response_headers", ")", "raise", "else", ":", "# Wait for retry_after_in_milliseconds time before the next retry", "time", ".", "sleep", "(", "retry_policy", ".", "retry_after_in_milliseconds", "/", "1000.0", ")" ]
Exectutes the function with passed parameters applying all retry policies :param object client: Document client instance :param object global_endpoint_manager: Instance of _GlobalEndpointManager class :param function function: Function to be called wrapped with retries :param (non-keyworded, variable number of arguments list) *args: :param (keyworded, variable number of arguments list) **kwargs:
[ "Exectutes", "the", "function", "with", "passed", "parameters", "applying", "all", "retry", "policies" ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/retry_utility.py#L34-L95
229,504
Azure/azure-cosmos-python
azure/cosmos/global_endpoint_manager.py
_GlobalEndpointManager._GetDatabaseAccount
def _GetDatabaseAccount(self): """Gets the database account first by using the default endpoint, and if that doesn't returns use the endpoints for the preferred locations in the order they are specified to get the database account. """ try: database_account = self._GetDatabaseAccountStub(self.DefaultEndpoint) return database_account # If for any reason(non-globaldb related), we are not able to get the database account from the above call to GetDatabaseAccount, # we would try to get this information from any of the preferred locations that the user might have specified(by creating a locational endpoint) # and keeping eating the exception until we get the database account and return None at the end, if we are not able to get that info from any endpoints except errors.HTTPFailure: for location_name in self.PreferredLocations: locational_endpoint = _GlobalEndpointManager.GetLocationalEndpoint(self.DefaultEndpoint, location_name) try: database_account = self._GetDatabaseAccountStub(locational_endpoint) return database_account except errors.HTTPFailure: pass return None
python
def _GetDatabaseAccount(self): """Gets the database account first by using the default endpoint, and if that doesn't returns use the endpoints for the preferred locations in the order they are specified to get the database account. """ try: database_account = self._GetDatabaseAccountStub(self.DefaultEndpoint) return database_account # If for any reason(non-globaldb related), we are not able to get the database account from the above call to GetDatabaseAccount, # we would try to get this information from any of the preferred locations that the user might have specified(by creating a locational endpoint) # and keeping eating the exception until we get the database account and return None at the end, if we are not able to get that info from any endpoints except errors.HTTPFailure: for location_name in self.PreferredLocations: locational_endpoint = _GlobalEndpointManager.GetLocationalEndpoint(self.DefaultEndpoint, location_name) try: database_account = self._GetDatabaseAccountStub(locational_endpoint) return database_account except errors.HTTPFailure: pass return None
[ "def", "_GetDatabaseAccount", "(", "self", ")", ":", "try", ":", "database_account", "=", "self", ".", "_GetDatabaseAccountStub", "(", "self", ".", "DefaultEndpoint", ")", "return", "database_account", "# If for any reason(non-globaldb related), we are not able to get the database account from the above call to GetDatabaseAccount,", "# we would try to get this information from any of the preferred locations that the user might have specified(by creating a locational endpoint)", "# and keeping eating the exception until we get the database account and return None at the end, if we are not able to get that info from any endpoints", "except", "errors", ".", "HTTPFailure", ":", "for", "location_name", "in", "self", ".", "PreferredLocations", ":", "locational_endpoint", "=", "_GlobalEndpointManager", ".", "GetLocationalEndpoint", "(", "self", ".", "DefaultEndpoint", ",", "location_name", ")", "try", ":", "database_account", "=", "self", ".", "_GetDatabaseAccountStub", "(", "locational_endpoint", ")", "return", "database_account", "except", "errors", ".", "HTTPFailure", ":", "pass", "return", "None" ]
Gets the database account first by using the default endpoint, and if that doesn't returns use the endpoints for the preferred locations in the order they are specified to get the database account.
[ "Gets", "the", "database", "account", "first", "by", "using", "the", "default", "endpoint", "and", "if", "that", "doesn", "t", "returns", "use", "the", "endpoints", "for", "the", "preferred", "locations", "in", "the", "order", "they", "are", "specified", "to", "get", "the", "database", "account", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/global_endpoint_manager.py#L104-L124
229,505
Azure/azure-cosmos-python
azure/cosmos/partition.py
_Partition.CompareTo
def CompareTo(self, other_hash_value): """Compares the passed hash value with the hash value of this object """ if len(self.hash_value) != len(other_hash_value): raise ValueError("Length of hashes doesn't match.") # The hash byte array that is returned from ComputeHash method has the MSB at the end of the array # so comparing the bytes from the end for compare operations. for i in xrange(0, len(self.hash_value)): if(self.hash_value[len(self.hash_value) - i - 1] < other_hash_value[len(self.hash_value) - i - 1]): return -1 elif self.hash_value[len(self.hash_value) - i - 1] > other_hash_value[len(self.hash_value) - i - 1]: return 1 return 0
python
def CompareTo(self, other_hash_value): """Compares the passed hash value with the hash value of this object """ if len(self.hash_value) != len(other_hash_value): raise ValueError("Length of hashes doesn't match.") # The hash byte array that is returned from ComputeHash method has the MSB at the end of the array # so comparing the bytes from the end for compare operations. for i in xrange(0, len(self.hash_value)): if(self.hash_value[len(self.hash_value) - i - 1] < other_hash_value[len(self.hash_value) - i - 1]): return -1 elif self.hash_value[len(self.hash_value) - i - 1] > other_hash_value[len(self.hash_value) - i - 1]: return 1 return 0
[ "def", "CompareTo", "(", "self", ",", "other_hash_value", ")", ":", "if", "len", "(", "self", ".", "hash_value", ")", "!=", "len", "(", "other_hash_value", ")", ":", "raise", "ValueError", "(", "\"Length of hashes doesn't match.\"", ")", "# The hash byte array that is returned from ComputeHash method has the MSB at the end of the array", "# so comparing the bytes from the end for compare operations.", "for", "i", "in", "xrange", "(", "0", ",", "len", "(", "self", ".", "hash_value", ")", ")", ":", "if", "(", "self", ".", "hash_value", "[", "len", "(", "self", ".", "hash_value", ")", "-", "i", "-", "1", "]", "<", "other_hash_value", "[", "len", "(", "self", ".", "hash_value", ")", "-", "i", "-", "1", "]", ")", ":", "return", "-", "1", "elif", "self", ".", "hash_value", "[", "len", "(", "self", ".", "hash_value", ")", "-", "i", "-", "1", "]", ">", "other_hash_value", "[", "len", "(", "self", ".", "hash_value", ")", "-", "i", "-", "1", "]", ":", "return", "1", "return", "0" ]
Compares the passed hash value with the hash value of this object
[ "Compares", "the", "passed", "hash", "value", "with", "the", "hash", "value", "of", "this", "object" ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/partition.py#L48-L61
229,506
Azure/azure-cosmos-python
azure/cosmos/murmur_hash.py
_MurmurHash.ComputeHash
def ComputeHash(self, key): """ Computes the hash of the value passed using MurmurHash3 algorithm. :param bytearray key: Byte array representing the key to be hashed. :return: 32 bit hash value. :rtype: int """ if key is None: raise ValueError("key is None.") hash_value = self._ComputeHash(key) return bytearray(pack('I', hash_value))
python
def ComputeHash(self, key): """ Computes the hash of the value passed using MurmurHash3 algorithm. :param bytearray key: Byte array representing the key to be hashed. :return: 32 bit hash value. :rtype: int """ if key is None: raise ValueError("key is None.") hash_value = self._ComputeHash(key) return bytearray(pack('I', hash_value))
[ "def", "ComputeHash", "(", "self", ",", "key", ")", ":", "if", "key", "is", "None", ":", "raise", "ValueError", "(", "\"key is None.\"", ")", "hash_value", "=", "self", ".", "_ComputeHash", "(", "key", ")", "return", "bytearray", "(", "pack", "(", "'I'", ",", "hash_value", ")", ")" ]
Computes the hash of the value passed using MurmurHash3 algorithm. :param bytearray key: Byte array representing the key to be hashed. :return: 32 bit hash value. :rtype: int
[ "Computes", "the", "hash", "of", "the", "value", "passed", "using", "MurmurHash3", "algorithm", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/murmur_hash.py#L49-L64
229,507
Azure/azure-cosmos-python
azure/cosmos/murmur_hash.py
_MurmurHash._ComputeHash
def _ComputeHash( key, seed = 0x0 ): """Computes the hash of the value passed using MurmurHash3 algorithm with the seed value. """ def fmix( h ): h ^= h >> 16 h = ( h * 0x85ebca6b ) & 0xFFFFFFFF h ^= h >> 13 h = ( h * 0xc2b2ae35 ) & 0xFFFFFFFF h ^= h >> 16 return h length = len( key ) nblocks = int( length / 4 ) h1 = seed c1 = 0xcc9e2d51 c2 = 0x1b873593 # body for block_start in xrange( 0, nblocks * 4, 4 ): k1 = key[ block_start + 3 ] << 24 | \ key[ block_start + 2 ] << 16 | \ key[ block_start + 1 ] << 8 | \ key[ block_start + 0 ] k1 = c1 * k1 & 0xFFFFFFFF k1 = ( k1 << 15 | k1 >> 17 ) & 0xFFFFFFFF # inlined ROTL32 k1 = ( c2 * k1 ) & 0xFFFFFFFF h1 ^= k1 h1 = ( h1 << 13 | h1 >> 19 ) & 0xFFFFFFFF # inlined _ROTL32 h1 = ( h1 * 5 + 0xe6546b64 ) & 0xFFFFFFFF # tail tail_index = nblocks * 4 k1 = 0 tail_size = length & 3 if tail_size >= 3: k1 ^= key[ tail_index + 2 ] << 16 if tail_size >= 2: k1 ^= key[ tail_index + 1 ] << 8 if tail_size >= 1: k1 ^= key[ tail_index + 0 ] if tail_size != 0: k1 = ( k1 * c1 ) & 0xFFFFFFFF k1 = ( k1 << 15 | k1 >> 17 ) & 0xFFFFFFFF # _ROTL32 k1 = ( k1 * c2 ) & 0xFFFFFFFF h1 ^= k1 return fmix( h1 ^ length )
python
def _ComputeHash( key, seed = 0x0 ): """Computes the hash of the value passed using MurmurHash3 algorithm with the seed value. """ def fmix( h ): h ^= h >> 16 h = ( h * 0x85ebca6b ) & 0xFFFFFFFF h ^= h >> 13 h = ( h * 0xc2b2ae35 ) & 0xFFFFFFFF h ^= h >> 16 return h length = len( key ) nblocks = int( length / 4 ) h1 = seed c1 = 0xcc9e2d51 c2 = 0x1b873593 # body for block_start in xrange( 0, nblocks * 4, 4 ): k1 = key[ block_start + 3 ] << 24 | \ key[ block_start + 2 ] << 16 | \ key[ block_start + 1 ] << 8 | \ key[ block_start + 0 ] k1 = c1 * k1 & 0xFFFFFFFF k1 = ( k1 << 15 | k1 >> 17 ) & 0xFFFFFFFF # inlined ROTL32 k1 = ( c2 * k1 ) & 0xFFFFFFFF h1 ^= k1 h1 = ( h1 << 13 | h1 >> 19 ) & 0xFFFFFFFF # inlined _ROTL32 h1 = ( h1 * 5 + 0xe6546b64 ) & 0xFFFFFFFF # tail tail_index = nblocks * 4 k1 = 0 tail_size = length & 3 if tail_size >= 3: k1 ^= key[ tail_index + 2 ] << 16 if tail_size >= 2: k1 ^= key[ tail_index + 1 ] << 8 if tail_size >= 1: k1 ^= key[ tail_index + 0 ] if tail_size != 0: k1 = ( k1 * c1 ) & 0xFFFFFFFF k1 = ( k1 << 15 | k1 >> 17 ) & 0xFFFFFFFF # _ROTL32 k1 = ( k1 * c2 ) & 0xFFFFFFFF h1 ^= k1 return fmix( h1 ^ length )
[ "def", "_ComputeHash", "(", "key", ",", "seed", "=", "0x0", ")", ":", "def", "fmix", "(", "h", ")", ":", "h", "^=", "h", ">>", "16", "h", "=", "(", "h", "*", "0x85ebca6b", ")", "&", "0xFFFFFFFF", "h", "^=", "h", ">>", "13", "h", "=", "(", "h", "*", "0xc2b2ae35", ")", "&", "0xFFFFFFFF", "h", "^=", "h", ">>", "16", "return", "h", "length", "=", "len", "(", "key", ")", "nblocks", "=", "int", "(", "length", "/", "4", ")", "h1", "=", "seed", "c1", "=", "0xcc9e2d51", "c2", "=", "0x1b873593", "# body", "for", "block_start", "in", "xrange", "(", "0", ",", "nblocks", "*", "4", ",", "4", ")", ":", "k1", "=", "key", "[", "block_start", "+", "3", "]", "<<", "24", "|", "key", "[", "block_start", "+", "2", "]", "<<", "16", "|", "key", "[", "block_start", "+", "1", "]", "<<", "8", "|", "key", "[", "block_start", "+", "0", "]", "k1", "=", "c1", "*", "k1", "&", "0xFFFFFFFF", "k1", "=", "(", "k1", "<<", "15", "|", "k1", ">>", "17", ")", "&", "0xFFFFFFFF", "# inlined ROTL32", "k1", "=", "(", "c2", "*", "k1", ")", "&", "0xFFFFFFFF", "h1", "^=", "k1", "h1", "=", "(", "h1", "<<", "13", "|", "h1", ">>", "19", ")", "&", "0xFFFFFFFF", "# inlined _ROTL32 ", "h1", "=", "(", "h1", "*", "5", "+", "0xe6546b64", ")", "&", "0xFFFFFFFF", "# tail", "tail_index", "=", "nblocks", "*", "4", "k1", "=", "0", "tail_size", "=", "length", "&", "3", "if", "tail_size", ">=", "3", ":", "k1", "^=", "key", "[", "tail_index", "+", "2", "]", "<<", "16", "if", "tail_size", ">=", "2", ":", "k1", "^=", "key", "[", "tail_index", "+", "1", "]", "<<", "8", "if", "tail_size", ">=", "1", ":", "k1", "^=", "key", "[", "tail_index", "+", "0", "]", "if", "tail_size", "!=", "0", ":", "k1", "=", "(", "k1", "*", "c1", ")", "&", "0xFFFFFFFF", "k1", "=", "(", "k1", "<<", "15", "|", "k1", ">>", "17", ")", "&", "0xFFFFFFFF", "# _ROTL32", "k1", "=", "(", "k1", "*", "c2", ")", "&", "0xFFFFFFFF", "h1", "^=", "k1", "return", "fmix", "(", "h1", "^", "length", ")" ]
Computes the hash of the value passed using MurmurHash3 algorithm with the seed value.
[ "Computes", "the", "hash", "of", "the", "value", "passed", "using", "MurmurHash3", "algorithm", "with", "the", "seed", "value", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/murmur_hash.py#L67-L119
229,508
Azure/azure-cosmos-python
azure/cosmos/vector_session_token.py
VectorSessionToken.create
def create(cls, session_token): """ Parses session token and creates the vector session token :param str session_token: :return: A Vector session Token :rtype: VectorSessionToken """ version = None global_lsn = None local_lsn_by_region = {} if not session_token: return None segments = session_token.split(cls.segment_separator) if len(segments) < 2: return None try: version = int(segments[0]) except ValueError as _: return None try: global_lsn = int(segments[1]) except ValueError as _: return None for i in range(2, len(segments)): region_segment = segments[i] region_id_with_lsn = region_segment.split(cls.region_progress_separator) if len(region_id_with_lsn) != 2: return None try: region_id = int(region_id_with_lsn[0]) local_lsn = int(region_id_with_lsn[1]) except ValueError as _: return None local_lsn_by_region[region_id] = local_lsn return VectorSessionToken(version, global_lsn, local_lsn_by_region, session_token)
python
def create(cls, session_token): """ Parses session token and creates the vector session token :param str session_token: :return: A Vector session Token :rtype: VectorSessionToken """ version = None global_lsn = None local_lsn_by_region = {} if not session_token: return None segments = session_token.split(cls.segment_separator) if len(segments) < 2: return None try: version = int(segments[0]) except ValueError as _: return None try: global_lsn = int(segments[1]) except ValueError as _: return None for i in range(2, len(segments)): region_segment = segments[i] region_id_with_lsn = region_segment.split(cls.region_progress_separator) if len(region_id_with_lsn) != 2: return None try: region_id = int(region_id_with_lsn[0]) local_lsn = int(region_id_with_lsn[1]) except ValueError as _: return None local_lsn_by_region[region_id] = local_lsn return VectorSessionToken(version, global_lsn, local_lsn_by_region, session_token)
[ "def", "create", "(", "cls", ",", "session_token", ")", ":", "version", "=", "None", "global_lsn", "=", "None", "local_lsn_by_region", "=", "{", "}", "if", "not", "session_token", ":", "return", "None", "segments", "=", "session_token", ".", "split", "(", "cls", ".", "segment_separator", ")", "if", "len", "(", "segments", ")", "<", "2", ":", "return", "None", "try", ":", "version", "=", "int", "(", "segments", "[", "0", "]", ")", "except", "ValueError", "as", "_", ":", "return", "None", "try", ":", "global_lsn", "=", "int", "(", "segments", "[", "1", "]", ")", "except", "ValueError", "as", "_", ":", "return", "None", "for", "i", "in", "range", "(", "2", ",", "len", "(", "segments", ")", ")", ":", "region_segment", "=", "segments", "[", "i", "]", "region_id_with_lsn", "=", "region_segment", ".", "split", "(", "cls", ".", "region_progress_separator", ")", "if", "len", "(", "region_id_with_lsn", ")", "!=", "2", ":", "return", "None", "try", ":", "region_id", "=", "int", "(", "region_id_with_lsn", "[", "0", "]", ")", "local_lsn", "=", "int", "(", "region_id_with_lsn", "[", "1", "]", ")", "except", "ValueError", "as", "_", ":", "return", "None", "local_lsn_by_region", "[", "region_id", "]", "=", "local_lsn", "return", "VectorSessionToken", "(", "version", ",", "global_lsn", ",", "local_lsn_by_region", ",", "session_token", ")" ]
Parses session token and creates the vector session token :param str session_token: :return: A Vector session Token :rtype: VectorSessionToken
[ "Parses", "session", "token", "and", "creates", "the", "vector", "session", "token" ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/vector_session_token.py#L53-L99
229,509
Azure/azure-cosmos-python
azure/cosmos/consistent_hash_ring.py
_ConsistentHashRing._ConstructPartitions
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. """ collections_node_count = len(collection_links) partitions = [partition._Partition() for _ in xrange(0, partitions_per_node * collections_node_count)] index = 0 for collection_node in collection_links: hash_value = self.hash_generator.ComputeHash(self._GetBytes(collection_node)) for _ in xrange(0, partitions_per_node): partitions[index] = partition._Partition(hash_value, collection_node) index += 1 hash_value = self.hash_generator.ComputeHash(hash_value) partitions.sort() return partitions
python
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. """ collections_node_count = len(collection_links) partitions = [partition._Partition() for _ in xrange(0, partitions_per_node * collections_node_count)] index = 0 for collection_node in collection_links: hash_value = self.hash_generator.ComputeHash(self._GetBytes(collection_node)) for _ in xrange(0, partitions_per_node): partitions[index] = partition._Partition(hash_value, collection_node) index += 1 hash_value = self.hash_generator.ComputeHash(hash_value) partitions.sort() return partitions
[ "def", "_ConstructPartitions", "(", "self", ",", "collection_links", ",", "partitions_per_node", ")", ":", "collections_node_count", "=", "len", "(", "collection_links", ")", "partitions", "=", "[", "partition", ".", "_Partition", "(", ")", "for", "_", "in", "xrange", "(", "0", ",", "partitions_per_node", "*", "collections_node_count", ")", "]", "index", "=", "0", "for", "collection_node", "in", "collection_links", ":", "hash_value", "=", "self", ".", "hash_generator", ".", "ComputeHash", "(", "self", ".", "_GetBytes", "(", "collection_node", ")", ")", "for", "_", "in", "xrange", "(", "0", ",", "partitions_per_node", ")", ":", "partitions", "[", "index", "]", "=", "partition", ".", "_Partition", "(", "hash_value", ",", "collection_node", ")", "index", "+=", "1", "hash_value", "=", "self", ".", "hash_generator", ".", "ComputeHash", "(", "hash_value", ")", "partitions", ".", "sort", "(", ")", "return", "partitions" ]
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", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/consistent_hash_ring.py#L75-L91
229,510
Azure/azure-cosmos-python
azure/cosmos/consistent_hash_ring.py
_ConsistentHashRing._FindPartition
def _FindPartition(self, key): """Finds the partition from the byte array representation of the partition key. """ hash_value = self.hash_generator.ComputeHash(key) return self._LowerBoundSearch(self.partitions, hash_value)
python
def _FindPartition(self, key): """Finds the partition from the byte array representation of the partition key. """ hash_value = self.hash_generator.ComputeHash(key) return self._LowerBoundSearch(self.partitions, hash_value)
[ "def", "_FindPartition", "(", "self", ",", "key", ")", ":", "hash_value", "=", "self", ".", "hash_generator", ".", "ComputeHash", "(", "key", ")", "return", "self", ".", "_LowerBoundSearch", "(", "self", ".", "partitions", ",", "hash_value", ")" ]
Finds the partition from the byte array representation of the partition key.
[ "Finds", "the", "partition", "from", "the", "byte", "array", "representation", "of", "the", "partition", "key", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/consistent_hash_ring.py#L93-L97
229,511
Azure/azure-cosmos-python
azure/cosmos/consistent_hash_ring.py
_ConsistentHashRing._GetSerializedPartitionList
def _GetSerializedPartitionList(self): """Gets the serialized version of the ConsistentRing. Added this helper for the test code. """ partition_list = list() for part in self.partitions: partition_list.append((part.node, unpack("<L", part.hash_value)[0])) return partition_list
python
def _GetSerializedPartitionList(self): """Gets the serialized version of the ConsistentRing. Added this helper for the test code. """ partition_list = list() for part in self.partitions: partition_list.append((part.node, unpack("<L", part.hash_value)[0])) return partition_list
[ "def", "_GetSerializedPartitionList", "(", "self", ")", ":", "partition_list", "=", "list", "(", ")", "for", "part", "in", "self", ".", "partitions", ":", "partition_list", ".", "append", "(", "(", "part", ".", "node", ",", "unpack", "(", "\"<L\"", ",", "part", ".", "hash_value", ")", "[", "0", "]", ")", ")", "return", "partition_list" ]
Gets the serialized version of the ConsistentRing. Added this helper for the test code.
[ "Gets", "the", "serialized", "version", "of", "the", "ConsistentRing", ".", "Added", "this", "helper", "for", "the", "test", "code", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/consistent_hash_ring.py#L99-L108
229,512
Azure/azure-cosmos-python
azure/cosmos/consistent_hash_ring.py
_ConsistentHashRing._GetBytes
def _GetBytes(partition_key): """Gets the bytes representing the value of the partition key. """ if isinstance(partition_key, six.string_types): return bytearray(partition_key, encoding='utf-8') else: raise ValueError("Unsupported " + str(type(partition_key)) + " for partitionKey.")
python
def _GetBytes(partition_key): """Gets the bytes representing the value of the partition key. """ if isinstance(partition_key, six.string_types): return bytearray(partition_key, encoding='utf-8') else: raise ValueError("Unsupported " + str(type(partition_key)) + " for partitionKey.")
[ "def", "_GetBytes", "(", "partition_key", ")", ":", "if", "isinstance", "(", "partition_key", ",", "six", ".", "string_types", ")", ":", "return", "bytearray", "(", "partition_key", ",", "encoding", "=", "'utf-8'", ")", "else", ":", "raise", "ValueError", "(", "\"Unsupported \"", "+", "str", "(", "type", "(", "partition_key", ")", ")", "+", "\" for partitionKey.\"", ")" ]
Gets the bytes representing the value of the partition key.
[ "Gets", "the", "bytes", "representing", "the", "value", "of", "the", "partition", "key", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/consistent_hash_ring.py#L111-L117
229,513
Azure/azure-cosmos-python
azure/cosmos/consistent_hash_ring.py
_ConsistentHashRing._LowerBoundSearch
def _LowerBoundSearch(partitions, hash_value): """Searches the partition in the partition array using hashValue. """ for i in xrange(0, len(partitions) - 1): if partitions[i].CompareTo(hash_value) <= 0 and partitions[i+1].CompareTo(hash_value) > 0: return i return len(partitions) - 1
python
def _LowerBoundSearch(partitions, hash_value): """Searches the partition in the partition array using hashValue. """ for i in xrange(0, len(partitions) - 1): if partitions[i].CompareTo(hash_value) <= 0 and partitions[i+1].CompareTo(hash_value) > 0: return i return len(partitions) - 1
[ "def", "_LowerBoundSearch", "(", "partitions", ",", "hash_value", ")", ":", "for", "i", "in", "xrange", "(", "0", ",", "len", "(", "partitions", ")", "-", "1", ")", ":", "if", "partitions", "[", "i", "]", ".", "CompareTo", "(", "hash_value", ")", "<=", "0", "and", "partitions", "[", "i", "+", "1", "]", ".", "CompareTo", "(", "hash_value", ")", ">", "0", ":", "return", "i", "return", "len", "(", "partitions", ")", "-", "1" ]
Searches the partition in the partition array using hashValue.
[ "Searches", "the", "partition", "in", "the", "partition", "array", "using", "hashValue", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/consistent_hash_ring.py#L120-L127
229,514
Azure/azure-cosmos-python
azure/cosmos/execution_context/base_execution_context.py
_QueryExecutionContextBase._fetch_items_helper_no_retries
def _fetch_items_helper_no_retries(self, fetch_function): """Fetches more items and doesn't retry on failure :return: List of fetched items. :rtype: list """ fetched_items = [] # Continues pages till finds a non empty page or all results are exhausted while self._continuation or not self._has_started: if not self._has_started: self._has_started = True self._options['continuation'] = self._continuation (fetched_items, response_headers) = fetch_function(self._options) fetched_items continuation_key = http_constants.HttpHeaders.Continuation # Use Etag as continuation token for change feed queries. if self._is_change_feed: continuation_key = http_constants.HttpHeaders.ETag # In change feed queries, the continuation token is always populated. The hasNext() test is whether # there is any items in the response or not. if not self._is_change_feed or len(fetched_items) > 0: self._continuation = response_headers.get(continuation_key) else: self._continuation = None if fetched_items: break return fetched_items
python
def _fetch_items_helper_no_retries(self, fetch_function): """Fetches more items and doesn't retry on failure :return: List of fetched items. :rtype: list """ fetched_items = [] # Continues pages till finds a non empty page or all results are exhausted while self._continuation or not self._has_started: if not self._has_started: self._has_started = True self._options['continuation'] = self._continuation (fetched_items, response_headers) = fetch_function(self._options) fetched_items continuation_key = http_constants.HttpHeaders.Continuation # Use Etag as continuation token for change feed queries. if self._is_change_feed: continuation_key = http_constants.HttpHeaders.ETag # In change feed queries, the continuation token is always populated. The hasNext() test is whether # there is any items in the response or not. if not self._is_change_feed or len(fetched_items) > 0: self._continuation = response_headers.get(continuation_key) else: self._continuation = None if fetched_items: break return fetched_items
[ "def", "_fetch_items_helper_no_retries", "(", "self", ",", "fetch_function", ")", ":", "fetched_items", "=", "[", "]", "# Continues pages till finds a non empty page or all results are exhausted", "while", "self", ".", "_continuation", "or", "not", "self", ".", "_has_started", ":", "if", "not", "self", ".", "_has_started", ":", "self", ".", "_has_started", "=", "True", "self", ".", "_options", "[", "'continuation'", "]", "=", "self", ".", "_continuation", "(", "fetched_items", ",", "response_headers", ")", "=", "fetch_function", "(", "self", ".", "_options", ")", "fetched_items", "continuation_key", "=", "http_constants", ".", "HttpHeaders", ".", "Continuation", "# Use Etag as continuation token for change feed queries.", "if", "self", ".", "_is_change_feed", ":", "continuation_key", "=", "http_constants", ".", "HttpHeaders", ".", "ETag", "# In change feed queries, the continuation token is always populated. The hasNext() test is whether", "# there is any items in the response or not.", "if", "not", "self", ".", "_is_change_feed", "or", "len", "(", "fetched_items", ")", ">", "0", ":", "self", ".", "_continuation", "=", "response_headers", ".", "get", "(", "continuation_key", ")", "else", ":", "self", ".", "_continuation", "=", "None", "if", "fetched_items", ":", "break", "return", "fetched_items" ]
Fetches more items and doesn't retry on failure :return: List of fetched items. :rtype: list
[ "Fetches", "more", "items", "and", "doesn", "t", "retry", "on", "failure" ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/execution_context/base_execution_context.py#L110-L137
229,515
Azure/azure-cosmos-python
azure/cosmos/execution_context/base_execution_context.py
_MultiCollectionQueryExecutionContext._fetch_next_block
def _fetch_next_block(self): """Fetches the next block of query results. This iterates fetches the next block of results from the current collection link. Once the current collection results were exhausted. It moves to the next collection link. :return: List of fetched items. :rtype: list """ # Fetch next block of results by executing the query against the current document collection fetched_items = self._fetch_items_helper_with_retries(self._fetch_function) # If there are multiple document collections to query for(in case of partitioning), keep looping through each one of them, # creating separate feed queries for each collection and fetching the items while not fetched_items: if self._collection_links and self._current_collection_index < self._collection_links_length: path = base.GetPathFromLink(self._collection_links[self._current_collection_index], 'docs') collection_id = base.GetResourceIdOrFullNameFromLink(self._collection_links[self._current_collection_index]) self._continuation = None self._has_started = False def fetch_fn(options): return self._client.QueryFeed(path, collection_id, self._query, options) self._fetch_function = fetch_fn fetched_items = self._fetch_items_helper_with_retries(self._fetch_function) self._current_collection_index += 1 else: break return fetched_items
python
def _fetch_next_block(self): """Fetches the next block of query results. This iterates fetches the next block of results from the current collection link. Once the current collection results were exhausted. It moves to the next collection link. :return: List of fetched items. :rtype: list """ # Fetch next block of results by executing the query against the current document collection fetched_items = self._fetch_items_helper_with_retries(self._fetch_function) # If there are multiple document collections to query for(in case of partitioning), keep looping through each one of them, # creating separate feed queries for each collection and fetching the items while not fetched_items: if self._collection_links and self._current_collection_index < self._collection_links_length: path = base.GetPathFromLink(self._collection_links[self._current_collection_index], 'docs') collection_id = base.GetResourceIdOrFullNameFromLink(self._collection_links[self._current_collection_index]) self._continuation = None self._has_started = False def fetch_fn(options): return self._client.QueryFeed(path, collection_id, self._query, options) self._fetch_function = fetch_fn fetched_items = self._fetch_items_helper_with_retries(self._fetch_function) self._current_collection_index += 1 else: break return fetched_items
[ "def", "_fetch_next_block", "(", "self", ")", ":", "# Fetch next block of results by executing the query against the current document collection", "fetched_items", "=", "self", ".", "_fetch_items_helper_with_retries", "(", "self", ".", "_fetch_function", ")", "# If there are multiple document collections to query for(in case of partitioning), keep looping through each one of them,", "# creating separate feed queries for each collection and fetching the items", "while", "not", "fetched_items", ":", "if", "self", ".", "_collection_links", "and", "self", ".", "_current_collection_index", "<", "self", ".", "_collection_links_length", ":", "path", "=", "base", ".", "GetPathFromLink", "(", "self", ".", "_collection_links", "[", "self", ".", "_current_collection_index", "]", ",", "'docs'", ")", "collection_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "self", ".", "_collection_links", "[", "self", ".", "_current_collection_index", "]", ")", "self", ".", "_continuation", "=", "None", "self", ".", "_has_started", "=", "False", "def", "fetch_fn", "(", "options", ")", ":", "return", "self", ".", "_client", ".", "QueryFeed", "(", "path", ",", "collection_id", ",", "self", ".", "_query", ",", "options", ")", "self", ".", "_fetch_function", "=", "fetch_fn", "fetched_items", "=", "self", ".", "_fetch_items_helper_with_retries", "(", "self", ".", "_fetch_function", ")", "self", ".", "_current_collection_index", "+=", "1", "else", ":", "break", "return", "fetched_items" ]
Fetches the next block of query results. This iterates fetches the next block of results from the current collection link. Once the current collection results were exhausted. It moves to the next collection link. :return: List of fetched items. :rtype: list
[ "Fetches", "the", "next", "block", "of", "query", "results", ".", "This", "iterates", "fetches", "the", "next", "block", "of", "results", "from", "the", "current", "collection", "link", ".", "Once", "the", "current", "collection", "results", "were", "exhausted", ".", "It", "moves", "to", "the", "next", "collection", "link", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/execution_context/base_execution_context.py#L227-L263
229,516
Azure/azure-cosmos-python
azure/cosmos/range.py
Range.Contains
def Contains(self, other): """Checks if the passed parameter is in the range of this object. """ if other is None: raise ValueError("other is None.") if isinstance(other, Range): if other.low >= self.low and other.high <= self.high: return True return False else: return self.Contains(Range(other, other))
python
def Contains(self, other): """Checks if the passed parameter is in the range of this object. """ if other is None: raise ValueError("other is None.") if isinstance(other, Range): if other.low >= self.low and other.high <= self.high: return True return False else: return self.Contains(Range(other, other))
[ "def", "Contains", "(", "self", ",", "other", ")", ":", "if", "other", "is", "None", ":", "raise", "ValueError", "(", "\"other is None.\"", ")", "if", "isinstance", "(", "other", ",", "Range", ")", ":", "if", "other", ".", "low", ">=", "self", ".", "low", "and", "other", ".", "high", "<=", "self", ".", "high", ":", "return", "True", "return", "False", "else", ":", "return", "self", ".", "Contains", "(", "Range", "(", "other", ",", "other", ")", ")" ]
Checks if the passed parameter is in the range of this object.
[ "Checks", "if", "the", "passed", "parameter", "is", "in", "the", "range", "of", "this", "object", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/range.py#L57-L68
229,517
Azure/azure-cosmos-python
azure/cosmos/range.py
Range.Intersect
def Intersect(self, other): """Checks if the passed parameter intersects the range of this object. """ if isinstance(other, Range): max_low = self.low if (self.low >= other.low) else other.low min_high = self.high if (self.high <= other.high) else other.high if max_low <= min_high: return True return False
python
def Intersect(self, other): """Checks if the passed parameter intersects the range of this object. """ if isinstance(other, Range): max_low = self.low if (self.low >= other.low) else other.low min_high = self.high if (self.high <= other.high) else other.high if max_low <= min_high: return True return False
[ "def", "Intersect", "(", "self", ",", "other", ")", ":", "if", "isinstance", "(", "other", ",", "Range", ")", ":", "max_low", "=", "self", ".", "low", "if", "(", "self", ".", "low", ">=", "other", ".", "low", ")", "else", "other", ".", "low", "min_high", "=", "self", ".", "high", "if", "(", "self", ".", "high", "<=", "other", ".", "high", ")", "else", "other", ".", "high", "if", "max_low", "<=", "min_high", ":", "return", "True", "return", "False" ]
Checks if the passed parameter intersects the range of this object.
[ "Checks", "if", "the", "passed", "parameter", "intersects", "the", "range", "of", "this", "object", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/range.py#L70-L80
229,518
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.RegisterPartitionResolver
def RegisterPartitionResolver(self, database_link, partition_resolver): """Registers the partition resolver associated with the database link :param str database_link: Database Self Link or ID based link. :param object partition_resolver: An instance of PartitionResolver. """ if not database_link: raise ValueError("database_link is None or empty.") if partition_resolver is None: raise ValueError("partition_resolver is None.") self.partition_resolvers = {base.TrimBeginningAndEndingSlashes(database_link): partition_resolver}
python
def RegisterPartitionResolver(self, database_link, partition_resolver): """Registers the partition resolver associated with the database link :param str database_link: Database Self Link or ID based link. :param object partition_resolver: An instance of PartitionResolver. """ if not database_link: raise ValueError("database_link is None or empty.") if partition_resolver is None: raise ValueError("partition_resolver is None.") self.partition_resolvers = {base.TrimBeginningAndEndingSlashes(database_link): partition_resolver}
[ "def", "RegisterPartitionResolver", "(", "self", ",", "database_link", ",", "partition_resolver", ")", ":", "if", "not", "database_link", ":", "raise", "ValueError", "(", "\"database_link is None or empty.\"", ")", "if", "partition_resolver", "is", "None", ":", "raise", "ValueError", "(", "\"partition_resolver is None.\"", ")", "self", ".", "partition_resolvers", "=", "{", "base", ".", "TrimBeginningAndEndingSlashes", "(", "database_link", ")", ":", "partition_resolver", "}" ]
Registers the partition resolver associated with the database link :param str database_link: Database Self Link or ID based link. :param object partition_resolver: An instance of PartitionResolver.
[ "Registers", "the", "partition", "resolver", "associated", "with", "the", "database", "link" ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L180-L195
229,519
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.GetPartitionResolver
def GetPartitionResolver(self, database_link): """Gets the partition resolver associated with the database link :param str database_link: Database self link or ID based link. :return: An instance of PartitionResolver. :rtype: object """ if not database_link: raise ValueError("database_link is None or empty.") return self.partition_resolvers.get(base.TrimBeginningAndEndingSlashes(database_link))
python
def GetPartitionResolver(self, database_link): """Gets the partition resolver associated with the database link :param str database_link: Database self link or ID based link. :return: An instance of PartitionResolver. :rtype: object """ if not database_link: raise ValueError("database_link is None or empty.") return self.partition_resolvers.get(base.TrimBeginningAndEndingSlashes(database_link))
[ "def", "GetPartitionResolver", "(", "self", ",", "database_link", ")", ":", "if", "not", "database_link", ":", "raise", "ValueError", "(", "\"database_link is None or empty.\"", ")", "return", "self", ".", "partition_resolvers", ".", "get", "(", "base", ".", "TrimBeginningAndEndingSlashes", "(", "database_link", ")", ")" ]
Gets the partition resolver associated with the database link :param str database_link: Database self link or ID based link. :return: An instance of PartitionResolver. :rtype: object
[ "Gets", "the", "partition", "resolver", "associated", "with", "the", "database", "link" ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L198-L212
229,520
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.CreateDatabase
def CreateDatabase(self, database, options=None): """Creates a database. :param dict database: The Azure Cosmos database to create. :param dict options: The request options for the request. :return: The Database that was created. :rtype: dict """ if options is None: options = {} CosmosClient.__ValidateResource(database) path = '/dbs' return self.Create(database, path, 'dbs', None, None, options)
python
def CreateDatabase(self, database, options=None): """Creates a database. :param dict database: The Azure Cosmos database to create. :param dict options: The request options for the request. :return: The Database that was created. :rtype: dict """ if options is None: options = {} CosmosClient.__ValidateResource(database) path = '/dbs' return self.Create(database, path, 'dbs', None, None, options)
[ "def", "CreateDatabase", "(", "self", ",", "database", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "CosmosClient", ".", "__ValidateResource", "(", "database", ")", "path", "=", "'/dbs'", "return", "self", ".", "Create", "(", "database", ",", "path", ",", "'dbs'", ",", "None", ",", "None", ",", "options", ")" ]
Creates a database. :param dict database: The Azure Cosmos database to create. :param dict options: The request options for the request. :return: The Database that was created. :rtype: dict
[ "Creates", "a", "database", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L215-L233
229,521
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadDatabase
def ReadDatabase(self, database_link, options=None): """Reads a database. :param str database_link: The link to the database. :param dict options: The request options for the request. :return: The Database that was read. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(database_link) database_id = base.GetResourceIdOrFullNameFromLink(database_link) return self.Read(path, 'dbs', database_id, None, options)
python
def ReadDatabase(self, database_link, options=None): """Reads a database. :param str database_link: The link to the database. :param dict options: The request options for the request. :return: The Database that was read. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(database_link) database_id = base.GetResourceIdOrFullNameFromLink(database_link) return self.Read(path, 'dbs', database_id, None, options)
[ "def", "ReadDatabase", "(", "self", ",", "database_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "database_link", ")", "database_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "database_link", ")", "return", "self", ".", "Read", "(", "path", ",", "'dbs'", ",", "database_id", ",", "None", ",", "options", ")" ]
Reads a database. :param str database_link: The link to the database. :param dict options: The request options for the request. :return: The Database that was read. :rtype: dict
[ "Reads", "a", "database", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L235-L253
229,522
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.QueryDatabases
def QueryDatabases(self, query, options=None): """Queries databases. :param (str or dict) query: :param dict options: The request options for the request. :return: Query Iterable of Databases. :rtype: query_iterable.QueryIterable """ if options is None: options = {} def fetch_fn(options): return self.__QueryFeed('/dbs', 'dbs', '', lambda r: r['Databases'], lambda _, b: b, query, options), self.last_response_headers return query_iterable.QueryIterable(self, query, options, fetch_fn)
python
def QueryDatabases(self, query, options=None): """Queries databases. :param (str or dict) query: :param dict options: The request options for the request. :return: Query Iterable of Databases. :rtype: query_iterable.QueryIterable """ if options is None: options = {} def fetch_fn(options): return self.__QueryFeed('/dbs', 'dbs', '', lambda r: r['Databases'], lambda _, b: b, query, options), self.last_response_headers return query_iterable.QueryIterable(self, query, options, fetch_fn)
[ "def", "QueryDatabases", "(", "self", ",", "query", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "def", "fetch_fn", "(", "options", ")", ":", "return", "self", ".", "__QueryFeed", "(", "'/dbs'", ",", "'dbs'", ",", "''", ",", "lambda", "r", ":", "r", "[", "'Databases'", "]", ",", "lambda", "_", ",", "b", ":", "b", ",", "query", ",", "options", ")", ",", "self", ".", "last_response_headers", "return", "query_iterable", ".", "QueryIterable", "(", "self", ",", "query", ",", "options", ",", "fetch_fn", ")" ]
Queries databases. :param (str or dict) query: :param dict options: The request options for the request. :return: Query Iterable of Databases. :rtype: query_iterable.QueryIterable
[ "Queries", "databases", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L272-L295
229,523
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadContainers
def ReadContainers(self, database_link, options=None): """Reads all collections in a database. :param str database_link: The link to the database. :param dict options: The request options for the request. :return: Query Iterable of Collections. :rtype: query_iterable.QueryIterable """ if options is None: options = {} return self.QueryContainers(database_link, None, options)
python
def ReadContainers(self, database_link, options=None): """Reads all collections in a database. :param str database_link: The link to the database. :param dict options: The request options for the request. :return: Query Iterable of Collections. :rtype: query_iterable.QueryIterable """ if options is None: options = {} return self.QueryContainers(database_link, None, options)
[ "def", "ReadContainers", "(", "self", ",", "database_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "return", "self", ".", "QueryContainers", "(", "database_link", ",", "None", ",", "options", ")" ]
Reads all collections in a database. :param str database_link: The link to the database. :param dict options: The request options for the request. :return: Query Iterable of Collections. :rtype: query_iterable.QueryIterable
[ "Reads", "all", "collections", "in", "a", "database", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L297-L313
229,524
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.CreateContainer
def CreateContainer(self, database_link, collection, options=None): """Creates a collection in a database. :param str database_link: The link to the database. :param dict collection: The Azure Cosmos collection to create. :param dict options: The request options for the request. :return: The Collection that was created. :rtype: dict """ if options is None: options = {} CosmosClient.__ValidateResource(collection) path = base.GetPathFromLink(database_link, 'colls') database_id = base.GetResourceIdOrFullNameFromLink(database_link) return self.Create(collection, path, 'colls', database_id, None, options)
python
def CreateContainer(self, database_link, collection, options=None): """Creates a collection in a database. :param str database_link: The link to the database. :param dict collection: The Azure Cosmos collection to create. :param dict options: The request options for the request. :return: The Collection that was created. :rtype: dict """ if options is None: options = {} CosmosClient.__ValidateResource(collection) path = base.GetPathFromLink(database_link, 'colls') database_id = base.GetResourceIdOrFullNameFromLink(database_link) return self.Create(collection, path, 'colls', database_id, None, options)
[ "def", "CreateContainer", "(", "self", ",", "database_link", ",", "collection", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "CosmosClient", ".", "__ValidateResource", "(", "collection", ")", "path", "=", "base", ".", "GetPathFromLink", "(", "database_link", ",", "'colls'", ")", "database_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "database_link", ")", "return", "self", ".", "Create", "(", "collection", ",", "path", ",", "'colls'", ",", "database_id", ",", "None", ",", "options", ")" ]
Creates a collection in a database. :param str database_link: The link to the database. :param dict collection: The Azure Cosmos collection to create. :param dict options: The request options for the request. :return: The Collection that was created. :rtype: dict
[ "Creates", "a", "collection", "in", "a", "database", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L344-L369
229,525
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReplaceContainer
def ReplaceContainer(self, collection_link, collection, options=None): """Replaces a collection and return it. :param str collection_link: The link to the collection entity. :param dict collection: The collection to be used. :param dict options: The request options for the request. :return: The new Collection. :rtype: dict """ if options is None: options = {} CosmosClient.__ValidateResource(collection) path = base.GetPathFromLink(collection_link) collection_id = base.GetResourceIdOrFullNameFromLink(collection_link) return self.Replace(collection, path, 'colls', collection_id, None, options)
python
def ReplaceContainer(self, collection_link, collection, options=None): """Replaces a collection and return it. :param str collection_link: The link to the collection entity. :param dict collection: The collection to be used. :param dict options: The request options for the request. :return: The new Collection. :rtype: dict """ if options is None: options = {} CosmosClient.__ValidateResource(collection) path = base.GetPathFromLink(collection_link) collection_id = base.GetResourceIdOrFullNameFromLink(collection_link) return self.Replace(collection, path, 'colls', collection_id, None, options)
[ "def", "ReplaceContainer", "(", "self", ",", "collection_link", ",", "collection", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "CosmosClient", ".", "__ValidateResource", "(", "collection", ")", "path", "=", "base", ".", "GetPathFromLink", "(", "collection_link", ")", "collection_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "collection_link", ")", "return", "self", ".", "Replace", "(", "collection", ",", "path", ",", "'colls'", ",", "collection_id", ",", "None", ",", "options", ")" ]
Replaces a collection and return it. :param str collection_link: The link to the collection entity. :param dict collection: The collection to be used. :param dict options: The request options for the request. :return: The new Collection. :rtype: dict
[ "Replaces", "a", "collection", "and", "return", "it", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L371-L398
229,526
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadContainer
def ReadContainer(self, collection_link, options=None): """Reads a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: The read Collection. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(collection_link) collection_id = base.GetResourceIdOrFullNameFromLink(collection_link) return self.Read(path, 'colls', collection_id, None, options)
python
def ReadContainer(self, collection_link, options=None): """Reads a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: The read Collection. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(collection_link) collection_id = base.GetResourceIdOrFullNameFromLink(collection_link) return self.Read(path, 'colls', collection_id, None, options)
[ "def", "ReadContainer", "(", "self", ",", "collection_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "collection_link", ")", "collection_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "collection_link", ")", "return", "self", ".", "Read", "(", "path", ",", "'colls'", ",", "collection_id", ",", "None", ",", "options", ")" ]
Reads a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: The read Collection. :rtype: dict
[ "Reads", "a", "collection", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L400-L423
229,527
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.UpsertUser
def UpsertUser(self, database_link, user, options=None): """Upserts a user. :param str database_link: The link to the database. :param dict user: The Azure Cosmos user to upsert. :param dict options: The request options for the request. :return: The upserted User. :rtype: dict """ if options is None: options = {} database_id, path = self._GetDatabaseIdWithPathForUser(database_link, user) return self.Upsert(user, path, 'users', database_id, None, options)
python
def UpsertUser(self, database_link, user, options=None): """Upserts a user. :param str database_link: The link to the database. :param dict user: The Azure Cosmos user to upsert. :param dict options: The request options for the request. :return: The upserted User. :rtype: dict """ if options is None: options = {} database_id, path = self._GetDatabaseIdWithPathForUser(database_link, user) return self.Upsert(user, path, 'users', database_id, None, options)
[ "def", "UpsertUser", "(", "self", ",", "database_link", ",", "user", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "database_id", ",", "path", "=", "self", ".", "_GetDatabaseIdWithPathForUser", "(", "database_link", ",", "user", ")", "return", "self", ".", "Upsert", "(", "user", ",", "path", ",", "'users'", ",", "database_id", ",", "None", ",", "options", ")" ]
Upserts a user. :param str database_link: The link to the database. :param dict user: The Azure Cosmos user to upsert. :param dict options: The request options for the request. :return: The upserted User. :rtype: dict
[ "Upserts", "a", "user", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L452-L475
229,528
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadUser
def ReadUser(self, user_link, options=None): """Reads a user. :param str user_link: The link to the user entity. :param dict options: The request options for the request. :return: The read User. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(user_link) user_id = base.GetResourceIdOrFullNameFromLink(user_link) return self.Read(path, 'users', user_id, None, options)
python
def ReadUser(self, user_link, options=None): """Reads a user. :param str user_link: The link to the user entity. :param dict options: The request options for the request. :return: The read User. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(user_link) user_id = base.GetResourceIdOrFullNameFromLink(user_link) return self.Read(path, 'users', user_id, None, options)
[ "def", "ReadUser", "(", "self", ",", "user_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "user_link", ")", "user_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "user_link", ")", "return", "self", ".", "Read", "(", "path", ",", "'users'", ",", "user_id", ",", "None", ",", "options", ")" ]
Reads a user. :param str user_link: The link to the user entity. :param dict options: The request options for the request. :return: The read User. :rtype: dict
[ "Reads", "a", "user", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L484-L503
229,529
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadUsers
def ReadUsers(self, database_link, options=None): """Reads all users in a database. :params str database_link: The link to the database. :params dict options: The request options for the request. :return: Query iterable of Users. :rtype: query_iterable.QueryIterable """ if options is None: options = {} return self.QueryUsers(database_link, None, options)
python
def ReadUsers(self, database_link, options=None): """Reads all users in a database. :params str database_link: The link to the database. :params dict options: The request options for the request. :return: Query iterable of Users. :rtype: query_iterable.QueryIterable """ if options is None: options = {} return self.QueryUsers(database_link, None, options)
[ "def", "ReadUsers", "(", "self", ",", "database_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "return", "self", ".", "QueryUsers", "(", "database_link", ",", "None", ",", "options", ")" ]
Reads all users in a database. :params str database_link: The link to the database. :params dict options: The request options for the request. :return: Query iterable of Users. :rtype: query_iterable.QueryIterable
[ "Reads", "all", "users", "in", "a", "database", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L505-L521
229,530
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.QueryUsers
def QueryUsers(self, database_link, query, options=None): """Queries users in a database. :param str database_link: The link to the database. :param (str or dict) query: :param dict options: The request options for the request. :return: Query Iterable of Users. :rtype: query_iterable.QueryIterable """ if options is None: options = {} path = base.GetPathFromLink(database_link, 'users') database_id = base.GetResourceIdOrFullNameFromLink(database_link) def fetch_fn(options): return self.__QueryFeed(path, 'users', database_id, lambda r: r['Users'], lambda _, b: b, query, options), self.last_response_headers return query_iterable.QueryIterable(self, query, options, fetch_fn)
python
def QueryUsers(self, database_link, query, options=None): """Queries users in a database. :param str database_link: The link to the database. :param (str or dict) query: :param dict options: The request options for the request. :return: Query Iterable of Users. :rtype: query_iterable.QueryIterable """ if options is None: options = {} path = base.GetPathFromLink(database_link, 'users') database_id = base.GetResourceIdOrFullNameFromLink(database_link) def fetch_fn(options): return self.__QueryFeed(path, 'users', database_id, lambda r: r['Users'], lambda _, b: b, query, options), self.last_response_headers return query_iterable.QueryIterable(self, query, options, fetch_fn)
[ "def", "QueryUsers", "(", "self", ",", "database_link", ",", "query", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "database_link", ",", "'users'", ")", "database_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "database_link", ")", "def", "fetch_fn", "(", "options", ")", ":", "return", "self", ".", "__QueryFeed", "(", "path", ",", "'users'", ",", "database_id", ",", "lambda", "r", ":", "r", "[", "'Users'", "]", ",", "lambda", "_", ",", "b", ":", "b", ",", "query", ",", "options", ")", ",", "self", ".", "last_response_headers", "return", "query_iterable", ".", "QueryIterable", "(", "self", ",", "query", ",", "options", ",", "fetch_fn", ")" ]
Queries users in a database. :param str database_link: The link to the database. :param (str or dict) query: :param dict options: The request options for the request. :return: Query Iterable of Users. :rtype: query_iterable.QueryIterable
[ "Queries", "users", "in", "a", "database", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L523-L551
229,531
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.DeleteDatabase
def DeleteDatabase(self, database_link, options=None): """Deletes a database. :param str database_link: The link to the database. :param dict options: The request options for the request. :return: The deleted Database. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(database_link) database_id = base.GetResourceIdOrFullNameFromLink(database_link) return self.DeleteResource(path, 'dbs', database_id, None, options)
python
def DeleteDatabase(self, database_link, options=None): """Deletes a database. :param str database_link: The link to the database. :param dict options: The request options for the request. :return: The deleted Database. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(database_link) database_id = base.GetResourceIdOrFullNameFromLink(database_link) return self.DeleteResource(path, 'dbs', database_id, None, options)
[ "def", "DeleteDatabase", "(", "self", ",", "database_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "database_link", ")", "database_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "database_link", ")", "return", "self", ".", "DeleteResource", "(", "path", ",", "'dbs'", ",", "database_id", ",", "None", ",", "options", ")" ]
Deletes a database. :param str database_link: The link to the database. :param dict options: The request options for the request. :return: The deleted Database. :rtype: dict
[ "Deletes", "a", "database", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L553-L576
229,532
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.CreatePermission
def CreatePermission(self, user_link, permission, options=None): """Creates a permission for a user. :param str user_link: The link to the user entity. :param dict permission: The Azure Cosmos user permission to create. :param dict options: The request options for the request. :return: The created Permission. :rtype: dict """ if options is None: options = {} path, user_id = self._GetUserIdWithPathForPermission(permission, user_link) return self.Create(permission, path, 'permissions', user_id, None, options)
python
def CreatePermission(self, user_link, permission, options=None): """Creates a permission for a user. :param str user_link: The link to the user entity. :param dict permission: The Azure Cosmos user permission to create. :param dict options: The request options for the request. :return: The created Permission. :rtype: dict """ if options is None: options = {} path, user_id = self._GetUserIdWithPathForPermission(permission, user_link) return self.Create(permission, path, 'permissions', user_id, None, options)
[ "def", "CreatePermission", "(", "self", ",", "user_link", ",", "permission", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", ",", "user_id", "=", "self", ".", "_GetUserIdWithPathForPermission", "(", "permission", ",", "user_link", ")", "return", "self", ".", "Create", "(", "permission", ",", "path", ",", "'permissions'", ",", "user_id", ",", "None", ",", "options", ")" ]
Creates a permission for a user. :param str user_link: The link to the user entity. :param dict permission: The Azure Cosmos user permission to create. :param dict options: The request options for the request. :return: The created Permission. :rtype: dict
[ "Creates", "a", "permission", "for", "a", "user", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L578-L603
229,533
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.UpsertPermission
def UpsertPermission(self, user_link, permission, options=None): """Upserts a permission for a user. :param str user_link: The link to the user entity. :param dict permission: The Azure Cosmos user permission to upsert. :param dict options: The request options for the request. :return: The upserted permission. :rtype: dict """ if options is None: options = {} path, user_id = self._GetUserIdWithPathForPermission(permission, user_link) return self.Upsert(permission, path, 'permissions', user_id, None, options)
python
def UpsertPermission(self, user_link, permission, options=None): """Upserts a permission for a user. :param str user_link: The link to the user entity. :param dict permission: The Azure Cosmos user permission to upsert. :param dict options: The request options for the request. :return: The upserted permission. :rtype: dict """ if options is None: options = {} path, user_id = self._GetUserIdWithPathForPermission(permission, user_link) return self.Upsert(permission, path, 'permissions', user_id, None, options)
[ "def", "UpsertPermission", "(", "self", ",", "user_link", ",", "permission", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", ",", "user_id", "=", "self", ".", "_GetUserIdWithPathForPermission", "(", "permission", ",", "user_link", ")", "return", "self", ".", "Upsert", "(", "permission", ",", "path", ",", "'permissions'", ",", "user_id", ",", "None", ",", "options", ")" ]
Upserts a permission for a user. :param str user_link: The link to the user entity. :param dict permission: The Azure Cosmos user permission to upsert. :param dict options: The request options for the request. :return: The upserted permission. :rtype: dict
[ "Upserts", "a", "permission", "for", "a", "user", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L605-L630
229,534
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadPermission
def ReadPermission(self, permission_link, options=None): """Reads a permission. :param str permission_link: The link to the permission. :param dict options: The request options for the request. :return: The read permission. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(permission_link) permission_id = base.GetResourceIdOrFullNameFromLink(permission_link) return self.Read(path, 'permissions', permission_id, None, options)
python
def ReadPermission(self, permission_link, options=None): """Reads a permission. :param str permission_link: The link to the permission. :param dict options: The request options for the request. :return: The read permission. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(permission_link) permission_id = base.GetResourceIdOrFullNameFromLink(permission_link) return self.Read(path, 'permissions', permission_id, None, options)
[ "def", "ReadPermission", "(", "self", ",", "permission_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "permission_link", ")", "permission_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "permission_link", ")", "return", "self", ".", "Read", "(", "path", ",", "'permissions'", ",", "permission_id", ",", "None", ",", "options", ")" ]
Reads a permission. :param str permission_link: The link to the permission. :param dict options: The request options for the request. :return: The read permission. :rtype: dict
[ "Reads", "a", "permission", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L639-L662
229,535
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadPermissions
def ReadPermissions(self, user_link, options=None): """Reads all permissions for a user. :param str user_link: The link to the user entity. :param dict options: The request options for the request. :return: Query Iterable of Permissions. :rtype: query_iterable.QueryIterable """ if options is None: options = {} return self.QueryPermissions(user_link, None, options)
python
def ReadPermissions(self, user_link, options=None): """Reads all permissions for a user. :param str user_link: The link to the user entity. :param dict options: The request options for the request. :return: Query Iterable of Permissions. :rtype: query_iterable.QueryIterable """ if options is None: options = {} return self.QueryPermissions(user_link, None, options)
[ "def", "ReadPermissions", "(", "self", ",", "user_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "return", "self", ".", "QueryPermissions", "(", "user_link", ",", "None", ",", "options", ")" ]
Reads all permissions for a user. :param str user_link: The link to the user entity. :param dict options: The request options for the request. :return: Query Iterable of Permissions. :rtype: query_iterable.QueryIterable
[ "Reads", "all", "permissions", "for", "a", "user", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L664-L681
229,536
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.QueryPermissions
def QueryPermissions(self, user_link, query, options=None): """Queries permissions for a user. :param str user_link: The link to the user entity. :param (str or dict) query: :param dict options: The request options for the request. :return: Query Iterable of Permissions. :rtype: query_iterable.QueryIterable """ if options is None: options = {} path = base.GetPathFromLink(user_link, 'permissions') user_id = base.GetResourceIdOrFullNameFromLink(user_link) def fetch_fn(options): return self.__QueryFeed(path, 'permissions', user_id, lambda r: r['Permissions'], lambda _, b: b, query, options), self.last_response_headers return query_iterable.QueryIterable(self, query, options, fetch_fn)
python
def QueryPermissions(self, user_link, query, options=None): """Queries permissions for a user. :param str user_link: The link to the user entity. :param (str or dict) query: :param dict options: The request options for the request. :return: Query Iterable of Permissions. :rtype: query_iterable.QueryIterable """ if options is None: options = {} path = base.GetPathFromLink(user_link, 'permissions') user_id = base.GetResourceIdOrFullNameFromLink(user_link) def fetch_fn(options): return self.__QueryFeed(path, 'permissions', user_id, lambda r: r['Permissions'], lambda _, b: b, query, options), self.last_response_headers return query_iterable.QueryIterable(self, query, options, fetch_fn)
[ "def", "QueryPermissions", "(", "self", ",", "user_link", ",", "query", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "user_link", ",", "'permissions'", ")", "user_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "user_link", ")", "def", "fetch_fn", "(", "options", ")", ":", "return", "self", ".", "__QueryFeed", "(", "path", ",", "'permissions'", ",", "user_id", ",", "lambda", "r", ":", "r", "[", "'Permissions'", "]", ",", "lambda", "_", ",", "b", ":", "b", ",", "query", ",", "options", ")", ",", "self", ".", "last_response_headers", "return", "query_iterable", ".", "QueryIterable", "(", "self", ",", "query", ",", "options", ",", "fetch_fn", ")" ]
Queries permissions for a user. :param str user_link: The link to the user entity. :param (str or dict) query: :param dict options: The request options for the request. :return: Query Iterable of Permissions. :rtype: query_iterable.QueryIterable
[ "Queries", "permissions", "for", "a", "user", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L683-L711
229,537
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReplaceUser
def ReplaceUser(self, user_link, user, options=None): """Replaces a user and return it. :param str user_link: The link to the user entity. :param dict user: :param dict options: The request options for the request. :return: The new User. :rtype: dict """ if options is None: options = {} CosmosClient.__ValidateResource(user) path = base.GetPathFromLink(user_link) user_id = base.GetResourceIdOrFullNameFromLink(user_link) return self.Replace(user, path, 'users', user_id, None, options)
python
def ReplaceUser(self, user_link, user, options=None): """Replaces a user and return it. :param str user_link: The link to the user entity. :param dict user: :param dict options: The request options for the request. :return: The new User. :rtype: dict """ if options is None: options = {} CosmosClient.__ValidateResource(user) path = base.GetPathFromLink(user_link) user_id = base.GetResourceIdOrFullNameFromLink(user_link) return self.Replace(user, path, 'users', user_id, None, options)
[ "def", "ReplaceUser", "(", "self", ",", "user_link", ",", "user", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "CosmosClient", ".", "__ValidateResource", "(", "user", ")", "path", "=", "base", ".", "GetPathFromLink", "(", "user_link", ")", "user_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "user_link", ")", "return", "self", ".", "Replace", "(", "user", ",", "path", ",", "'users'", ",", "user_id", ",", "None", ",", "options", ")" ]
Replaces a user and return it. :param str user_link: The link to the user entity. :param dict user: :param dict options: The request options for the request. :return: The new User. :rtype: dict
[ "Replaces", "a", "user", "and", "return", "it", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L713-L739
229,538
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.DeleteUser
def DeleteUser(self, user_link, options=None): """Deletes a user. :param str user_link: The link to the user entity. :param dict options: The request options for the request. :return: The deleted user. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(user_link) user_id = base.GetResourceIdOrFullNameFromLink(user_link) return self.DeleteResource(path, 'users', user_id, None, options)
python
def DeleteUser(self, user_link, options=None): """Deletes a user. :param str user_link: The link to the user entity. :param dict options: The request options for the request. :return: The deleted user. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(user_link) user_id = base.GetResourceIdOrFullNameFromLink(user_link) return self.DeleteResource(path, 'users', user_id, None, options)
[ "def", "DeleteUser", "(", "self", ",", "user_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "user_link", ")", "user_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "user_link", ")", "return", "self", ".", "DeleteResource", "(", "path", ",", "'users'", ",", "user_id", ",", "None", ",", "options", ")" ]
Deletes a user. :param str user_link: The link to the user entity. :param dict options: The request options for the request. :return: The deleted user. :rtype: dict
[ "Deletes", "a", "user", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L741-L764
229,539
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReplacePermission
def ReplacePermission(self, permission_link, permission, options=None): """Replaces a permission and return it. :param str permission_link: The link to the permission. :param dict permission: :param dict options: The request options for the request. :return: The new Permission. :rtype: dict """ if options is None: options = {} CosmosClient.__ValidateResource(permission) path = base.GetPathFromLink(permission_link) permission_id = base.GetResourceIdOrFullNameFromLink(permission_link) return self.Replace(permission, path, 'permissions', permission_id, None, options)
python
def ReplacePermission(self, permission_link, permission, options=None): """Replaces a permission and return it. :param str permission_link: The link to the permission. :param dict permission: :param dict options: The request options for the request. :return: The new Permission. :rtype: dict """ if options is None: options = {} CosmosClient.__ValidateResource(permission) path = base.GetPathFromLink(permission_link) permission_id = base.GetResourceIdOrFullNameFromLink(permission_link) return self.Replace(permission, path, 'permissions', permission_id, None, options)
[ "def", "ReplacePermission", "(", "self", ",", "permission_link", ",", "permission", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "CosmosClient", ".", "__ValidateResource", "(", "permission", ")", "path", "=", "base", ".", "GetPathFromLink", "(", "permission_link", ")", "permission_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "permission_link", ")", "return", "self", ".", "Replace", "(", "permission", ",", "path", ",", "'permissions'", ",", "permission_id", ",", "None", ",", "options", ")" ]
Replaces a permission and return it. :param str permission_link: The link to the permission. :param dict permission: :param dict options: The request options for the request. :return: The new Permission. :rtype: dict
[ "Replaces", "a", "permission", "and", "return", "it", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L766-L792
229,540
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.DeletePermission
def DeletePermission(self, permission_link, options=None): """Deletes a permission. :param str permission_link: The link to the permission. :param dict options: The request options for the request. :return: The deleted Permission. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(permission_link) permission_id = base.GetResourceIdOrFullNameFromLink(permission_link) return self.DeleteResource(path, 'permissions', permission_id, None, options)
python
def DeletePermission(self, permission_link, options=None): """Deletes a permission. :param str permission_link: The link to the permission. :param dict options: The request options for the request. :return: The deleted Permission. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(permission_link) permission_id = base.GetResourceIdOrFullNameFromLink(permission_link) return self.DeleteResource(path, 'permissions', permission_id, None, options)
[ "def", "DeletePermission", "(", "self", ",", "permission_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "permission_link", ")", "permission_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "permission_link", ")", "return", "self", ".", "DeleteResource", "(", "path", ",", "'permissions'", ",", "permission_id", ",", "None", ",", "options", ")" ]
Deletes a permission. :param str permission_link: The link to the permission. :param dict options: The request options for the request. :return: The deleted Permission. :rtype: dict
[ "Deletes", "a", "permission", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L794-L817
229,541
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadItems
def ReadItems(self, collection_link, feed_options=None): """Reads all documents in a collection. :param str collection_link: The link to the document collection. :param dict feed_options: :return: Query Iterable of Documents. :rtype: query_iterable.QueryIterable """ if feed_options is None: feed_options = {} return self.QueryItems(collection_link, None, feed_options)
python
def ReadItems(self, collection_link, feed_options=None): """Reads all documents in a collection. :param str collection_link: The link to the document collection. :param dict feed_options: :return: Query Iterable of Documents. :rtype: query_iterable.QueryIterable """ if feed_options is None: feed_options = {} return self.QueryItems(collection_link, None, feed_options)
[ "def", "ReadItems", "(", "self", ",", "collection_link", ",", "feed_options", "=", "None", ")", ":", "if", "feed_options", "is", "None", ":", "feed_options", "=", "{", "}", "return", "self", ".", "QueryItems", "(", "collection_link", ",", "None", ",", "feed_options", ")" ]
Reads all documents in a collection. :param str collection_link: The link to the document collection. :param dict feed_options: :return: Query Iterable of Documents. :rtype: query_iterable.QueryIterable
[ "Reads", "all", "documents", "in", "a", "collection", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L819-L835
229,542
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.QueryItems
def QueryItems(self, database_or_Container_link, query, options=None, partition_key=None): """Queries documents in a collection. :param str database_or_Container_link: The link to the database when using partitioning, otherwise link to the document collection. :param (str or dict) query: :param dict options: The request options for the request. :param str partition_key: Partition key for the query(default value None) :return: Query Iterable of Documents. :rtype: query_iterable.QueryIterable """ database_or_Container_link = base.TrimBeginningAndEndingSlashes(database_or_Container_link) if options is None: options = {} if(base.IsDatabaseLink(database_or_Container_link)): # Python doesn't have a good way of specifying an overloaded constructor, and this is how it's generally overloaded constructors are specified(by calling a @classmethod) and returning the 'self' instance return query_iterable.QueryIterable.PartitioningQueryIterable(self, query, options, database_or_Container_link, partition_key) else: path = base.GetPathFromLink(database_or_Container_link, 'docs') collection_id = base.GetResourceIdOrFullNameFromLink(database_or_Container_link) def fetch_fn(options): return self.__QueryFeed(path, 'docs', collection_id, lambda r: r['Documents'], lambda _, b: b, query, options), self.last_response_headers return query_iterable.QueryIterable(self, query, options, fetch_fn, database_or_Container_link)
python
def QueryItems(self, database_or_Container_link, query, options=None, partition_key=None): """Queries documents in a collection. :param str database_or_Container_link: The link to the database when using partitioning, otherwise link to the document collection. :param (str or dict) query: :param dict options: The request options for the request. :param str partition_key: Partition key for the query(default value None) :return: Query Iterable of Documents. :rtype: query_iterable.QueryIterable """ database_or_Container_link = base.TrimBeginningAndEndingSlashes(database_or_Container_link) if options is None: options = {} if(base.IsDatabaseLink(database_or_Container_link)): # Python doesn't have a good way of specifying an overloaded constructor, and this is how it's generally overloaded constructors are specified(by calling a @classmethod) and returning the 'self' instance return query_iterable.QueryIterable.PartitioningQueryIterable(self, query, options, database_or_Container_link, partition_key) else: path = base.GetPathFromLink(database_or_Container_link, 'docs') collection_id = base.GetResourceIdOrFullNameFromLink(database_or_Container_link) def fetch_fn(options): return self.__QueryFeed(path, 'docs', collection_id, lambda r: r['Documents'], lambda _, b: b, query, options), self.last_response_headers return query_iterable.QueryIterable(self, query, options, fetch_fn, database_or_Container_link)
[ "def", "QueryItems", "(", "self", ",", "database_or_Container_link", ",", "query", ",", "options", "=", "None", ",", "partition_key", "=", "None", ")", ":", "database_or_Container_link", "=", "base", ".", "TrimBeginningAndEndingSlashes", "(", "database_or_Container_link", ")", "if", "options", "is", "None", ":", "options", "=", "{", "}", "if", "(", "base", ".", "IsDatabaseLink", "(", "database_or_Container_link", ")", ")", ":", "# Python doesn't have a good way of specifying an overloaded constructor, and this is how it's generally overloaded constructors are specified(by calling a @classmethod) and returning the 'self' instance", "return", "query_iterable", ".", "QueryIterable", ".", "PartitioningQueryIterable", "(", "self", ",", "query", ",", "options", ",", "database_or_Container_link", ",", "partition_key", ")", "else", ":", "path", "=", "base", ".", "GetPathFromLink", "(", "database_or_Container_link", ",", "'docs'", ")", "collection_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "database_or_Container_link", ")", "def", "fetch_fn", "(", "options", ")", ":", "return", "self", ".", "__QueryFeed", "(", "path", ",", "'docs'", ",", "collection_id", ",", "lambda", "r", ":", "r", "[", "'Documents'", "]", ",", "lambda", "_", ",", "b", ":", "b", ",", "query", ",", "options", ")", ",", "self", ".", "last_response_headers", "return", "query_iterable", ".", "QueryIterable", "(", "self", ",", "query", ",", "options", ",", "fetch_fn", ",", "database_or_Container_link", ")" ]
Queries documents in a collection. :param str database_or_Container_link: The link to the database when using partitioning, otherwise link to the document collection. :param (str or dict) query: :param dict options: The request options for the request. :param str partition_key: Partition key for the query(default value None) :return: Query Iterable of Documents. :rtype: query_iterable.QueryIterable
[ "Queries", "documents", "in", "a", "collection", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L837-L873
229,543
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.QueryItemsChangeFeed
def QueryItemsChangeFeed(self, collection_link, options=None): """Queries documents change feed in a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. options may also specify partition key range id. :return: Query Iterable of Documents. :rtype: query_iterable.QueryIterable """ partition_key_range_id = None if options is not None and 'partitionKeyRangeId' in options: partition_key_range_id = options['partitionKeyRangeId'] return self._QueryChangeFeed(collection_link, "Documents" , options, partition_key_range_id)
python
def QueryItemsChangeFeed(self, collection_link, options=None): """Queries documents change feed in a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. options may also specify partition key range id. :return: Query Iterable of Documents. :rtype: query_iterable.QueryIterable """ partition_key_range_id = None if options is not None and 'partitionKeyRangeId' in options: partition_key_range_id = options['partitionKeyRangeId'] return self._QueryChangeFeed(collection_link, "Documents" , options, partition_key_range_id)
[ "def", "QueryItemsChangeFeed", "(", "self", ",", "collection_link", ",", "options", "=", "None", ")", ":", "partition_key_range_id", "=", "None", "if", "options", "is", "not", "None", "and", "'partitionKeyRangeId'", "in", "options", ":", "partition_key_range_id", "=", "options", "[", "'partitionKeyRangeId'", "]", "return", "self", ".", "_QueryChangeFeed", "(", "collection_link", ",", "\"Documents\"", ",", "options", ",", "partition_key_range_id", ")" ]
Queries documents change feed in a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. options may also specify partition key range id. :return: Query Iterable of Documents. :rtype: query_iterable.QueryIterable
[ "Queries", "documents", "change", "feed", "in", "a", "collection", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L875-L895
229,544
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient._QueryChangeFeed
def _QueryChangeFeed(self, collection_link, resource_type, options=None, partition_key_range_id=None): """Queries change feed of a resource in a collection. :param str collection_link: The link to the document collection. :param str resource_type: The type of the resource. :param dict options: The request options for the request. :param str partition_key_range_id: Specifies partition key range id. :return: Query Iterable of Documents. :rtype: query_iterable.QueryIterable """ if options is None: options = {} options['changeFeed'] = True resource_key_map = {'Documents' : 'docs'} # For now, change feed only supports Documents and Partition Key Range resouce type if resource_type not in resource_key_map: raise NotImplementedError(resource_type + " change feed query is not supported.") resource_key = resource_key_map[resource_type] path = base.GetPathFromLink(collection_link, resource_key) collection_id = base.GetResourceIdOrFullNameFromLink(collection_link) def fetch_fn(options): return self.__QueryFeed(path, resource_key, collection_id, lambda r: r[resource_type], lambda _, b: b, None, options, partition_key_range_id), self.last_response_headers return query_iterable.QueryIterable(self, None, options, fetch_fn, collection_link)
python
def _QueryChangeFeed(self, collection_link, resource_type, options=None, partition_key_range_id=None): """Queries change feed of a resource in a collection. :param str collection_link: The link to the document collection. :param str resource_type: The type of the resource. :param dict options: The request options for the request. :param str partition_key_range_id: Specifies partition key range id. :return: Query Iterable of Documents. :rtype: query_iterable.QueryIterable """ if options is None: options = {} options['changeFeed'] = True resource_key_map = {'Documents' : 'docs'} # For now, change feed only supports Documents and Partition Key Range resouce type if resource_type not in resource_key_map: raise NotImplementedError(resource_type + " change feed query is not supported.") resource_key = resource_key_map[resource_type] path = base.GetPathFromLink(collection_link, resource_key) collection_id = base.GetResourceIdOrFullNameFromLink(collection_link) def fetch_fn(options): return self.__QueryFeed(path, resource_key, collection_id, lambda r: r[resource_type], lambda _, b: b, None, options, partition_key_range_id), self.last_response_headers return query_iterable.QueryIterable(self, None, options, fetch_fn, collection_link)
[ "def", "_QueryChangeFeed", "(", "self", ",", "collection_link", ",", "resource_type", ",", "options", "=", "None", ",", "partition_key_range_id", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "options", "[", "'changeFeed'", "]", "=", "True", "resource_key_map", "=", "{", "'Documents'", ":", "'docs'", "}", "# For now, change feed only supports Documents and Partition Key Range resouce type", "if", "resource_type", "not", "in", "resource_key_map", ":", "raise", "NotImplementedError", "(", "resource_type", "+", "\" change feed query is not supported.\"", ")", "resource_key", "=", "resource_key_map", "[", "resource_type", "]", "path", "=", "base", ".", "GetPathFromLink", "(", "collection_link", ",", "resource_key", ")", "collection_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "collection_link", ")", "def", "fetch_fn", "(", "options", ")", ":", "return", "self", ".", "__QueryFeed", "(", "path", ",", "resource_key", ",", "collection_id", ",", "lambda", "r", ":", "r", "[", "resource_type", "]", ",", "lambda", "_", ",", "b", ":", "b", ",", "None", ",", "options", ",", "partition_key_range_id", ")", ",", "self", ".", "last_response_headers", "return", "query_iterable", ".", "QueryIterable", "(", "self", ",", "None", ",", "options", ",", "fetch_fn", ",", "collection_link", ")" ]
Queries change feed of a resource in a collection. :param str collection_link: The link to the document collection. :param str resource_type: The type of the resource. :param dict options: The request options for the request. :param str partition_key_range_id: Specifies partition key range id. :return: Query Iterable of Documents. :rtype: query_iterable.QueryIterable
[ "Queries", "change", "feed", "of", "a", "resource", "in", "a", "collection", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L897-L937
229,545
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient._ReadPartitionKeyRanges
def _ReadPartitionKeyRanges(self, collection_link, feed_options=None): """Reads Partition Key Ranges. :param str collection_link: The link to the document collection. :param dict feed_options: :return: Query Iterable of PartitionKeyRanges. :rtype: query_iterable.QueryIterable """ if feed_options is None: feed_options = {} return self._QueryPartitionKeyRanges(collection_link, None, feed_options)
python
def _ReadPartitionKeyRanges(self, collection_link, feed_options=None): """Reads Partition Key Ranges. :param str collection_link: The link to the document collection. :param dict feed_options: :return: Query Iterable of PartitionKeyRanges. :rtype: query_iterable.QueryIterable """ if feed_options is None: feed_options = {} return self._QueryPartitionKeyRanges(collection_link, None, feed_options)
[ "def", "_ReadPartitionKeyRanges", "(", "self", ",", "collection_link", ",", "feed_options", "=", "None", ")", ":", "if", "feed_options", "is", "None", ":", "feed_options", "=", "{", "}", "return", "self", ".", "_QueryPartitionKeyRanges", "(", "collection_link", ",", "None", ",", "feed_options", ")" ]
Reads Partition Key Ranges. :param str collection_link: The link to the document collection. :param dict feed_options: :return: Query Iterable of PartitionKeyRanges. :rtype: query_iterable.QueryIterable
[ "Reads", "Partition", "Key", "Ranges", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L939-L955
229,546
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.CreateItem
def CreateItem(self, database_or_Container_link, document, options=None): """Creates a document in a collection. :param str database_or_Container_link: The link to the database when using partitioning, otherwise link to the document collection. :param dict document: The Azure Cosmos document to create. :param dict options: The request options for the request. :param bool options['disableAutomaticIdGeneration']: Disables the automatic id generation. If id is missing in the body and this option is true, an error will be returned. :return: The created Document. :rtype: dict """ # Python's default arguments are evaluated once when the function is defined, not each time the function is called (like it is in say, Ruby). # This means that if you use a mutable default argument and mutate it, you will and have mutated that object for all future calls to the function as well. # So, using a non-mutable deafult in this case(None) and assigning an empty dict(mutable) inside the method # For more details on this gotcha, please refer http://docs.python-guide.org/en/latest/writing/gotchas/ if options is None: options = {} # We check the link to be document collection link since it can be database link in case of client side partitioning if(base.IsItemContainerLink(database_or_Container_link)): options = self._AddPartitionKey(database_or_Container_link, document, options) collection_id, document, path = self._GetContainerIdWithPathForItem(database_or_Container_link, document, options) return self.Create(document, path, 'docs', collection_id, None, options)
python
def CreateItem(self, database_or_Container_link, document, options=None): """Creates a document in a collection. :param str database_or_Container_link: The link to the database when using partitioning, otherwise link to the document collection. :param dict document: The Azure Cosmos document to create. :param dict options: The request options for the request. :param bool options['disableAutomaticIdGeneration']: Disables the automatic id generation. If id is missing in the body and this option is true, an error will be returned. :return: The created Document. :rtype: dict """ # Python's default arguments are evaluated once when the function is defined, not each time the function is called (like it is in say, Ruby). # This means that if you use a mutable default argument and mutate it, you will and have mutated that object for all future calls to the function as well. # So, using a non-mutable deafult in this case(None) and assigning an empty dict(mutable) inside the method # For more details on this gotcha, please refer http://docs.python-guide.org/en/latest/writing/gotchas/ if options is None: options = {} # We check the link to be document collection link since it can be database link in case of client side partitioning if(base.IsItemContainerLink(database_or_Container_link)): options = self._AddPartitionKey(database_or_Container_link, document, options) collection_id, document, path = self._GetContainerIdWithPathForItem(database_or_Container_link, document, options) return self.Create(document, path, 'docs', collection_id, None, options)
[ "def", "CreateItem", "(", "self", ",", "database_or_Container_link", ",", "document", ",", "options", "=", "None", ")", ":", "# Python's default arguments are evaluated once when the function is defined, not each time the function is called (like it is in say, Ruby). ", "# This means that if you use a mutable default argument and mutate it, you will and have mutated that object for all future calls to the function as well.", "# So, using a non-mutable deafult in this case(None) and assigning an empty dict(mutable) inside the method", "# For more details on this gotcha, please refer http://docs.python-guide.org/en/latest/writing/gotchas/", "if", "options", "is", "None", ":", "options", "=", "{", "}", "# We check the link to be document collection link since it can be database link in case of client side partitioning", "if", "(", "base", ".", "IsItemContainerLink", "(", "database_or_Container_link", ")", ")", ":", "options", "=", "self", ".", "_AddPartitionKey", "(", "database_or_Container_link", ",", "document", ",", "options", ")", "collection_id", ",", "document", ",", "path", "=", "self", ".", "_GetContainerIdWithPathForItem", "(", "database_or_Container_link", ",", "document", ",", "options", ")", "return", "self", ".", "Create", "(", "document", ",", "path", ",", "'docs'", ",", "collection_id", ",", "None", ",", "options", ")" ]
Creates a document in a collection. :param str database_or_Container_link: The link to the database when using partitioning, otherwise link to the document collection. :param dict document: The Azure Cosmos document to create. :param dict options: The request options for the request. :param bool options['disableAutomaticIdGeneration']: Disables the automatic id generation. If id is missing in the body and this option is true, an error will be returned. :return: The created Document. :rtype: dict
[ "Creates", "a", "document", "in", "a", "collection", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L987-L1023
229,547
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.UpsertItem
def UpsertItem(self, database_or_Container_link, document, options=None): """Upserts a document in a collection. :param str database_or_Container_link: The link to the database when using partitioning, otherwise link to the document collection. :param dict document: The Azure Cosmos document to upsert. :param dict options: The request options for the request. :param bool options['disableAutomaticIdGeneration']: Disables the automatic id generation. If id is missing in the body and this option is true, an error will be returned. :return: The upserted Document. :rtype: dict """ # Python's default arguments are evaluated once when the function is defined, not each time the function is called (like it is in say, Ruby). # This means that if you use a mutable default argument and mutate it, you will and have mutated that object for all future calls to the function as well. # So, using a non-mutable deafult in this case(None) and assigning an empty dict(mutable) inside the method # For more details on this gotcha, please refer http://docs.python-guide.org/en/latest/writing/gotchas/ if options is None: options = {} # We check the link to be document collection link since it can be database link in case of client side partitioning if(base.IsItemContainerLink(database_or_Container_link)): options = self._AddPartitionKey(database_or_Container_link, document, options) collection_id, document, path = self._GetContainerIdWithPathForItem(database_or_Container_link, document, options) return self.Upsert(document, path, 'docs', collection_id, None, options)
python
def UpsertItem(self, database_or_Container_link, document, options=None): """Upserts a document in a collection. :param str database_or_Container_link: The link to the database when using partitioning, otherwise link to the document collection. :param dict document: The Azure Cosmos document to upsert. :param dict options: The request options for the request. :param bool options['disableAutomaticIdGeneration']: Disables the automatic id generation. If id is missing in the body and this option is true, an error will be returned. :return: The upserted Document. :rtype: dict """ # Python's default arguments are evaluated once when the function is defined, not each time the function is called (like it is in say, Ruby). # This means that if you use a mutable default argument and mutate it, you will and have mutated that object for all future calls to the function as well. # So, using a non-mutable deafult in this case(None) and assigning an empty dict(mutable) inside the method # For more details on this gotcha, please refer http://docs.python-guide.org/en/latest/writing/gotchas/ if options is None: options = {} # We check the link to be document collection link since it can be database link in case of client side partitioning if(base.IsItemContainerLink(database_or_Container_link)): options = self._AddPartitionKey(database_or_Container_link, document, options) collection_id, document, path = self._GetContainerIdWithPathForItem(database_or_Container_link, document, options) return self.Upsert(document, path, 'docs', collection_id, None, options)
[ "def", "UpsertItem", "(", "self", ",", "database_or_Container_link", ",", "document", ",", "options", "=", "None", ")", ":", "# Python's default arguments are evaluated once when the function is defined, not each time the function is called (like it is in say, Ruby). ", "# This means that if you use a mutable default argument and mutate it, you will and have mutated that object for all future calls to the function as well.", "# So, using a non-mutable deafult in this case(None) and assigning an empty dict(mutable) inside the method", "# For more details on this gotcha, please refer http://docs.python-guide.org/en/latest/writing/gotchas/", "if", "options", "is", "None", ":", "options", "=", "{", "}", "# We check the link to be document collection link since it can be database link in case of client side partitioning", "if", "(", "base", ".", "IsItemContainerLink", "(", "database_or_Container_link", ")", ")", ":", "options", "=", "self", ".", "_AddPartitionKey", "(", "database_or_Container_link", ",", "document", ",", "options", ")", "collection_id", ",", "document", ",", "path", "=", "self", ".", "_GetContainerIdWithPathForItem", "(", "database_or_Container_link", ",", "document", ",", "options", ")", "return", "self", ".", "Upsert", "(", "document", ",", "path", ",", "'docs'", ",", "collection_id", ",", "None", ",", "options", ")" ]
Upserts a document in a collection. :param str database_or_Container_link: The link to the database when using partitioning, otherwise link to the document collection. :param dict document: The Azure Cosmos document to upsert. :param dict options: The request options for the request. :param bool options['disableAutomaticIdGeneration']: Disables the automatic id generation. If id is missing in the body and this option is true, an error will be returned. :return: The upserted Document. :rtype: dict
[ "Upserts", "a", "document", "in", "a", "collection", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1025-L1061
229,548
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadItem
def ReadItem(self, document_link, options=None): """Reads a document. :param str document_link: The link to the document. :param dict options: The request options for the request. :return: The read Document. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(document_link) document_id = base.GetResourceIdOrFullNameFromLink(document_link) return self.Read(path, 'docs', document_id, None, options)
python
def ReadItem(self, document_link, options=None): """Reads a document. :param str document_link: The link to the document. :param dict options: The request options for the request. :return: The read Document. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(document_link) document_id = base.GetResourceIdOrFullNameFromLink(document_link) return self.Read(path, 'docs', document_id, None, options)
[ "def", "ReadItem", "(", "self", ",", "document_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "document_link", ")", "document_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "document_link", ")", "return", "self", ".", "Read", "(", "path", ",", "'docs'", ",", "document_id", ",", "None", ",", "options", ")" ]
Reads a document. :param str document_link: The link to the document. :param dict options: The request options for the request. :return: The read Document. :rtype: dict
[ "Reads", "a", "document", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1094-L1117
229,549
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadTriggers
def ReadTriggers(self, collection_link, options=None): """Reads all triggers in a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: Query Iterable of Triggers. :rtype: query_iterable.QueryIterable """ if options is None: options = {} return self.QueryTriggers(collection_link, None, options)
python
def ReadTriggers(self, collection_link, options=None): """Reads all triggers in a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: Query Iterable of Triggers. :rtype: query_iterable.QueryIterable """ if options is None: options = {} return self.QueryTriggers(collection_link, None, options)
[ "def", "ReadTriggers", "(", "self", ",", "collection_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "return", "self", ".", "QueryTriggers", "(", "collection_link", ",", "None", ",", "options", ")" ]
Reads all triggers in a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: Query Iterable of Triggers. :rtype: query_iterable.QueryIterable
[ "Reads", "all", "triggers", "in", "a", "collection", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1119-L1136
229,550
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.CreateTrigger
def CreateTrigger(self, collection_link, trigger, options=None): """Creates a trigger in a collection. :param str collection_link: The link to the document collection. :param dict trigger: :param dict options: The request options for the request. :return: The created Trigger. :rtype: dict """ if options is None: options = {} collection_id, path, trigger = self._GetContainerIdWithPathForTrigger(collection_link, trigger) return self.Create(trigger, path, 'triggers', collection_id, None, options)
python
def CreateTrigger(self, collection_link, trigger, options=None): """Creates a trigger in a collection. :param str collection_link: The link to the document collection. :param dict trigger: :param dict options: The request options for the request. :return: The created Trigger. :rtype: dict """ if options is None: options = {} collection_id, path, trigger = self._GetContainerIdWithPathForTrigger(collection_link, trigger) return self.Create(trigger, path, 'triggers', collection_id, None, options)
[ "def", "CreateTrigger", "(", "self", ",", "collection_link", ",", "trigger", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "collection_id", ",", "path", ",", "trigger", "=", "self", ".", "_GetContainerIdWithPathForTrigger", "(", "collection_link", ",", "trigger", ")", "return", "self", ".", "Create", "(", "trigger", ",", "path", ",", "'triggers'", ",", "collection_id", ",", "None", ",", "options", ")" ]
Creates a trigger in a collection. :param str collection_link: The link to the document collection. :param dict trigger: :param dict options: The request options for the request. :return: The created Trigger. :rtype: dict
[ "Creates", "a", "trigger", "in", "a", "collection", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1168-L1192
229,551
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.UpsertTrigger
def UpsertTrigger(self, collection_link, trigger, options=None): """Upserts a trigger in a collection. :param str collection_link: The link to the document collection. :param dict trigger: :param dict options: The request options for the request. :return: The upserted Trigger. :rtype: dict """ if options is None: options = {} collection_id, path, trigger = self._GetContainerIdWithPathForTrigger(collection_link, trigger) return self.Upsert(trigger, path, 'triggers', collection_id, None, options)
python
def UpsertTrigger(self, collection_link, trigger, options=None): """Upserts a trigger in a collection. :param str collection_link: The link to the document collection. :param dict trigger: :param dict options: The request options for the request. :return: The upserted Trigger. :rtype: dict """ if options is None: options = {} collection_id, path, trigger = self._GetContainerIdWithPathForTrigger(collection_link, trigger) return self.Upsert(trigger, path, 'triggers', collection_id, None, options)
[ "def", "UpsertTrigger", "(", "self", ",", "collection_link", ",", "trigger", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "collection_id", ",", "path", ",", "trigger", "=", "self", ".", "_GetContainerIdWithPathForTrigger", "(", "collection_link", ",", "trigger", ")", "return", "self", ".", "Upsert", "(", "trigger", ",", "path", ",", "'triggers'", ",", "collection_id", ",", "None", ",", "options", ")" ]
Upserts a trigger in a collection. :param str collection_link: The link to the document collection. :param dict trigger: :param dict options: The request options for the request. :return: The upserted Trigger. :rtype: dict
[ "Upserts", "a", "trigger", "in", "a", "collection", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1194-L1218
229,552
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadTrigger
def ReadTrigger(self, trigger_link, options=None): """Reads a trigger. :param str trigger_link: The link to the trigger. :param dict options: The request options for the request. :return: The read Trigger. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(trigger_link) trigger_id = base.GetResourceIdOrFullNameFromLink(trigger_link) return self.Read(path, 'triggers', trigger_id, None, options)
python
def ReadTrigger(self, trigger_link, options=None): """Reads a trigger. :param str trigger_link: The link to the trigger. :param dict options: The request options for the request. :return: The read Trigger. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(trigger_link) trigger_id = base.GetResourceIdOrFullNameFromLink(trigger_link) return self.Read(path, 'triggers', trigger_id, None, options)
[ "def", "ReadTrigger", "(", "self", ",", "trigger_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "trigger_link", ")", "trigger_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "trigger_link", ")", "return", "self", ".", "Read", "(", "path", ",", "'triggers'", ",", "trigger_id", ",", "None", ",", "options", ")" ]
Reads a trigger. :param str trigger_link: The link to the trigger. :param dict options: The request options for the request. :return: The read Trigger. :rtype: dict
[ "Reads", "a", "trigger", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1233-L1252
229,553
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadUserDefinedFunctions
def ReadUserDefinedFunctions(self, collection_link, options=None): """Reads all user defined functions in a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: Query Iterable of UDFs. :rtype: query_iterable.QueryIterable """ if options is None: options = {} return self.QueryUserDefinedFunctions(collection_link, None, options)
python
def ReadUserDefinedFunctions(self, collection_link, options=None): """Reads all user defined functions in a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: Query Iterable of UDFs. :rtype: query_iterable.QueryIterable """ if options is None: options = {} return self.QueryUserDefinedFunctions(collection_link, None, options)
[ "def", "ReadUserDefinedFunctions", "(", "self", ",", "collection_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "return", "self", ".", "QueryUserDefinedFunctions", "(", "collection_link", ",", "None", ",", "options", ")" ]
Reads all user defined functions in a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: Query Iterable of UDFs. :rtype: query_iterable.QueryIterable
[ "Reads", "all", "user", "defined", "functions", "in", "a", "collection", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1254-L1271
229,554
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.QueryUserDefinedFunctions
def QueryUserDefinedFunctions(self, collection_link, query, options=None): """Queries user defined functions in a collection. :param str collection_link: The link to the collection. :param (str or dict) query: :param dict options: The request options for the request. :return: Query Iterable of UDFs. :rtype: query_iterable.QueryIterable """ if options is None: options = {} path = base.GetPathFromLink(collection_link, 'udfs') collection_id = base.GetResourceIdOrFullNameFromLink(collection_link) def fetch_fn(options): return self.__QueryFeed(path, 'udfs', collection_id, lambda r: r['UserDefinedFunctions'], lambda _, b: b, query, options), self.last_response_headers return query_iterable.QueryIterable(self, query, options, fetch_fn)
python
def QueryUserDefinedFunctions(self, collection_link, query, options=None): """Queries user defined functions in a collection. :param str collection_link: The link to the collection. :param (str or dict) query: :param dict options: The request options for the request. :return: Query Iterable of UDFs. :rtype: query_iterable.QueryIterable """ if options is None: options = {} path = base.GetPathFromLink(collection_link, 'udfs') collection_id = base.GetResourceIdOrFullNameFromLink(collection_link) def fetch_fn(options): return self.__QueryFeed(path, 'udfs', collection_id, lambda r: r['UserDefinedFunctions'], lambda _, b: b, query, options), self.last_response_headers return query_iterable.QueryIterable(self, query, options, fetch_fn)
[ "def", "QueryUserDefinedFunctions", "(", "self", ",", "collection_link", ",", "query", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "collection_link", ",", "'udfs'", ")", "collection_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "collection_link", ")", "def", "fetch_fn", "(", "options", ")", ":", "return", "self", ".", "__QueryFeed", "(", "path", ",", "'udfs'", ",", "collection_id", ",", "lambda", "r", ":", "r", "[", "'UserDefinedFunctions'", "]", ",", "lambda", "_", ",", "b", ":", "b", ",", "query", ",", "options", ")", ",", "self", ".", "last_response_headers", "return", "query_iterable", ".", "QueryIterable", "(", "self", ",", "query", ",", "options", ",", "fetch_fn", ")" ]
Queries user defined functions in a collection. :param str collection_link: The link to the collection. :param (str or dict) query: :param dict options: The request options for the request. :return: Query Iterable of UDFs. :rtype: query_iterable.QueryIterable
[ "Queries", "user", "defined", "functions", "in", "a", "collection", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1273-L1301
229,555
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.CreateUserDefinedFunction
def CreateUserDefinedFunction(self, collection_link, udf, options=None): """Creates a user defined function in a collection. :param str collection_link: The link to the collection. :param str udf: :param dict options: The request options for the request. :return: The created UDF. :rtype: dict """ if options is None: options = {} collection_id, path, udf = self._GetContainerIdWithPathForUDF(collection_link, udf) return self.Create(udf, path, 'udfs', collection_id, None, options)
python
def CreateUserDefinedFunction(self, collection_link, udf, options=None): """Creates a user defined function in a collection. :param str collection_link: The link to the collection. :param str udf: :param dict options: The request options for the request. :return: The created UDF. :rtype: dict """ if options is None: options = {} collection_id, path, udf = self._GetContainerIdWithPathForUDF(collection_link, udf) return self.Create(udf, path, 'udfs', collection_id, None, options)
[ "def", "CreateUserDefinedFunction", "(", "self", ",", "collection_link", ",", "udf", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "collection_id", ",", "path", ",", "udf", "=", "self", ".", "_GetContainerIdWithPathForUDF", "(", "collection_link", ",", "udf", ")", "return", "self", ".", "Create", "(", "udf", ",", "path", ",", "'udfs'", ",", "collection_id", ",", "None", ",", "options", ")" ]
Creates a user defined function in a collection. :param str collection_link: The link to the collection. :param str udf: :param dict options: The request options for the request. :return: The created UDF. :rtype: dict
[ "Creates", "a", "user", "defined", "function", "in", "a", "collection", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1303-L1327
229,556
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.UpsertUserDefinedFunction
def UpsertUserDefinedFunction(self, collection_link, udf, options=None): """Upserts a user defined function in a collection. :param str collection_link: The link to the collection. :param str udf: :param dict options: The request options for the request. :return: The upserted UDF. :rtype: dict """ if options is None: options = {} collection_id, path, udf = self._GetContainerIdWithPathForUDF(collection_link, udf) return self.Upsert(udf, path, 'udfs', collection_id, None, options)
python
def UpsertUserDefinedFunction(self, collection_link, udf, options=None): """Upserts a user defined function in a collection. :param str collection_link: The link to the collection. :param str udf: :param dict options: The request options for the request. :return: The upserted UDF. :rtype: dict """ if options is None: options = {} collection_id, path, udf = self._GetContainerIdWithPathForUDF(collection_link, udf) return self.Upsert(udf, path, 'udfs', collection_id, None, options)
[ "def", "UpsertUserDefinedFunction", "(", "self", ",", "collection_link", ",", "udf", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "collection_id", ",", "path", ",", "udf", "=", "self", ".", "_GetContainerIdWithPathForUDF", "(", "collection_link", ",", "udf", ")", "return", "self", ".", "Upsert", "(", "udf", ",", "path", ",", "'udfs'", ",", "collection_id", ",", "None", ",", "options", ")" ]
Upserts a user defined function in a collection. :param str collection_link: The link to the collection. :param str udf: :param dict options: The request options for the request. :return: The upserted UDF. :rtype: dict
[ "Upserts", "a", "user", "defined", "function", "in", "a", "collection", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1329-L1353
229,557
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadUserDefinedFunction
def ReadUserDefinedFunction(self, udf_link, options=None): """Reads a user defined function. :param str udf_link: The link to the user defined function. :param dict options: The request options for the request. :return: The read UDF. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(udf_link) udf_id = base.GetResourceIdOrFullNameFromLink(udf_link) return self.Read(path, 'udfs', udf_id, None, options)
python
def ReadUserDefinedFunction(self, udf_link, options=None): """Reads a user defined function. :param str udf_link: The link to the user defined function. :param dict options: The request options for the request. :return: The read UDF. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(udf_link) udf_id = base.GetResourceIdOrFullNameFromLink(udf_link) return self.Read(path, 'udfs', udf_id, None, options)
[ "def", "ReadUserDefinedFunction", "(", "self", ",", "udf_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "udf_link", ")", "udf_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "udf_link", ")", "return", "self", ".", "Read", "(", "path", ",", "'udfs'", ",", "udf_id", ",", "None", ",", "options", ")" ]
Reads a user defined function. :param str udf_link: The link to the user defined function. :param dict options: The request options for the request. :return: The read UDF. :rtype: dict
[ "Reads", "a", "user", "defined", "function", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1368-L1387
229,558
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadStoredProcedures
def ReadStoredProcedures(self, collection_link, options=None): """Reads all store procedures in a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: Query Iterable of Stored Procedures. :rtype: query_iterable.QueryIterable """ if options is None: options = {} return self.QueryStoredProcedures(collection_link, None, options)
python
def ReadStoredProcedures(self, collection_link, options=None): """Reads all store procedures in a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: Query Iterable of Stored Procedures. :rtype: query_iterable.QueryIterable """ if options is None: options = {} return self.QueryStoredProcedures(collection_link, None, options)
[ "def", "ReadStoredProcedures", "(", "self", ",", "collection_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "return", "self", ".", "QueryStoredProcedures", "(", "collection_link", ",", "None", ",", "options", ")" ]
Reads all store procedures in a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: Query Iterable of Stored Procedures. :rtype: query_iterable.QueryIterable
[ "Reads", "all", "store", "procedures", "in", "a", "collection", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1389-L1406
229,559
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.CreateStoredProcedure
def CreateStoredProcedure(self, collection_link, sproc, options=None): """Creates a stored procedure in a collection. :param str collection_link: The link to the document collection. :param str sproc: :param dict options: The request options for the request. :return: The created Stored Procedure. :rtype: dict """ if options is None: options = {} collection_id, path, sproc = self._GetContainerIdWithPathForSproc(collection_link, sproc) return self.Create(sproc, path, 'sprocs', collection_id, None, options)
python
def CreateStoredProcedure(self, collection_link, sproc, options=None): """Creates a stored procedure in a collection. :param str collection_link: The link to the document collection. :param str sproc: :param dict options: The request options for the request. :return: The created Stored Procedure. :rtype: dict """ if options is None: options = {} collection_id, path, sproc = self._GetContainerIdWithPathForSproc(collection_link, sproc) return self.Create(sproc, path, 'sprocs', collection_id, None, options)
[ "def", "CreateStoredProcedure", "(", "self", ",", "collection_link", ",", "sproc", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "collection_id", ",", "path", ",", "sproc", "=", "self", ".", "_GetContainerIdWithPathForSproc", "(", "collection_link", ",", "sproc", ")", "return", "self", ".", "Create", "(", "sproc", ",", "path", ",", "'sprocs'", ",", "collection_id", ",", "None", ",", "options", ")" ]
Creates a stored procedure in a collection. :param str collection_link: The link to the document collection. :param str sproc: :param dict options: The request options for the request. :return: The created Stored Procedure. :rtype: dict
[ "Creates", "a", "stored", "procedure", "in", "a", "collection", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1438-L1462
229,560
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.UpsertStoredProcedure
def UpsertStoredProcedure(self, collection_link, sproc, options=None): """Upserts a stored procedure in a collection. :param str collection_link: The link to the document collection. :param str sproc: :param dict options: The request options for the request. :return: The upserted Stored Procedure. :rtype: dict """ if options is None: options = {} collection_id, path, sproc = self._GetContainerIdWithPathForSproc(collection_link, sproc) return self.Upsert(sproc, path, 'sprocs', collection_id, None, options)
python
def UpsertStoredProcedure(self, collection_link, sproc, options=None): """Upserts a stored procedure in a collection. :param str collection_link: The link to the document collection. :param str sproc: :param dict options: The request options for the request. :return: The upserted Stored Procedure. :rtype: dict """ if options is None: options = {} collection_id, path, sproc = self._GetContainerIdWithPathForSproc(collection_link, sproc) return self.Upsert(sproc, path, 'sprocs', collection_id, None, options)
[ "def", "UpsertStoredProcedure", "(", "self", ",", "collection_link", ",", "sproc", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "collection_id", ",", "path", ",", "sproc", "=", "self", ".", "_GetContainerIdWithPathForSproc", "(", "collection_link", ",", "sproc", ")", "return", "self", ".", "Upsert", "(", "sproc", ",", "path", ",", "'sprocs'", ",", "collection_id", ",", "None", ",", "options", ")" ]
Upserts a stored procedure in a collection. :param str collection_link: The link to the document collection. :param str sproc: :param dict options: The request options for the request. :return: The upserted Stored Procedure. :rtype: dict
[ "Upserts", "a", "stored", "procedure", "in", "a", "collection", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1464-L1488
229,561
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadStoredProcedure
def ReadStoredProcedure(self, sproc_link, options=None): """Reads a stored procedure. :param str sproc_link: The link to the stored procedure. :param dict options: The request options for the request. :return: The read Stored Procedure. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(sproc_link) sproc_id = base.GetResourceIdOrFullNameFromLink(sproc_link) return self.Read(path, 'sprocs', sproc_id, None, options)
python
def ReadStoredProcedure(self, sproc_link, options=None): """Reads a stored procedure. :param str sproc_link: The link to the stored procedure. :param dict options: The request options for the request. :return: The read Stored Procedure. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(sproc_link) sproc_id = base.GetResourceIdOrFullNameFromLink(sproc_link) return self.Read(path, 'sprocs', sproc_id, None, options)
[ "def", "ReadStoredProcedure", "(", "self", ",", "sproc_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "sproc_link", ")", "sproc_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "sproc_link", ")", "return", "self", ".", "Read", "(", "path", ",", "'sprocs'", ",", "sproc_id", ",", "None", ",", "options", ")" ]
Reads a stored procedure. :param str sproc_link: The link to the stored procedure. :param dict options: The request options for the request. :return: The read Stored Procedure. :rtype: dict
[ "Reads", "a", "stored", "procedure", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1502-L1521
229,562
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadConflicts
def ReadConflicts(self, collection_link, feed_options=None): """Reads conflicts. :param str collection_link: The link to the document collection. :param dict feed_options: :return: Query Iterable of Conflicts. :rtype: query_iterable.QueryIterable """ if feed_options is None: feed_options = {} return self.QueryConflicts(collection_link, None, feed_options)
python
def ReadConflicts(self, collection_link, feed_options=None): """Reads conflicts. :param str collection_link: The link to the document collection. :param dict feed_options: :return: Query Iterable of Conflicts. :rtype: query_iterable.QueryIterable """ if feed_options is None: feed_options = {} return self.QueryConflicts(collection_link, None, feed_options)
[ "def", "ReadConflicts", "(", "self", ",", "collection_link", ",", "feed_options", "=", "None", ")", ":", "if", "feed_options", "is", "None", ":", "feed_options", "=", "{", "}", "return", "self", ".", "QueryConflicts", "(", "collection_link", ",", "None", ",", "feed_options", ")" ]
Reads conflicts. :param str collection_link: The link to the document collection. :param dict feed_options: :return: Query Iterable of Conflicts. :rtype: query_iterable.QueryIterable
[ "Reads", "conflicts", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1523-L1539
229,563
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadConflict
def ReadConflict(self, conflict_link, options=None): """Reads a conflict. :param str conflict_link: The link to the conflict. :param dict options: :return: The read Conflict. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(conflict_link) conflict_id = base.GetResourceIdOrFullNameFromLink(conflict_link) return self.Read(path, 'conflicts', conflict_id, None, options)
python
def ReadConflict(self, conflict_link, options=None): """Reads a conflict. :param str conflict_link: The link to the conflict. :param dict options: :return: The read Conflict. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(conflict_link) conflict_id = base.GetResourceIdOrFullNameFromLink(conflict_link) return self.Read(path, 'conflicts', conflict_id, None, options)
[ "def", "ReadConflict", "(", "self", ",", "conflict_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "conflict_link", ")", "conflict_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "conflict_link", ")", "return", "self", ".", "Read", "(", "path", ",", "'conflicts'", ",", "conflict_id", ",", "None", ",", "options", ")" ]
Reads a conflict. :param str conflict_link: The link to the conflict. :param dict options: :return: The read Conflict. :rtype: dict
[ "Reads", "a", "conflict", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1571-L1593
229,564
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.DeleteContainer
def DeleteContainer(self, collection_link, options=None): """Deletes a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: The deleted Collection. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(collection_link) collection_id = base.GetResourceIdOrFullNameFromLink(collection_link) return self.DeleteResource(path, 'colls', collection_id, None, options)
python
def DeleteContainer(self, collection_link, options=None): """Deletes a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: The deleted Collection. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(collection_link) collection_id = base.GetResourceIdOrFullNameFromLink(collection_link) return self.DeleteResource(path, 'colls', collection_id, None, options)
[ "def", "DeleteContainer", "(", "self", ",", "collection_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "collection_link", ")", "collection_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "collection_link", ")", "return", "self", ".", "DeleteResource", "(", "path", ",", "'colls'", ",", "collection_id", ",", "None", ",", "options", ")" ]
Deletes a collection. :param str collection_link: The link to the document collection. :param dict options: The request options for the request. :return: The deleted Collection. :rtype: dict
[ "Deletes", "a", "collection", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1595-L1618
229,565
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReplaceItem
def ReplaceItem(self, document_link, new_document, options=None): """Replaces a document and returns it. :param str document_link: The link to the document. :param dict new_document: :param dict options: The request options for the request. :return: The new Document. :rtype: dict """ CosmosClient.__ValidateResource(new_document) path = base.GetPathFromLink(document_link) document_id = base.GetResourceIdOrFullNameFromLink(document_link) # Python's default arguments are evaluated once when the function is defined, not each time the function is called (like it is in say, Ruby). # This means that if you use a mutable default argument and mutate it, you will and have mutated that object for all future calls to the function as well. # So, using a non-mutable deafult in this case(None) and assigning an empty dict(mutable) inside the function so that it remains local # For more details on this gotcha, please refer http://docs.python-guide.org/en/latest/writing/gotchas/ if options is None: options = {} # Extract the document collection link and add the partition key to options collection_link = base.GetItemContainerLink(document_link) options = self._AddPartitionKey(collection_link, new_document, options) return self.Replace(new_document, path, 'docs', document_id, None, options)
python
def ReplaceItem(self, document_link, new_document, options=None): """Replaces a document and returns it. :param str document_link: The link to the document. :param dict new_document: :param dict options: The request options for the request. :return: The new Document. :rtype: dict """ CosmosClient.__ValidateResource(new_document) path = base.GetPathFromLink(document_link) document_id = base.GetResourceIdOrFullNameFromLink(document_link) # Python's default arguments are evaluated once when the function is defined, not each time the function is called (like it is in say, Ruby). # This means that if you use a mutable default argument and mutate it, you will and have mutated that object for all future calls to the function as well. # So, using a non-mutable deafult in this case(None) and assigning an empty dict(mutable) inside the function so that it remains local # For more details on this gotcha, please refer http://docs.python-guide.org/en/latest/writing/gotchas/ if options is None: options = {} # Extract the document collection link and add the partition key to options collection_link = base.GetItemContainerLink(document_link) options = self._AddPartitionKey(collection_link, new_document, options) return self.Replace(new_document, path, 'docs', document_id, None, options)
[ "def", "ReplaceItem", "(", "self", ",", "document_link", ",", "new_document", ",", "options", "=", "None", ")", ":", "CosmosClient", ".", "__ValidateResource", "(", "new_document", ")", "path", "=", "base", ".", "GetPathFromLink", "(", "document_link", ")", "document_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "document_link", ")", "# Python's default arguments are evaluated once when the function is defined, not each time the function is called (like it is in say, Ruby). ", "# This means that if you use a mutable default argument and mutate it, you will and have mutated that object for all future calls to the function as well.", "# So, using a non-mutable deafult in this case(None) and assigning an empty dict(mutable) inside the function so that it remains local", "# For more details on this gotcha, please refer http://docs.python-guide.org/en/latest/writing/gotchas/", "if", "options", "is", "None", ":", "options", "=", "{", "}", "# Extract the document collection link and add the partition key to options", "collection_link", "=", "base", ".", "GetItemContainerLink", "(", "document_link", ")", "options", "=", "self", ".", "_AddPartitionKey", "(", "collection_link", ",", "new_document", ",", "options", ")", "return", "self", ".", "Replace", "(", "new_document", ",", "path", ",", "'docs'", ",", "document_id", ",", "None", ",", "options", ")" ]
Replaces a document and returns it. :param str document_link: The link to the document. :param dict new_document: :param dict options: The request options for the request. :return: The new Document. :rtype: dict
[ "Replaces", "a", "document", "and", "returns", "it", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1620-L1655
229,566
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.CreateAttachment
def CreateAttachment(self, document_link, attachment, options=None): """Creates an attachment in a document. :param str document_link: The link to the document. :param dict attachment: The Azure Cosmos attachment to create. :param dict options: The request options for the request. :return: The created Attachment. :rtype: dict """ if options is None: options = {} document_id, path = self._GetItemIdWithPathForAttachment(attachment, document_link) return self.Create(attachment, path, 'attachments', document_id, None, options)
python
def CreateAttachment(self, document_link, attachment, options=None): """Creates an attachment in a document. :param str document_link: The link to the document. :param dict attachment: The Azure Cosmos attachment to create. :param dict options: The request options for the request. :return: The created Attachment. :rtype: dict """ if options is None: options = {} document_id, path = self._GetItemIdWithPathForAttachment(attachment, document_link) return self.Create(attachment, path, 'attachments', document_id, None, options)
[ "def", "CreateAttachment", "(", "self", ",", "document_link", ",", "attachment", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "document_id", ",", "path", "=", "self", ".", "_GetItemIdWithPathForAttachment", "(", "attachment", ",", "document_link", ")", "return", "self", ".", "Create", "(", "attachment", ",", "path", ",", "'attachments'", ",", "document_id", ",", "None", ",", "options", ")" ]
Creates an attachment in a document. :param str document_link: The link to the document. :param dict attachment: The Azure Cosmos attachment to create. :param dict options: The request options for the request. :return: The created Attachment. :rtype: dict
[ "Creates", "an", "attachment", "in", "a", "document", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1682-L1707
229,567
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.UpsertAttachment
def UpsertAttachment(self, document_link, attachment, options=None): """Upserts an attachment in a document. :param str document_link: The link to the document. :param dict attachment: The Azure Cosmos attachment to upsert. :param dict options: The request options for the request. :return: The upserted Attachment. :rtype: dict """ if options is None: options = {} document_id, path = self._GetItemIdWithPathForAttachment(attachment, document_link) return self.Upsert(attachment, path, 'attachments', document_id, None, options)
python
def UpsertAttachment(self, document_link, attachment, options=None): """Upserts an attachment in a document. :param str document_link: The link to the document. :param dict attachment: The Azure Cosmos attachment to upsert. :param dict options: The request options for the request. :return: The upserted Attachment. :rtype: dict """ if options is None: options = {} document_id, path = self._GetItemIdWithPathForAttachment(attachment, document_link) return self.Upsert(attachment, path, 'attachments', document_id, None, options)
[ "def", "UpsertAttachment", "(", "self", ",", "document_link", ",", "attachment", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "document_id", ",", "path", "=", "self", ".", "_GetItemIdWithPathForAttachment", "(", "attachment", ",", "document_link", ")", "return", "self", ".", "Upsert", "(", "attachment", ",", "path", ",", "'attachments'", ",", "document_id", ",", "None", ",", "options", ")" ]
Upserts an attachment in a document. :param str document_link: The link to the document. :param dict attachment: The Azure Cosmos attachment to upsert. :param dict options: The request options for the request. :return: The upserted Attachment. :rtype: dict
[ "Upserts", "an", "attachment", "in", "a", "document", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1709-L1734
229,568
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.CreateAttachmentAndUploadMedia
def CreateAttachmentAndUploadMedia(self, document_link, readable_stream, options=None): """Creates an attachment and upload media. :param str document_link: The link to the document. :param (file-like stream object) readable_stream: :param dict options: The request options for the request. :return: The created Attachment. :rtype: dict """ if options is None: options = {} document_id, initial_headers, path = self._GetItemIdWithPathForAttachmentMedia(document_link, options) return self.Create(readable_stream, path, 'attachments', document_id, initial_headers, options)
python
def CreateAttachmentAndUploadMedia(self, document_link, readable_stream, options=None): """Creates an attachment and upload media. :param str document_link: The link to the document. :param (file-like stream object) readable_stream: :param dict options: The request options for the request. :return: The created Attachment. :rtype: dict """ if options is None: options = {} document_id, initial_headers, path = self._GetItemIdWithPathForAttachmentMedia(document_link, options) return self.Create(readable_stream, path, 'attachments', document_id, initial_headers, options)
[ "def", "CreateAttachmentAndUploadMedia", "(", "self", ",", "document_link", ",", "readable_stream", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "document_id", ",", "initial_headers", ",", "path", "=", "self", ".", "_GetItemIdWithPathForAttachmentMedia", "(", "document_link", ",", "options", ")", "return", "self", ".", "Create", "(", "readable_stream", ",", "path", ",", "'attachments'", ",", "document_id", ",", "initial_headers", ",", "options", ")" ]
Creates an attachment and upload media. :param str document_link: The link to the document. :param (file-like stream object) readable_stream: :param dict options: The request options for the request. :return: The created Attachment. :rtype: dict
[ "Creates", "an", "attachment", "and", "upload", "media", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1742-L1769
229,569
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.UpsertAttachmentAndUploadMedia
def UpsertAttachmentAndUploadMedia(self, document_link, readable_stream, options=None): """Upserts an attachment and upload media. :param str document_link: The link to the document. :param (file-like stream object) readable_stream: :param dict options: The request options for the request. :return: The upserted Attachment. :rtype: dict """ if options is None: options = {} document_id, initial_headers, path = self._GetItemIdWithPathForAttachmentMedia(document_link, options) return self.Upsert(readable_stream, path, 'attachments', document_id, initial_headers, options)
python
def UpsertAttachmentAndUploadMedia(self, document_link, readable_stream, options=None): """Upserts an attachment and upload media. :param str document_link: The link to the document. :param (file-like stream object) readable_stream: :param dict options: The request options for the request. :return: The upserted Attachment. :rtype: dict """ if options is None: options = {} document_id, initial_headers, path = self._GetItemIdWithPathForAttachmentMedia(document_link, options) return self.Upsert(readable_stream, path, 'attachments', document_id, initial_headers, options)
[ "def", "UpsertAttachmentAndUploadMedia", "(", "self", ",", "document_link", ",", "readable_stream", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "document_id", ",", "initial_headers", ",", "path", "=", "self", ".", "_GetItemIdWithPathForAttachmentMedia", "(", "document_link", ",", "options", ")", "return", "self", ".", "Upsert", "(", "readable_stream", ",", "path", ",", "'attachments'", ",", "document_id", ",", "initial_headers", ",", "options", ")" ]
Upserts an attachment and upload media. :param str document_link: The link to the document. :param (file-like stream object) readable_stream: :param dict options: The request options for the request. :return: The upserted Attachment. :rtype: dict
[ "Upserts", "an", "attachment", "and", "upload", "media", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1771-L1798
229,570
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadAttachment
def ReadAttachment(self, attachment_link, options=None): """Reads an attachment. :param str attachment_link: The link to the attachment. :param dict options: The request options for the request. :return: The read Attachment. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(attachment_link) attachment_id = base.GetResourceIdOrFullNameFromLink(attachment_link) return self.Read(path, 'attachments', attachment_id, None, options)
python
def ReadAttachment(self, attachment_link, options=None): """Reads an attachment. :param str attachment_link: The link to the attachment. :param dict options: The request options for the request. :return: The read Attachment. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(attachment_link) attachment_id = base.GetResourceIdOrFullNameFromLink(attachment_link) return self.Read(path, 'attachments', attachment_id, None, options)
[ "def", "ReadAttachment", "(", "self", ",", "attachment_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "attachment_link", ")", "attachment_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "attachment_link", ")", "return", "self", ".", "Read", "(", "path", ",", "'attachments'", ",", "attachment_id", ",", "None", ",", "options", ")" ]
Reads an attachment. :param str attachment_link: The link to the attachment. :param dict options: The request options for the request. :return: The read Attachment. :rtype: dict
[ "Reads", "an", "attachment", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1819-L1842
229,571
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadAttachments
def ReadAttachments(self, document_link, options=None): """Reads all attachments in a document. :param str document_link: The link to the document. :param dict options: The request options for the request. :return: Query Iterable of Attachments. :rtype: query_iterable.QueryIterable """ if options is None: options = {} return self.QueryAttachments(document_link, None, options)
python
def ReadAttachments(self, document_link, options=None): """Reads all attachments in a document. :param str document_link: The link to the document. :param dict options: The request options for the request. :return: Query Iterable of Attachments. :rtype: query_iterable.QueryIterable """ if options is None: options = {} return self.QueryAttachments(document_link, None, options)
[ "def", "ReadAttachments", "(", "self", ",", "document_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "return", "self", ".", "QueryAttachments", "(", "document_link", ",", "None", ",", "options", ")" ]
Reads all attachments in a document. :param str document_link: The link to the document. :param dict options: The request options for the request. :return: Query Iterable of Attachments. :rtype: query_iterable.QueryIterable
[ "Reads", "all", "attachments", "in", "a", "document", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1844-L1861
229,572
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.QueryAttachments
def QueryAttachments(self, document_link, query, options=None): """Queries attachments in a document. :param str document_link: The link to the document. :param (str or dict) query: :param dict options: The request options for the request. :return: Query Iterable of Attachments. :rtype: query_iterable.QueryIterable """ if options is None: options = {} path = base.GetPathFromLink(document_link, 'attachments') document_id = base.GetResourceIdOrFullNameFromLink(document_link) def fetch_fn(options): return self.__QueryFeed(path, 'attachments', document_id, lambda r: r['Attachments'], lambda _, b: b, query, options), self.last_response_headers return query_iterable.QueryIterable(self, query, options, fetch_fn)
python
def QueryAttachments(self, document_link, query, options=None): """Queries attachments in a document. :param str document_link: The link to the document. :param (str or dict) query: :param dict options: The request options for the request. :return: Query Iterable of Attachments. :rtype: query_iterable.QueryIterable """ if options is None: options = {} path = base.GetPathFromLink(document_link, 'attachments') document_id = base.GetResourceIdOrFullNameFromLink(document_link) def fetch_fn(options): return self.__QueryFeed(path, 'attachments', document_id, lambda r: r['Attachments'], lambda _, b: b, query, options), self.last_response_headers return query_iterable.QueryIterable(self, query, options, fetch_fn)
[ "def", "QueryAttachments", "(", "self", ",", "document_link", ",", "query", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "document_link", ",", "'attachments'", ")", "document_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "document_link", ")", "def", "fetch_fn", "(", "options", ")", ":", "return", "self", ".", "__QueryFeed", "(", "path", ",", "'attachments'", ",", "document_id", ",", "lambda", "r", ":", "r", "[", "'Attachments'", "]", ",", "lambda", "_", ",", "b", ":", "b", ",", "query", ",", "options", ")", ",", "self", ".", "last_response_headers", "return", "query_iterable", ".", "QueryIterable", "(", "self", ",", "query", ",", "options", ",", "fetch_fn", ")" ]
Queries attachments in a document. :param str document_link: The link to the document. :param (str or dict) query: :param dict options: The request options for the request. :return: Query Iterable of Attachments. :rtype: query_iterable.QueryIterable
[ "Queries", "attachments", "in", "a", "document", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1863-L1892
229,573
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadMedia
def ReadMedia(self, media_link): """Reads a media. When self.connection_policy.MediaReadMode == documents.MediaReadMode.Streamed, returns a file-like stream object; otherwise, returns a str. :param str media_link: The link to the media. :return: The read Media. :rtype: str or file-like stream object """ default_headers = self.default_headers path = base.GetPathFromLink(media_link) media_id = base.GetResourceIdOrFullNameFromLink(media_link) attachment_id = base.GetAttachmentIdFromMediaId(media_id) headers = base.GetHeaders(self, default_headers, 'get', path, attachment_id, 'media', {}) # ReadMedia will always use WriteEndpoint since it's not replicated in readable Geo regions request = request_object._RequestObject('media', documents._OperationType.Read) result, self.last_response_headers = self.__Get(path, request, headers) return result
python
def ReadMedia(self, media_link): """Reads a media. When self.connection_policy.MediaReadMode == documents.MediaReadMode.Streamed, returns a file-like stream object; otherwise, returns a str. :param str media_link: The link to the media. :return: The read Media. :rtype: str or file-like stream object """ default_headers = self.default_headers path = base.GetPathFromLink(media_link) media_id = base.GetResourceIdOrFullNameFromLink(media_link) attachment_id = base.GetAttachmentIdFromMediaId(media_id) headers = base.GetHeaders(self, default_headers, 'get', path, attachment_id, 'media', {}) # ReadMedia will always use WriteEndpoint since it's not replicated in readable Geo regions request = request_object._RequestObject('media', documents._OperationType.Read) result, self.last_response_headers = self.__Get(path, request, headers) return result
[ "def", "ReadMedia", "(", "self", ",", "media_link", ")", ":", "default_headers", "=", "self", ".", "default_headers", "path", "=", "base", ".", "GetPathFromLink", "(", "media_link", ")", "media_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "media_link", ")", "attachment_id", "=", "base", ".", "GetAttachmentIdFromMediaId", "(", "media_id", ")", "headers", "=", "base", ".", "GetHeaders", "(", "self", ",", "default_headers", ",", "'get'", ",", "path", ",", "attachment_id", ",", "'media'", ",", "{", "}", ")", "# ReadMedia will always use WriteEndpoint since it's not replicated in readable Geo regions", "request", "=", "request_object", ".", "_RequestObject", "(", "'media'", ",", "documents", ".", "_OperationType", ".", "Read", ")", "result", ",", "self", ".", "last_response_headers", "=", "self", ".", "__Get", "(", "path", ",", "request", ",", "headers", ")", "return", "result" ]
Reads a media. When self.connection_policy.MediaReadMode == documents.MediaReadMode.Streamed, returns a file-like stream object; otherwise, returns a str. :param str media_link: The link to the media. :return: The read Media. :rtype: str or file-like stream object
[ "Reads", "a", "media", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1895-L1929
229,574
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.UpdateMedia
def UpdateMedia(self, media_link, readable_stream, options=None): """Updates a media and returns it. :param str media_link: The link to the media. :param (file-like stream object) readable_stream: :param dict options: The request options for the request. :return: The updated Media. :rtype: str or file-like stream object """ if options is None: options = {} initial_headers = dict(self.default_headers) # Add required headers slug and content-type in case the body is a stream if options.get('slug'): initial_headers[http_constants.HttpHeaders.Slug] = options['slug'] if options.get('contentType'): initial_headers[http_constants.HttpHeaders.ContentType] = ( options['contentType']) else: initial_headers[http_constants.HttpHeaders.ContentType] = ( runtime_constants.MediaTypes.OctetStream) path = base.GetPathFromLink(media_link) media_id = base.GetResourceIdOrFullNameFromLink(media_link) attachment_id = base.GetAttachmentIdFromMediaId(media_id) headers = base.GetHeaders(self, initial_headers, 'put', path, attachment_id, 'media', options) # UpdateMedia will use WriteEndpoint since it uses PUT operation request = request_object._RequestObject('media', documents._OperationType.Update) result, self.last_response_headers = self.__Put(path, request, readable_stream, headers) self._UpdateSessionIfRequired(headers, result, self.last_response_headers) return result
python
def UpdateMedia(self, media_link, readable_stream, options=None): """Updates a media and returns it. :param str media_link: The link to the media. :param (file-like stream object) readable_stream: :param dict options: The request options for the request. :return: The updated Media. :rtype: str or file-like stream object """ if options is None: options = {} initial_headers = dict(self.default_headers) # Add required headers slug and content-type in case the body is a stream if options.get('slug'): initial_headers[http_constants.HttpHeaders.Slug] = options['slug'] if options.get('contentType'): initial_headers[http_constants.HttpHeaders.ContentType] = ( options['contentType']) else: initial_headers[http_constants.HttpHeaders.ContentType] = ( runtime_constants.MediaTypes.OctetStream) path = base.GetPathFromLink(media_link) media_id = base.GetResourceIdOrFullNameFromLink(media_link) attachment_id = base.GetAttachmentIdFromMediaId(media_id) headers = base.GetHeaders(self, initial_headers, 'put', path, attachment_id, 'media', options) # UpdateMedia will use WriteEndpoint since it uses PUT operation request = request_object._RequestObject('media', documents._OperationType.Update) result, self.last_response_headers = self.__Put(path, request, readable_stream, headers) self._UpdateSessionIfRequired(headers, result, self.last_response_headers) return result
[ "def", "UpdateMedia", "(", "self", ",", "media_link", ",", "readable_stream", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "initial_headers", "=", "dict", "(", "self", ".", "default_headers", ")", "# Add required headers slug and content-type in case the body is a stream", "if", "options", ".", "get", "(", "'slug'", ")", ":", "initial_headers", "[", "http_constants", ".", "HttpHeaders", ".", "Slug", "]", "=", "options", "[", "'slug'", "]", "if", "options", ".", "get", "(", "'contentType'", ")", ":", "initial_headers", "[", "http_constants", ".", "HttpHeaders", ".", "ContentType", "]", "=", "(", "options", "[", "'contentType'", "]", ")", "else", ":", "initial_headers", "[", "http_constants", ".", "HttpHeaders", ".", "ContentType", "]", "=", "(", "runtime_constants", ".", "MediaTypes", ".", "OctetStream", ")", "path", "=", "base", ".", "GetPathFromLink", "(", "media_link", ")", "media_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "media_link", ")", "attachment_id", "=", "base", ".", "GetAttachmentIdFromMediaId", "(", "media_id", ")", "headers", "=", "base", ".", "GetHeaders", "(", "self", ",", "initial_headers", ",", "'put'", ",", "path", ",", "attachment_id", ",", "'media'", ",", "options", ")", "# UpdateMedia will use WriteEndpoint since it uses PUT operation", "request", "=", "request_object", ".", "_RequestObject", "(", "'media'", ",", "documents", ".", "_OperationType", ".", "Update", ")", "result", ",", "self", ".", "last_response_headers", "=", "self", ".", "__Put", "(", "path", ",", "request", ",", "readable_stream", ",", "headers", ")", "self", ".", "_UpdateSessionIfRequired", "(", "headers", ",", "result", ",", "self", ".", "last_response_headers", ")", "return", "result" ]
Updates a media and returns it. :param str media_link: The link to the media. :param (file-like stream object) readable_stream: :param dict options: The request options for the request. :return: The updated Media. :rtype: str or file-like stream object
[ "Updates", "a", "media", "and", "returns", "it", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1931-L1981
229,575
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReplaceAttachment
def ReplaceAttachment(self, attachment_link, attachment, options=None): """Replaces an attachment and returns it. :param str attachment_link: The link to the attachment. :param dict attachment: :param dict options: The request options for the request. :return: The replaced Attachment :rtype: dict """ if options is None: options = {} CosmosClient.__ValidateResource(attachment) path = base.GetPathFromLink(attachment_link) attachment_id = base.GetResourceIdOrFullNameFromLink(attachment_link) return self.Replace(attachment, path, 'attachments', attachment_id, None, options)
python
def ReplaceAttachment(self, attachment_link, attachment, options=None): """Replaces an attachment and returns it. :param str attachment_link: The link to the attachment. :param dict attachment: :param dict options: The request options for the request. :return: The replaced Attachment :rtype: dict """ if options is None: options = {} CosmosClient.__ValidateResource(attachment) path = base.GetPathFromLink(attachment_link) attachment_id = base.GetResourceIdOrFullNameFromLink(attachment_link) return self.Replace(attachment, path, 'attachments', attachment_id, None, options)
[ "def", "ReplaceAttachment", "(", "self", ",", "attachment_link", ",", "attachment", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "CosmosClient", ".", "__ValidateResource", "(", "attachment", ")", "path", "=", "base", ".", "GetPathFromLink", "(", "attachment_link", ")", "attachment_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "attachment_link", ")", "return", "self", ".", "Replace", "(", "attachment", ",", "path", ",", "'attachments'", ",", "attachment_id", ",", "None", ",", "options", ")" ]
Replaces an attachment and returns it. :param str attachment_link: The link to the attachment. :param dict attachment: :param dict options: The request options for the request. :return: The replaced Attachment :rtype: dict
[ "Replaces", "an", "attachment", "and", "returns", "it", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L1983-L2009
229,576
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.DeleteAttachment
def DeleteAttachment(self, attachment_link, options=None): """Deletes an attachment. :param str attachment_link: The link to the attachment. :param dict options: The request options for the request. :return: The deleted Attachment. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(attachment_link) attachment_id = base.GetResourceIdOrFullNameFromLink(attachment_link) return self.DeleteResource(path, 'attachments', attachment_id, None, options)
python
def DeleteAttachment(self, attachment_link, options=None): """Deletes an attachment. :param str attachment_link: The link to the attachment. :param dict options: The request options for the request. :return: The deleted Attachment. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(attachment_link) attachment_id = base.GetResourceIdOrFullNameFromLink(attachment_link) return self.DeleteResource(path, 'attachments', attachment_id, None, options)
[ "def", "DeleteAttachment", "(", "self", ",", "attachment_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "attachment_link", ")", "attachment_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "attachment_link", ")", "return", "self", ".", "DeleteResource", "(", "path", ",", "'attachments'", ",", "attachment_id", ",", "None", ",", "options", ")" ]
Deletes an attachment. :param str attachment_link: The link to the attachment. :param dict options: The request options for the request. :return: The deleted Attachment. :rtype: dict
[ "Deletes", "an", "attachment", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2011-L2034
229,577
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReplaceTrigger
def ReplaceTrigger(self, trigger_link, trigger, options=None): """Replaces a trigger and returns it. :param str trigger_link: The link to the trigger. :param dict trigger: :param dict options: The request options for the request. :return: The replaced Trigger. :rtype: dict """ if options is None: options = {} CosmosClient.__ValidateResource(trigger) trigger = trigger.copy() if trigger.get('serverScript'): trigger['body'] = str(trigger['serverScript']) elif trigger.get('body'): trigger['body'] = str(trigger['body']) path = base.GetPathFromLink(trigger_link) trigger_id = base.GetResourceIdOrFullNameFromLink(trigger_link) return self.Replace(trigger, path, 'triggers', trigger_id, None, options)
python
def ReplaceTrigger(self, trigger_link, trigger, options=None): """Replaces a trigger and returns it. :param str trigger_link: The link to the trigger. :param dict trigger: :param dict options: The request options for the request. :return: The replaced Trigger. :rtype: dict """ if options is None: options = {} CosmosClient.__ValidateResource(trigger) trigger = trigger.copy() if trigger.get('serverScript'): trigger['body'] = str(trigger['serverScript']) elif trigger.get('body'): trigger['body'] = str(trigger['body']) path = base.GetPathFromLink(trigger_link) trigger_id = base.GetResourceIdOrFullNameFromLink(trigger_link) return self.Replace(trigger, path, 'triggers', trigger_id, None, options)
[ "def", "ReplaceTrigger", "(", "self", ",", "trigger_link", ",", "trigger", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "CosmosClient", ".", "__ValidateResource", "(", "trigger", ")", "trigger", "=", "trigger", ".", "copy", "(", ")", "if", "trigger", ".", "get", "(", "'serverScript'", ")", ":", "trigger", "[", "'body'", "]", "=", "str", "(", "trigger", "[", "'serverScript'", "]", ")", "elif", "trigger", ".", "get", "(", "'body'", ")", ":", "trigger", "[", "'body'", "]", "=", "str", "(", "trigger", "[", "'body'", "]", ")", "path", "=", "base", ".", "GetPathFromLink", "(", "trigger_link", ")", "trigger_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "trigger_link", ")", "return", "self", ".", "Replace", "(", "trigger", ",", "path", ",", "'triggers'", ",", "trigger_id", ",", "None", ",", "options", ")" ]
Replaces a trigger and returns it. :param str trigger_link: The link to the trigger. :param dict trigger: :param dict options: The request options for the request. :return: The replaced Trigger. :rtype: dict
[ "Replaces", "a", "trigger", "and", "returns", "it", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2036-L2068
229,578
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.DeleteTrigger
def DeleteTrigger(self, trigger_link, options=None): """Deletes a trigger. :param str trigger_link: The link to the trigger. :param dict options: The request options for the request. :return: The deleted Trigger. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(trigger_link) trigger_id = base.GetResourceIdOrFullNameFromLink(trigger_link) return self.DeleteResource(path, 'triggers', trigger_id, None, options)
python
def DeleteTrigger(self, trigger_link, options=None): """Deletes a trigger. :param str trigger_link: The link to the trigger. :param dict options: The request options for the request. :return: The deleted Trigger. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(trigger_link) trigger_id = base.GetResourceIdOrFullNameFromLink(trigger_link) return self.DeleteResource(path, 'triggers', trigger_id, None, options)
[ "def", "DeleteTrigger", "(", "self", ",", "trigger_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "trigger_link", ")", "trigger_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "trigger_link", ")", "return", "self", ".", "DeleteResource", "(", "path", ",", "'triggers'", ",", "trigger_id", ",", "None", ",", "options", ")" ]
Deletes a trigger. :param str trigger_link: The link to the trigger. :param dict options: The request options for the request. :return: The deleted Trigger. :rtype: dict
[ "Deletes", "a", "trigger", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2070-L2093
229,579
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReplaceUserDefinedFunction
def ReplaceUserDefinedFunction(self, udf_link, udf, options=None): """Replaces a user defined function and returns it. :param str udf_link: The link to the user defined function. :param dict udf: :param dict options: The request options for the request. :return: The new UDF. :rtype: dict """ if options is None: options = {} CosmosClient.__ValidateResource(udf) udf = udf.copy() if udf.get('serverScript'): udf['body'] = str(udf['serverScript']) elif udf.get('body'): udf['body'] = str(udf['body']) path = base.GetPathFromLink(udf_link) udf_id = base.GetResourceIdOrFullNameFromLink(udf_link) return self.Replace(udf, path, 'udfs', udf_id, None, options)
python
def ReplaceUserDefinedFunction(self, udf_link, udf, options=None): """Replaces a user defined function and returns it. :param str udf_link: The link to the user defined function. :param dict udf: :param dict options: The request options for the request. :return: The new UDF. :rtype: dict """ if options is None: options = {} CosmosClient.__ValidateResource(udf) udf = udf.copy() if udf.get('serverScript'): udf['body'] = str(udf['serverScript']) elif udf.get('body'): udf['body'] = str(udf['body']) path = base.GetPathFromLink(udf_link) udf_id = base.GetResourceIdOrFullNameFromLink(udf_link) return self.Replace(udf, path, 'udfs', udf_id, None, options)
[ "def", "ReplaceUserDefinedFunction", "(", "self", ",", "udf_link", ",", "udf", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "CosmosClient", ".", "__ValidateResource", "(", "udf", ")", "udf", "=", "udf", ".", "copy", "(", ")", "if", "udf", ".", "get", "(", "'serverScript'", ")", ":", "udf", "[", "'body'", "]", "=", "str", "(", "udf", "[", "'serverScript'", "]", ")", "elif", "udf", ".", "get", "(", "'body'", ")", ":", "udf", "[", "'body'", "]", "=", "str", "(", "udf", "[", "'body'", "]", ")", "path", "=", "base", ".", "GetPathFromLink", "(", "udf_link", ")", "udf_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "udf_link", ")", "return", "self", ".", "Replace", "(", "udf", ",", "path", ",", "'udfs'", ",", "udf_id", ",", "None", ",", "options", ")" ]
Replaces a user defined function and returns it. :param str udf_link: The link to the user defined function. :param dict udf: :param dict options: The request options for the request. :return: The new UDF. :rtype: dict
[ "Replaces", "a", "user", "defined", "function", "and", "returns", "it", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2095-L2127
229,580
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.DeleteUserDefinedFunction
def DeleteUserDefinedFunction(self, udf_link, options=None): """Deletes a user defined function. :param str udf_link: The link to the user defined function. :param dict options: The request options for the request. :return: The deleted UDF. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(udf_link) udf_id = base.GetResourceIdOrFullNameFromLink(udf_link) return self.DeleteResource(path, 'udfs', udf_id, None, options)
python
def DeleteUserDefinedFunction(self, udf_link, options=None): """Deletes a user defined function. :param str udf_link: The link to the user defined function. :param dict options: The request options for the request. :return: The deleted UDF. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(udf_link) udf_id = base.GetResourceIdOrFullNameFromLink(udf_link) return self.DeleteResource(path, 'udfs', udf_id, None, options)
[ "def", "DeleteUserDefinedFunction", "(", "self", ",", "udf_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "udf_link", ")", "udf_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "udf_link", ")", "return", "self", ".", "DeleteResource", "(", "path", ",", "'udfs'", ",", "udf_id", ",", "None", ",", "options", ")" ]
Deletes a user defined function. :param str udf_link: The link to the user defined function. :param dict options: The request options for the request. :return: The deleted UDF. :rtype: dict
[ "Deletes", "a", "user", "defined", "function", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2129-L2152
229,581
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ExecuteStoredProcedure
def ExecuteStoredProcedure(self, sproc_link, params, options=None): """Executes a store procedure. :param str sproc_link: The link to the stored procedure. :param dict params: List or None :param dict options: The request options for the request. :return: The Stored Procedure response. :rtype: dict """ if options is None: options = {} initial_headers = dict(self.default_headers) initial_headers.update({ http_constants.HttpHeaders.Accept: ( runtime_constants.MediaTypes.Json) }) if params and not type(params) is list: params = [params] path = base.GetPathFromLink(sproc_link) sproc_id = base.GetResourceIdOrFullNameFromLink(sproc_link) headers = base.GetHeaders(self, initial_headers, 'post', path, sproc_id, 'sprocs', options) # ExecuteStoredProcedure will use WriteEndpoint since it uses POST operation request = request_object._RequestObject('sprocs', documents._OperationType.ExecuteJavaScript) result, self.last_response_headers = self.__Post(path, request, params, headers) return result
python
def ExecuteStoredProcedure(self, sproc_link, params, options=None): """Executes a store procedure. :param str sproc_link: The link to the stored procedure. :param dict params: List or None :param dict options: The request options for the request. :return: The Stored Procedure response. :rtype: dict """ if options is None: options = {} initial_headers = dict(self.default_headers) initial_headers.update({ http_constants.HttpHeaders.Accept: ( runtime_constants.MediaTypes.Json) }) if params and not type(params) is list: params = [params] path = base.GetPathFromLink(sproc_link) sproc_id = base.GetResourceIdOrFullNameFromLink(sproc_link) headers = base.GetHeaders(self, initial_headers, 'post', path, sproc_id, 'sprocs', options) # ExecuteStoredProcedure will use WriteEndpoint since it uses POST operation request = request_object._RequestObject('sprocs', documents._OperationType.ExecuteJavaScript) result, self.last_response_headers = self.__Post(path, request, params, headers) return result
[ "def", "ExecuteStoredProcedure", "(", "self", ",", "sproc_link", ",", "params", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "initial_headers", "=", "dict", "(", "self", ".", "default_headers", ")", "initial_headers", ".", "update", "(", "{", "http_constants", ".", "HttpHeaders", ".", "Accept", ":", "(", "runtime_constants", ".", "MediaTypes", ".", "Json", ")", "}", ")", "if", "params", "and", "not", "type", "(", "params", ")", "is", "list", ":", "params", "=", "[", "params", "]", "path", "=", "base", ".", "GetPathFromLink", "(", "sproc_link", ")", "sproc_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "sproc_link", ")", "headers", "=", "base", ".", "GetHeaders", "(", "self", ",", "initial_headers", ",", "'post'", ",", "path", ",", "sproc_id", ",", "'sprocs'", ",", "options", ")", "# ExecuteStoredProcedure will use WriteEndpoint since it uses POST operation", "request", "=", "request_object", ".", "_RequestObject", "(", "'sprocs'", ",", "documents", ".", "_OperationType", ".", "ExecuteJavaScript", ")", "result", ",", "self", ".", "last_response_headers", "=", "self", ".", "__Post", "(", "path", ",", "request", ",", "params", ",", "headers", ")", "return", "result" ]
Executes a store procedure. :param str sproc_link: The link to the stored procedure. :param dict params: List or None :param dict options: The request options for the request. :return: The Stored Procedure response. :rtype: dict
[ "Executes", "a", "store", "procedure", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2154-L2198
229,582
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReplaceStoredProcedure
def ReplaceStoredProcedure(self, sproc_link, sproc, options=None): """Replaces a stored procedure and returns it. :param str sproc_link: The link to the stored procedure. :param dict sproc: :param dict options: The request options for the request. :return: The replaced Stored Procedure. :rtype: dict """ if options is None: options = {} CosmosClient.__ValidateResource(sproc) sproc = sproc.copy() if sproc.get('serverScript'): sproc['body'] = str(sproc['serverScript']) elif sproc.get('body'): sproc['body'] = str(sproc['body']) path = base.GetPathFromLink(sproc_link) sproc_id = base.GetResourceIdOrFullNameFromLink(sproc_link) return self.Replace(sproc, path, 'sprocs', sproc_id, None, options)
python
def ReplaceStoredProcedure(self, sproc_link, sproc, options=None): """Replaces a stored procedure and returns it. :param str sproc_link: The link to the stored procedure. :param dict sproc: :param dict options: The request options for the request. :return: The replaced Stored Procedure. :rtype: dict """ if options is None: options = {} CosmosClient.__ValidateResource(sproc) sproc = sproc.copy() if sproc.get('serverScript'): sproc['body'] = str(sproc['serverScript']) elif sproc.get('body'): sproc['body'] = str(sproc['body']) path = base.GetPathFromLink(sproc_link) sproc_id = base.GetResourceIdOrFullNameFromLink(sproc_link) return self.Replace(sproc, path, 'sprocs', sproc_id, None, options)
[ "def", "ReplaceStoredProcedure", "(", "self", ",", "sproc_link", ",", "sproc", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "CosmosClient", ".", "__ValidateResource", "(", "sproc", ")", "sproc", "=", "sproc", ".", "copy", "(", ")", "if", "sproc", ".", "get", "(", "'serverScript'", ")", ":", "sproc", "[", "'body'", "]", "=", "str", "(", "sproc", "[", "'serverScript'", "]", ")", "elif", "sproc", ".", "get", "(", "'body'", ")", ":", "sproc", "[", "'body'", "]", "=", "str", "(", "sproc", "[", "'body'", "]", ")", "path", "=", "base", ".", "GetPathFromLink", "(", "sproc_link", ")", "sproc_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "sproc_link", ")", "return", "self", ".", "Replace", "(", "sproc", ",", "path", ",", "'sprocs'", ",", "sproc_id", ",", "None", ",", "options", ")" ]
Replaces a stored procedure and returns it. :param str sproc_link: The link to the stored procedure. :param dict sproc: :param dict options: The request options for the request. :return: The replaced Stored Procedure. :rtype: dict
[ "Replaces", "a", "stored", "procedure", "and", "returns", "it", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2200-L2232
229,583
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.DeleteStoredProcedure
def DeleteStoredProcedure(self, sproc_link, options=None): """Deletes a stored procedure. :param str sproc_link: The link to the stored procedure. :param dict options: The request options for the request. :return: The deleted Stored Procedure. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(sproc_link) sproc_id = base.GetResourceIdOrFullNameFromLink(sproc_link) return self.DeleteResource(path, 'sprocs', sproc_id, None, options)
python
def DeleteStoredProcedure(self, sproc_link, options=None): """Deletes a stored procedure. :param str sproc_link: The link to the stored procedure. :param dict options: The request options for the request. :return: The deleted Stored Procedure. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(sproc_link) sproc_id = base.GetResourceIdOrFullNameFromLink(sproc_link) return self.DeleteResource(path, 'sprocs', sproc_id, None, options)
[ "def", "DeleteStoredProcedure", "(", "self", ",", "sproc_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "sproc_link", ")", "sproc_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "sproc_link", ")", "return", "self", ".", "DeleteResource", "(", "path", ",", "'sprocs'", ",", "sproc_id", ",", "None", ",", "options", ")" ]
Deletes a stored procedure. :param str sproc_link: The link to the stored procedure. :param dict options: The request options for the request. :return: The deleted Stored Procedure. :rtype: dict
[ "Deletes", "a", "stored", "procedure", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2234-L2257
229,584
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.DeleteConflict
def DeleteConflict(self, conflict_link, options=None): """Deletes a conflict. :param str conflict_link: The link to the conflict. :param dict options: The request options for the request. :return: The deleted Conflict. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(conflict_link) conflict_id = base.GetResourceIdOrFullNameFromLink(conflict_link) return self.DeleteResource(path, 'conflicts', conflict_id, None, options)
python
def DeleteConflict(self, conflict_link, options=None): """Deletes a conflict. :param str conflict_link: The link to the conflict. :param dict options: The request options for the request. :return: The deleted Conflict. :rtype: dict """ if options is None: options = {} path = base.GetPathFromLink(conflict_link) conflict_id = base.GetResourceIdOrFullNameFromLink(conflict_link) return self.DeleteResource(path, 'conflicts', conflict_id, None, options)
[ "def", "DeleteConflict", "(", "self", ",", "conflict_link", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "path", "=", "base", ".", "GetPathFromLink", "(", "conflict_link", ")", "conflict_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "conflict_link", ")", "return", "self", ".", "DeleteResource", "(", "path", ",", "'conflicts'", ",", "conflict_id", ",", "None", ",", "options", ")" ]
Deletes a conflict. :param str conflict_link: The link to the conflict. :param dict options: The request options for the request. :return: The deleted Conflict. :rtype: dict
[ "Deletes", "a", "conflict", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2259-L2282
229,585
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReplaceOffer
def ReplaceOffer(self, offer_link, offer): """Replaces an offer and returns it. :param str offer_link: The link to the offer. :param dict offer: :return: The replaced Offer. :rtype: dict """ CosmosClient.__ValidateResource(offer) path = base.GetPathFromLink(offer_link) offer_id = base.GetResourceIdOrFullNameFromLink(offer_link) return self.Replace(offer, path, 'offers', offer_id, None, None)
python
def ReplaceOffer(self, offer_link, offer): """Replaces an offer and returns it. :param str offer_link: The link to the offer. :param dict offer: :return: The replaced Offer. :rtype: dict """ CosmosClient.__ValidateResource(offer) path = base.GetPathFromLink(offer_link) offer_id = base.GetResourceIdOrFullNameFromLink(offer_link) return self.Replace(offer, path, 'offers', offer_id, None, None)
[ "def", "ReplaceOffer", "(", "self", ",", "offer_link", ",", "offer", ")", ":", "CosmosClient", ".", "__ValidateResource", "(", "offer", ")", "path", "=", "base", ".", "GetPathFromLink", "(", "offer_link", ")", "offer_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "offer_link", ")", "return", "self", ".", "Replace", "(", "offer", ",", "path", ",", "'offers'", ",", "offer_id", ",", "None", ",", "None", ")" ]
Replaces an offer and returns it. :param str offer_link: The link to the offer. :param dict offer: :return: The replaced Offer. :rtype: dict
[ "Replaces", "an", "offer", "and", "returns", "it", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2284-L2300
229,586
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.ReadOffer
def ReadOffer(self, offer_link): """Reads an offer. :param str offer_link: The link to the offer. :return: The read Offer. :rtype: dict """ path = base.GetPathFromLink(offer_link) offer_id = base.GetResourceIdOrFullNameFromLink(offer_link) return self.Read(path, 'offers', offer_id, None, {})
python
def ReadOffer(self, offer_link): """Reads an offer. :param str offer_link: The link to the offer. :return: The read Offer. :rtype: dict """ path = base.GetPathFromLink(offer_link) offer_id = base.GetResourceIdOrFullNameFromLink(offer_link) return self.Read(path, 'offers', offer_id, None, {})
[ "def", "ReadOffer", "(", "self", ",", "offer_link", ")", ":", "path", "=", "base", ".", "GetPathFromLink", "(", "offer_link", ")", "offer_id", "=", "base", ".", "GetResourceIdOrFullNameFromLink", "(", "offer_link", ")", "return", "self", ".", "Read", "(", "path", ",", "'offers'", ",", "offer_id", ",", "None", ",", "{", "}", ")" ]
Reads an offer. :param str offer_link: The link to the offer. :return: The read Offer. :rtype: dict
[ "Reads", "an", "offer", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2302-L2316
229,587
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.GetDatabaseAccount
def GetDatabaseAccount(self, url_connection=None): """Gets database account info. :return: The Database Account. :rtype: documents.DatabaseAccount """ if url_connection is None: url_connection = self.url_connection initial_headers = dict(self.default_headers) headers = base.GetHeaders(self, initial_headers, 'get', '', # path '', # id '', # type {}) request = request_object._RequestObject('databaseaccount', documents._OperationType.Read, url_connection) result, self.last_response_headers = self.__Get('', request, headers) database_account = documents.DatabaseAccount() database_account.DatabasesLink = '/dbs/' database_account.MediaLink = '/media/' if (http_constants.HttpHeaders.MaxMediaStorageUsageInMB in self.last_response_headers): database_account.MaxMediaStorageUsageInMB = ( self.last_response_headers[ http_constants.HttpHeaders.MaxMediaStorageUsageInMB]) if (http_constants.HttpHeaders.CurrentMediaStorageUsageInMB in self.last_response_headers): database_account.CurrentMediaStorageUsageInMB = ( self.last_response_headers[ http_constants.HttpHeaders.CurrentMediaStorageUsageInMB]) database_account.ConsistencyPolicy = result.get(constants._Constants.UserConsistencyPolicy) # WritableLocations and ReadableLocations fields will be available only for geo-replicated database accounts if constants._Constants.WritableLocations in result: database_account._WritableLocations = result[constants._Constants.WritableLocations] if constants._Constants.ReadableLocations in result: database_account._ReadableLocations = result[constants._Constants.ReadableLocations] if constants._Constants.EnableMultipleWritableLocations in result: database_account._EnableMultipleWritableLocations = result[constants._Constants.EnableMultipleWritableLocations] self._useMultipleWriteLocations = self.connection_policy.UseMultipleWriteLocations and database_account._EnableMultipleWritableLocations return database_account
python
def GetDatabaseAccount(self, url_connection=None): """Gets database account info. :return: The Database Account. :rtype: documents.DatabaseAccount """ if url_connection is None: url_connection = self.url_connection initial_headers = dict(self.default_headers) headers = base.GetHeaders(self, initial_headers, 'get', '', # path '', # id '', # type {}) request = request_object._RequestObject('databaseaccount', documents._OperationType.Read, url_connection) result, self.last_response_headers = self.__Get('', request, headers) database_account = documents.DatabaseAccount() database_account.DatabasesLink = '/dbs/' database_account.MediaLink = '/media/' if (http_constants.HttpHeaders.MaxMediaStorageUsageInMB in self.last_response_headers): database_account.MaxMediaStorageUsageInMB = ( self.last_response_headers[ http_constants.HttpHeaders.MaxMediaStorageUsageInMB]) if (http_constants.HttpHeaders.CurrentMediaStorageUsageInMB in self.last_response_headers): database_account.CurrentMediaStorageUsageInMB = ( self.last_response_headers[ http_constants.HttpHeaders.CurrentMediaStorageUsageInMB]) database_account.ConsistencyPolicy = result.get(constants._Constants.UserConsistencyPolicy) # WritableLocations and ReadableLocations fields will be available only for geo-replicated database accounts if constants._Constants.WritableLocations in result: database_account._WritableLocations = result[constants._Constants.WritableLocations] if constants._Constants.ReadableLocations in result: database_account._ReadableLocations = result[constants._Constants.ReadableLocations] if constants._Constants.EnableMultipleWritableLocations in result: database_account._EnableMultipleWritableLocations = result[constants._Constants.EnableMultipleWritableLocations] self._useMultipleWriteLocations = self.connection_policy.UseMultipleWriteLocations and database_account._EnableMultipleWritableLocations return database_account
[ "def", "GetDatabaseAccount", "(", "self", ",", "url_connection", "=", "None", ")", ":", "if", "url_connection", "is", "None", ":", "url_connection", "=", "self", ".", "url_connection", "initial_headers", "=", "dict", "(", "self", ".", "default_headers", ")", "headers", "=", "base", ".", "GetHeaders", "(", "self", ",", "initial_headers", ",", "'get'", ",", "''", ",", "# path", "''", ",", "# id", "''", ",", "# type", "{", "}", ")", "request", "=", "request_object", ".", "_RequestObject", "(", "'databaseaccount'", ",", "documents", ".", "_OperationType", ".", "Read", ",", "url_connection", ")", "result", ",", "self", ".", "last_response_headers", "=", "self", ".", "__Get", "(", "''", ",", "request", ",", "headers", ")", "database_account", "=", "documents", ".", "DatabaseAccount", "(", ")", "database_account", ".", "DatabasesLink", "=", "'/dbs/'", "database_account", ".", "MediaLink", "=", "'/media/'", "if", "(", "http_constants", ".", "HttpHeaders", ".", "MaxMediaStorageUsageInMB", "in", "self", ".", "last_response_headers", ")", ":", "database_account", ".", "MaxMediaStorageUsageInMB", "=", "(", "self", ".", "last_response_headers", "[", "http_constants", ".", "HttpHeaders", ".", "MaxMediaStorageUsageInMB", "]", ")", "if", "(", "http_constants", ".", "HttpHeaders", ".", "CurrentMediaStorageUsageInMB", "in", "self", ".", "last_response_headers", ")", ":", "database_account", ".", "CurrentMediaStorageUsageInMB", "=", "(", "self", ".", "last_response_headers", "[", "http_constants", ".", "HttpHeaders", ".", "CurrentMediaStorageUsageInMB", "]", ")", "database_account", ".", "ConsistencyPolicy", "=", "result", ".", "get", "(", "constants", ".", "_Constants", ".", "UserConsistencyPolicy", ")", "# WritableLocations and ReadableLocations fields will be available only for geo-replicated database accounts", "if", "constants", ".", "_Constants", ".", "WritableLocations", "in", "result", ":", "database_account", ".", "_WritableLocations", "=", "result", "[", "constants", ".", "_Constants", ".", "WritableLocations", "]", "if", "constants", ".", "_Constants", ".", "ReadableLocations", "in", "result", ":", "database_account", ".", "_ReadableLocations", "=", "result", "[", "constants", ".", "_Constants", ".", "ReadableLocations", "]", "if", "constants", ".", "_Constants", ".", "EnableMultipleWritableLocations", "in", "result", ":", "database_account", ".", "_EnableMultipleWritableLocations", "=", "result", "[", "constants", ".", "_Constants", ".", "EnableMultipleWritableLocations", "]", "self", ".", "_useMultipleWriteLocations", "=", "self", ".", "connection_policy", ".", "UseMultipleWriteLocations", "and", "database_account", ".", "_EnableMultipleWritableLocations", "return", "database_account" ]
Gets database account info. :return: The Database Account. :rtype: documents.DatabaseAccount
[ "Gets", "database", "account", "info", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2361-L2410
229,588
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.Create
def Create(self, body, path, type, id, initial_headers, options=None): """Creates a Azure Cosmos resource and returns it. :param dict body: :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request. :return: The created Azure Cosmos resource. :rtype: dict """ if options is None: options = {} initial_headers = initial_headers or self.default_headers headers = base.GetHeaders(self, initial_headers, 'post', path, id, type, options) # Create will use WriteEndpoint since it uses POST operation request = request_object._RequestObject(type, documents._OperationType.Create) result, self.last_response_headers = self.__Post(path, request, body, headers) # update session for write request self._UpdateSessionIfRequired(headers, result, self.last_response_headers) return result
python
def Create(self, body, path, type, id, initial_headers, options=None): """Creates a Azure Cosmos resource and returns it. :param dict body: :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request. :return: The created Azure Cosmos resource. :rtype: dict """ if options is None: options = {} initial_headers = initial_headers or self.default_headers headers = base.GetHeaders(self, initial_headers, 'post', path, id, type, options) # Create will use WriteEndpoint since it uses POST operation request = request_object._RequestObject(type, documents._OperationType.Create) result, self.last_response_headers = self.__Post(path, request, body, headers) # update session for write request self._UpdateSessionIfRequired(headers, result, self.last_response_headers) return result
[ "def", "Create", "(", "self", ",", "body", ",", "path", ",", "type", ",", "id", ",", "initial_headers", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "initial_headers", "=", "initial_headers", "or", "self", ".", "default_headers", "headers", "=", "base", ".", "GetHeaders", "(", "self", ",", "initial_headers", ",", "'post'", ",", "path", ",", "id", ",", "type", ",", "options", ")", "# Create will use WriteEndpoint since it uses POST operation", "request", "=", "request_object", ".", "_RequestObject", "(", "type", ",", "documents", ".", "_OperationType", ".", "Create", ")", "result", ",", "self", ".", "last_response_headers", "=", "self", ".", "__Post", "(", "path", ",", "request", ",", "body", ",", "headers", ")", "# update session for write request", "self", ".", "_UpdateSessionIfRequired", "(", "headers", ",", "result", ",", "self", ".", "last_response_headers", ")", "return", "result" ]
Creates a Azure Cosmos resource and returns it. :param dict body: :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request. :return: The created Azure Cosmos resource. :rtype: dict
[ "Creates", "a", "Azure", "Cosmos", "resource", "and", "returns", "it", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2412-L2450
229,589
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.Replace
def Replace(self, resource, path, type, id, initial_headers, options=None): """Replaces a Azure Cosmos resource and returns it. :param dict resource: :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request. :return: The new Azure Cosmos resource. :rtype: dict """ if options is None: options = {} initial_headers = initial_headers or self.default_headers headers = base.GetHeaders(self, initial_headers, 'put', path, id, type, options) # Replace will use WriteEndpoint since it uses PUT operation request = request_object._RequestObject(type, documents._OperationType.Replace) result, self.last_response_headers = self.__Put(path, request, resource, headers) # update session for request mutates data on server side self._UpdateSessionIfRequired(headers, result, self.last_response_headers) return result
python
def Replace(self, resource, path, type, id, initial_headers, options=None): """Replaces a Azure Cosmos resource and returns it. :param dict resource: :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request. :return: The new Azure Cosmos resource. :rtype: dict """ if options is None: options = {} initial_headers = initial_headers or self.default_headers headers = base.GetHeaders(self, initial_headers, 'put', path, id, type, options) # Replace will use WriteEndpoint since it uses PUT operation request = request_object._RequestObject(type, documents._OperationType.Replace) result, self.last_response_headers = self.__Put(path, request, resource, headers) # update session for request mutates data on server side self._UpdateSessionIfRequired(headers, result, self.last_response_headers) return result
[ "def", "Replace", "(", "self", ",", "resource", ",", "path", ",", "type", ",", "id", ",", "initial_headers", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "initial_headers", "=", "initial_headers", "or", "self", ".", "default_headers", "headers", "=", "base", ".", "GetHeaders", "(", "self", ",", "initial_headers", ",", "'put'", ",", "path", ",", "id", ",", "type", ",", "options", ")", "# Replace will use WriteEndpoint since it uses PUT operation", "request", "=", "request_object", ".", "_RequestObject", "(", "type", ",", "documents", ".", "_OperationType", ".", "Replace", ")", "result", ",", "self", ".", "last_response_headers", "=", "self", ".", "__Put", "(", "path", ",", "request", ",", "resource", ",", "headers", ")", "# update session for request mutates data on server side", "self", ".", "_UpdateSessionIfRequired", "(", "headers", ",", "result", ",", "self", ".", "last_response_headers", ")", "return", "result" ]
Replaces a Azure Cosmos resource and returns it. :param dict resource: :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request. :return: The new Azure Cosmos resource. :rtype: dict
[ "Replaces", "a", "Azure", "Cosmos", "resource", "and", "returns", "it", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2493-L2530
229,590
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.Read
def Read(self, path, type, id, initial_headers, options=None): """Reads a Azure Cosmos resource and returns it. :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request. :return: The upserted Azure Cosmos resource. :rtype: dict """ if options is None: options = {} initial_headers = initial_headers or self.default_headers headers = base.GetHeaders(self, initial_headers, 'get', path, id, type, options) # Read will use ReadEndpoint since it uses GET operation request = request_object._RequestObject(type, documents._OperationType.Read) result, self.last_response_headers = self.__Get(path, request, headers) return result
python
def Read(self, path, type, id, initial_headers, options=None): """Reads a Azure Cosmos resource and returns it. :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request. :return: The upserted Azure Cosmos resource. :rtype: dict """ if options is None: options = {} initial_headers = initial_headers or self.default_headers headers = base.GetHeaders(self, initial_headers, 'get', path, id, type, options) # Read will use ReadEndpoint since it uses GET operation request = request_object._RequestObject(type, documents._OperationType.Read) result, self.last_response_headers = self.__Get(path, request, headers) return result
[ "def", "Read", "(", "self", ",", "path", ",", "type", ",", "id", ",", "initial_headers", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "initial_headers", "=", "initial_headers", "or", "self", ".", "default_headers", "headers", "=", "base", ".", "GetHeaders", "(", "self", ",", "initial_headers", ",", "'get'", ",", "path", ",", "id", ",", "type", ",", "options", ")", "# Read will use ReadEndpoint since it uses GET operation", "request", "=", "request_object", ".", "_RequestObject", "(", "type", ",", "documents", ".", "_OperationType", ".", "Read", ")", "result", ",", "self", ".", "last_response_headers", "=", "self", ".", "__Get", "(", "path", ",", "request", ",", "headers", ")", "return", "result" ]
Reads a Azure Cosmos resource and returns it. :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request. :return: The upserted Azure Cosmos resource. :rtype: dict
[ "Reads", "a", "Azure", "Cosmos", "resource", "and", "returns", "it", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2532-L2564
229,591
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.DeleteResource
def DeleteResource(self, path, type, id, initial_headers, options=None): """Deletes a Azure Cosmos resource and returns it. :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request. :return: The deleted Azure Cosmos resource. :rtype: dict """ if options is None: options = {} initial_headers = initial_headers or self.default_headers headers = base.GetHeaders(self, initial_headers, 'delete', path, id, type, options) # Delete will use WriteEndpoint since it uses DELETE operation request = request_object._RequestObject(type, documents._OperationType.Delete) result, self.last_response_headers = self.__Delete(path, request, headers) # update session for request mutates data on server side self._UpdateSessionIfRequired(headers, result, self.last_response_headers) return result
python
def DeleteResource(self, path, type, id, initial_headers, options=None): """Deletes a Azure Cosmos resource and returns it. :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request. :return: The deleted Azure Cosmos resource. :rtype: dict """ if options is None: options = {} initial_headers = initial_headers or self.default_headers headers = base.GetHeaders(self, initial_headers, 'delete', path, id, type, options) # Delete will use WriteEndpoint since it uses DELETE operation request = request_object._RequestObject(type, documents._OperationType.Delete) result, self.last_response_headers = self.__Delete(path, request, headers) # update session for request mutates data on server side self._UpdateSessionIfRequired(headers, result, self.last_response_headers) return result
[ "def", "DeleteResource", "(", "self", ",", "path", ",", "type", ",", "id", ",", "initial_headers", ",", "options", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "initial_headers", "=", "initial_headers", "or", "self", ".", "default_headers", "headers", "=", "base", ".", "GetHeaders", "(", "self", ",", "initial_headers", ",", "'delete'", ",", "path", ",", "id", ",", "type", ",", "options", ")", "# Delete will use WriteEndpoint since it uses DELETE operation", "request", "=", "request_object", ".", "_RequestObject", "(", "type", ",", "documents", ".", "_OperationType", ".", "Delete", ")", "result", ",", "self", ".", "last_response_headers", "=", "self", ".", "__Delete", "(", "path", ",", "request", ",", "headers", ")", "# update session for request mutates data on server side", "self", ".", "_UpdateSessionIfRequired", "(", "headers", ",", "result", ",", "self", ".", "last_response_headers", ")", "return", "result" ]
Deletes a Azure Cosmos resource and returns it. :param str path: :param str type: :param str id: :param dict initial_headers: :param dict options: The request options for the request. :return: The deleted Azure Cosmos resource. :rtype: dict
[ "Deletes", "a", "Azure", "Cosmos", "resource", "and", "returns", "it", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2566-L2603
229,592
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.__Get
def __Get(self, path, request, headers): """Azure Cosmos 'GET' http request. :params str url: :params str path: :params dict headers: :return: Tuple of (result, headers). :rtype: tuple of (dict, dict) """ return synchronized_request.SynchronizedRequest(self, request, self._global_endpoint_manager, self.connection_policy, self._requests_session, 'GET', path, None, None, headers)
python
def __Get(self, path, request, headers): """Azure Cosmos 'GET' http request. :params str url: :params str path: :params dict headers: :return: Tuple of (result, headers). :rtype: tuple of (dict, dict) """ return synchronized_request.SynchronizedRequest(self, request, self._global_endpoint_manager, self.connection_policy, self._requests_session, 'GET', path, None, None, headers)
[ "def", "__Get", "(", "self", ",", "path", ",", "request", ",", "headers", ")", ":", "return", "synchronized_request", ".", "SynchronizedRequest", "(", "self", ",", "request", ",", "self", ".", "_global_endpoint_manager", ",", "self", ".", "connection_policy", ",", "self", ".", "_requests_session", ",", "'GET'", ",", "path", ",", "None", ",", "None", ",", "headers", ")" ]
Azure Cosmos 'GET' http request. :params str url: :params str path: :params dict headers: :return: Tuple of (result, headers). :rtype: tuple of (dict, dict)
[ "Azure", "Cosmos", "GET", "http", "request", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2605-L2627
229,593
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.__Post
def __Post(self, path, request, body, headers): """Azure Cosmos 'POST' http request. :params str url: :params str path: :params (str, unicode, dict) body: :params dict headers: :return: Tuple of (result, headers). :rtype: tuple of (dict, dict) """ return synchronized_request.SynchronizedRequest(self, request, self._global_endpoint_manager, self.connection_policy, self._requests_session, 'POST', path, body, query_params=None, headers=headers)
python
def __Post(self, path, request, body, headers): """Azure Cosmos 'POST' http request. :params str url: :params str path: :params (str, unicode, dict) body: :params dict headers: :return: Tuple of (result, headers). :rtype: tuple of (dict, dict) """ return synchronized_request.SynchronizedRequest(self, request, self._global_endpoint_manager, self.connection_policy, self._requests_session, 'POST', path, body, query_params=None, headers=headers)
[ "def", "__Post", "(", "self", ",", "path", ",", "request", ",", "body", ",", "headers", ")", ":", "return", "synchronized_request", ".", "SynchronizedRequest", "(", "self", ",", "request", ",", "self", ".", "_global_endpoint_manager", ",", "self", ".", "connection_policy", ",", "self", ".", "_requests_session", ",", "'POST'", ",", "path", ",", "body", ",", "query_params", "=", "None", ",", "headers", "=", "headers", ")" ]
Azure Cosmos 'POST' http request. :params str url: :params str path: :params (str, unicode, dict) body: :params dict headers: :return: Tuple of (result, headers). :rtype: tuple of (dict, dict)
[ "Azure", "Cosmos", "POST", "http", "request", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2629-L2652
229,594
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.__Delete
def __Delete(self, path, request, headers): """Azure Cosmos 'DELETE' http request. :params str url: :params str path: :params dict headers: :return: Tuple of (result, headers). :rtype: tuple of (dict, dict) """ return synchronized_request.SynchronizedRequest(self, request, self._global_endpoint_manager, self.connection_policy, self._requests_session, 'DELETE', path, request_data=None, query_params=None, headers=headers)
python
def __Delete(self, path, request, headers): """Azure Cosmos 'DELETE' http request. :params str url: :params str path: :params dict headers: :return: Tuple of (result, headers). :rtype: tuple of (dict, dict) """ return synchronized_request.SynchronizedRequest(self, request, self._global_endpoint_manager, self.connection_policy, self._requests_session, 'DELETE', path, request_data=None, query_params=None, headers=headers)
[ "def", "__Delete", "(", "self", ",", "path", ",", "request", ",", "headers", ")", ":", "return", "synchronized_request", ".", "SynchronizedRequest", "(", "self", ",", "request", ",", "self", ".", "_global_endpoint_manager", ",", "self", ".", "connection_policy", ",", "self", ".", "_requests_session", ",", "'DELETE'", ",", "path", ",", "request_data", "=", "None", ",", "query_params", "=", "None", ",", "headers", "=", "headers", ")" ]
Azure Cosmos 'DELETE' http request. :params str url: :params str path: :params dict headers: :return: Tuple of (result, headers). :rtype: tuple of (dict, dict)
[ "Azure", "Cosmos", "DELETE", "http", "request", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2679-L2701
229,595
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.QueryFeed
def QueryFeed(self, path, collection_id, query, options, partition_key_range_id = None): """Query Feed for Document Collection resource. :param str path: Path to the document collection. :param str collection_id: Id of the document collection. :param (str or dict) query: :param dict options: The request options for the request. :param str partition_key_range_id: Partition key range id. :rtype: tuple """ return self.__QueryFeed(path, 'docs', collection_id, lambda r: r['Documents'], lambda _, b: b, query, options, partition_key_range_id), self.last_response_headers
python
def QueryFeed(self, path, collection_id, query, options, partition_key_range_id = None): """Query Feed for Document Collection resource. :param str path: Path to the document collection. :param str collection_id: Id of the document collection. :param (str or dict) query: :param dict options: The request options for the request. :param str partition_key_range_id: Partition key range id. :rtype: tuple """ return self.__QueryFeed(path, 'docs', collection_id, lambda r: r['Documents'], lambda _, b: b, query, options, partition_key_range_id), self.last_response_headers
[ "def", "QueryFeed", "(", "self", ",", "path", ",", "collection_id", ",", "query", ",", "options", ",", "partition_key_range_id", "=", "None", ")", ":", "return", "self", ".", "__QueryFeed", "(", "path", ",", "'docs'", ",", "collection_id", ",", "lambda", "r", ":", "r", "[", "'Documents'", "]", ",", "lambda", "_", ",", "b", ":", "b", ",", "query", ",", "options", ",", "partition_key_range_id", ")", ",", "self", ".", "last_response_headers" ]
Query Feed for Document Collection resource. :param str path: Path to the document collection. :param str collection_id: Id of the document collection. :param (str or dict) query: :param dict options: The request options for the request. :param str partition_key_range_id: Partition key range id. :rtype: tuple
[ "Query", "Feed", "for", "Document", "Collection", "resource", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2703-L2726
229,596
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.__QueryFeed
def __QueryFeed(self, path, type, id, result_fn, create_fn, query, options=None, partition_key_range_id=None): """Query for more than one Azure Cosmos resources. :param str path: :param str type: :param str id: :param function result_fn: :param function create_fn: :param (str or dict) query: :param dict options: The request options for the request. :param str partition_key_range_id: Specifies partition key range id. :rtype: list :raises SystemError: If the query compatibility mode is undefined. """ if options is None: options = {} if query: __GetBodiesFromQueryResult = result_fn else: def __GetBodiesFromQueryResult(result): if result is not None: return [create_fn(self, body) for body in result_fn(result)] else: # If there is no change feed, the result data is empty and result is None. # This case should be interpreted as an empty array. return [] initial_headers = self.default_headers.copy() # Copy to make sure that default_headers won't be changed. if query is None: # Query operations will use ReadEndpoint even though it uses GET(for feed requests) request = request_object._RequestObject(type, documents._OperationType.ReadFeed) headers = base.GetHeaders(self, initial_headers, 'get', path, id, type, options, partition_key_range_id) result, self.last_response_headers = self.__Get(path, request, headers) return __GetBodiesFromQueryResult(result) else: query = self.__CheckAndUnifyQueryFormat(query) initial_headers[http_constants.HttpHeaders.IsQuery] = 'true' if (self._query_compatibility_mode == CosmosClient._QueryCompatibilityMode.Default or self._query_compatibility_mode == CosmosClient._QueryCompatibilityMode.Query): initial_headers[http_constants.HttpHeaders.ContentType] = runtime_constants.MediaTypes.QueryJson elif self._query_compatibility_mode == CosmosClient._QueryCompatibilityMode.SqlQuery: initial_headers[http_constants.HttpHeaders.ContentType] = runtime_constants.MediaTypes.SQL else: raise SystemError('Unexpected query compatibility mode.') # Query operations will use ReadEndpoint even though it uses POST(for regular query operations) request = request_object._RequestObject(type, documents._OperationType.SqlQuery) headers = base.GetHeaders(self, initial_headers, 'post', path, id, type, options, partition_key_range_id) result, self.last_response_headers = self.__Post(path, request, query, headers) return __GetBodiesFromQueryResult(result)
python
def __QueryFeed(self, path, type, id, result_fn, create_fn, query, options=None, partition_key_range_id=None): """Query for more than one Azure Cosmos resources. :param str path: :param str type: :param str id: :param function result_fn: :param function create_fn: :param (str or dict) query: :param dict options: The request options for the request. :param str partition_key_range_id: Specifies partition key range id. :rtype: list :raises SystemError: If the query compatibility mode is undefined. """ if options is None: options = {} if query: __GetBodiesFromQueryResult = result_fn else: def __GetBodiesFromQueryResult(result): if result is not None: return [create_fn(self, body) for body in result_fn(result)] else: # If there is no change feed, the result data is empty and result is None. # This case should be interpreted as an empty array. return [] initial_headers = self.default_headers.copy() # Copy to make sure that default_headers won't be changed. if query is None: # Query operations will use ReadEndpoint even though it uses GET(for feed requests) request = request_object._RequestObject(type, documents._OperationType.ReadFeed) headers = base.GetHeaders(self, initial_headers, 'get', path, id, type, options, partition_key_range_id) result, self.last_response_headers = self.__Get(path, request, headers) return __GetBodiesFromQueryResult(result) else: query = self.__CheckAndUnifyQueryFormat(query) initial_headers[http_constants.HttpHeaders.IsQuery] = 'true' if (self._query_compatibility_mode == CosmosClient._QueryCompatibilityMode.Default or self._query_compatibility_mode == CosmosClient._QueryCompatibilityMode.Query): initial_headers[http_constants.HttpHeaders.ContentType] = runtime_constants.MediaTypes.QueryJson elif self._query_compatibility_mode == CosmosClient._QueryCompatibilityMode.SqlQuery: initial_headers[http_constants.HttpHeaders.ContentType] = runtime_constants.MediaTypes.SQL else: raise SystemError('Unexpected query compatibility mode.') # Query operations will use ReadEndpoint even though it uses POST(for regular query operations) request = request_object._RequestObject(type, documents._OperationType.SqlQuery) headers = base.GetHeaders(self, initial_headers, 'post', path, id, type, options, partition_key_range_id) result, self.last_response_headers = self.__Post(path, request, query, headers) return __GetBodiesFromQueryResult(result)
[ "def", "__QueryFeed", "(", "self", ",", "path", ",", "type", ",", "id", ",", "result_fn", ",", "create_fn", ",", "query", ",", "options", "=", "None", ",", "partition_key_range_id", "=", "None", ")", ":", "if", "options", "is", "None", ":", "options", "=", "{", "}", "if", "query", ":", "__GetBodiesFromQueryResult", "=", "result_fn", "else", ":", "def", "__GetBodiesFromQueryResult", "(", "result", ")", ":", "if", "result", "is", "not", "None", ":", "return", "[", "create_fn", "(", "self", ",", "body", ")", "for", "body", "in", "result_fn", "(", "result", ")", "]", "else", ":", "# If there is no change feed, the result data is empty and result is None.", "# This case should be interpreted as an empty array.", "return", "[", "]", "initial_headers", "=", "self", ".", "default_headers", ".", "copy", "(", ")", "# Copy to make sure that default_headers won't be changed.", "if", "query", "is", "None", ":", "# Query operations will use ReadEndpoint even though it uses GET(for feed requests)", "request", "=", "request_object", ".", "_RequestObject", "(", "type", ",", "documents", ".", "_OperationType", ".", "ReadFeed", ")", "headers", "=", "base", ".", "GetHeaders", "(", "self", ",", "initial_headers", ",", "'get'", ",", "path", ",", "id", ",", "type", ",", "options", ",", "partition_key_range_id", ")", "result", ",", "self", ".", "last_response_headers", "=", "self", ".", "__Get", "(", "path", ",", "request", ",", "headers", ")", "return", "__GetBodiesFromQueryResult", "(", "result", ")", "else", ":", "query", "=", "self", ".", "__CheckAndUnifyQueryFormat", "(", "query", ")", "initial_headers", "[", "http_constants", ".", "HttpHeaders", ".", "IsQuery", "]", "=", "'true'", "if", "(", "self", ".", "_query_compatibility_mode", "==", "CosmosClient", ".", "_QueryCompatibilityMode", ".", "Default", "or", "self", ".", "_query_compatibility_mode", "==", "CosmosClient", ".", "_QueryCompatibilityMode", ".", "Query", ")", ":", "initial_headers", "[", "http_constants", ".", "HttpHeaders", ".", "ContentType", "]", "=", "runtime_constants", ".", "MediaTypes", ".", "QueryJson", "elif", "self", ".", "_query_compatibility_mode", "==", "CosmosClient", ".", "_QueryCompatibilityMode", ".", "SqlQuery", ":", "initial_headers", "[", "http_constants", ".", "HttpHeaders", ".", "ContentType", "]", "=", "runtime_constants", ".", "MediaTypes", ".", "SQL", "else", ":", "raise", "SystemError", "(", "'Unexpected query compatibility mode.'", ")", "# Query operations will use ReadEndpoint even though it uses POST(for regular query operations)", "request", "=", "request_object", ".", "_RequestObject", "(", "type", ",", "documents", ".", "_OperationType", ".", "SqlQuery", ")", "headers", "=", "base", ".", "GetHeaders", "(", "self", ",", "initial_headers", ",", "'post'", ",", "path", ",", "id", ",", "type", ",", "options", ",", "partition_key_range_id", ")", "result", ",", "self", ".", "last_response_headers", "=", "self", ".", "__Post", "(", "path", ",", "request", ",", "query", ",", "headers", ")", "return", "__GetBodiesFromQueryResult", "(", "result", ")" ]
Query for more than one Azure Cosmos resources. :param str path: :param str type: :param str id: :param function result_fn: :param function create_fn: :param (str or dict) query: :param dict options: The request options for the request. :param str partition_key_range_id: Specifies partition key range id. :rtype: list :raises SystemError: If the query compatibility mode is undefined.
[ "Query", "for", "more", "than", "one", "Azure", "Cosmos", "resources", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2728-L2814
229,597
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient.__CheckAndUnifyQueryFormat
def __CheckAndUnifyQueryFormat(self, query_body): """Checks and unifies the format of the query body. :raises TypeError: If query_body is not of expected type (depending on the query compatibility mode). :raises ValueError: If query_body is a dict but doesn\'t have valid query text. :raises SystemError: If the query compatibility mode is undefined. :param (str or dict) query_body: :return: The formatted query body. :rtype: dict or string """ if (self._query_compatibility_mode == CosmosClient._QueryCompatibilityMode.Default or self._query_compatibility_mode == CosmosClient._QueryCompatibilityMode.Query): if not isinstance(query_body, dict) and not isinstance(query_body, six.string_types): raise TypeError('query body must be a dict or string.') if isinstance(query_body, dict) and not query_body.get('query'): raise ValueError('query body must have valid query text with key "query".') if isinstance(query_body, six.string_types): return {'query': query_body} elif (self._query_compatibility_mode == CosmosClient._QueryCompatibilityMode.SqlQuery and not isinstance(query_body, six.string_types)): raise TypeError('query body must be a string.') else: raise SystemError('Unexpected query compatibility mode.') return query_body
python
def __CheckAndUnifyQueryFormat(self, query_body): """Checks and unifies the format of the query body. :raises TypeError: If query_body is not of expected type (depending on the query compatibility mode). :raises ValueError: If query_body is a dict but doesn\'t have valid query text. :raises SystemError: If the query compatibility mode is undefined. :param (str or dict) query_body: :return: The formatted query body. :rtype: dict or string """ if (self._query_compatibility_mode == CosmosClient._QueryCompatibilityMode.Default or self._query_compatibility_mode == CosmosClient._QueryCompatibilityMode.Query): if not isinstance(query_body, dict) and not isinstance(query_body, six.string_types): raise TypeError('query body must be a dict or string.') if isinstance(query_body, dict) and not query_body.get('query'): raise ValueError('query body must have valid query text with key "query".') if isinstance(query_body, six.string_types): return {'query': query_body} elif (self._query_compatibility_mode == CosmosClient._QueryCompatibilityMode.SqlQuery and not isinstance(query_body, six.string_types)): raise TypeError('query body must be a string.') else: raise SystemError('Unexpected query compatibility mode.') return query_body
[ "def", "__CheckAndUnifyQueryFormat", "(", "self", ",", "query_body", ")", ":", "if", "(", "self", ".", "_query_compatibility_mode", "==", "CosmosClient", ".", "_QueryCompatibilityMode", ".", "Default", "or", "self", ".", "_query_compatibility_mode", "==", "CosmosClient", ".", "_QueryCompatibilityMode", ".", "Query", ")", ":", "if", "not", "isinstance", "(", "query_body", ",", "dict", ")", "and", "not", "isinstance", "(", "query_body", ",", "six", ".", "string_types", ")", ":", "raise", "TypeError", "(", "'query body must be a dict or string.'", ")", "if", "isinstance", "(", "query_body", ",", "dict", ")", "and", "not", "query_body", ".", "get", "(", "'query'", ")", ":", "raise", "ValueError", "(", "'query body must have valid query text with key \"query\".'", ")", "if", "isinstance", "(", "query_body", ",", "six", ".", "string_types", ")", ":", "return", "{", "'query'", ":", "query_body", "}", "elif", "(", "self", ".", "_query_compatibility_mode", "==", "CosmosClient", ".", "_QueryCompatibilityMode", ".", "SqlQuery", "and", "not", "isinstance", "(", "query_body", ",", "six", ".", "string_types", ")", ")", ":", "raise", "TypeError", "(", "'query body must be a string.'", ")", "else", ":", "raise", "SystemError", "(", "'Unexpected query compatibility mode.'", ")", "return", "query_body" ]
Checks and unifies the format of the query body. :raises TypeError: If query_body is not of expected type (depending on the query compatibility mode). :raises ValueError: If query_body is a dict but doesn\'t have valid query text. :raises SystemError: If the query compatibility mode is undefined. :param (str or dict) query_body: :return: The formatted query body. :rtype: dict or string
[ "Checks", "and", "unifies", "the", "format", "of", "the", "query", "body", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2816-L2844
229,598
Azure/azure-cosmos-python
azure/cosmos/cosmos_client.py
CosmosClient._UpdateSessionIfRequired
def _UpdateSessionIfRequired(self, request_headers, response_result, response_headers): """ Updates session if necessary. :param dict response_result: :param dict response_headers: :param dict response_headers :return: None, but updates the client session if necessary. """ '''if this request was made with consistency level as session, then update the session''' if response_result is None or response_headers is None: return is_session_consistency = False if http_constants.HttpHeaders.ConsistencyLevel in request_headers: if documents.ConsistencyLevel.Session == request_headers[http_constants.HttpHeaders.ConsistencyLevel]: is_session_consistency = True if is_session_consistency: # update session self.session.update_session(response_result, response_headers)
python
def _UpdateSessionIfRequired(self, request_headers, response_result, response_headers): """ Updates session if necessary. :param dict response_result: :param dict response_headers: :param dict response_headers :return: None, but updates the client session if necessary. """ '''if this request was made with consistency level as session, then update the session''' if response_result is None or response_headers is None: return is_session_consistency = False if http_constants.HttpHeaders.ConsistencyLevel in request_headers: if documents.ConsistencyLevel.Session == request_headers[http_constants.HttpHeaders.ConsistencyLevel]: is_session_consistency = True if is_session_consistency: # update session self.session.update_session(response_result, response_headers)
[ "def", "_UpdateSessionIfRequired", "(", "self", ",", "request_headers", ",", "response_result", ",", "response_headers", ")", ":", "'''if this request was made with consistency level as session, then update\n the session'''", "if", "response_result", "is", "None", "or", "response_headers", "is", "None", ":", "return", "is_session_consistency", "=", "False", "if", "http_constants", ".", "HttpHeaders", ".", "ConsistencyLevel", "in", "request_headers", ":", "if", "documents", ".", "ConsistencyLevel", ".", "Session", "==", "request_headers", "[", "http_constants", ".", "HttpHeaders", ".", "ConsistencyLevel", "]", ":", "is_session_consistency", "=", "True", "if", "is_session_consistency", ":", "# update session", "self", ".", "session", ".", "update_session", "(", "response_result", ",", "response_headers", ")" ]
Updates session if necessary. :param dict response_result: :param dict response_headers: :param dict response_headers :return: None, but updates the client session if necessary.
[ "Updates", "session", "if", "necessary", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/cosmos_client.py#L2912-L2938
229,599
Azure/azure-cosmos-python
azure/cosmos/base.py
GetResourceIdOrFullNameFromLink
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. :rtype: str """ # For named based, the resource link is the full name if IsNameBased(resource_link): return TrimBeginningAndEndingSlashes(resource_link) # Padding the resource link with leading and trailing slashes if not already if resource_link[-1] != '/': resource_link = resource_link + '/' if resource_link[0] != '/': resource_link = '/' + resource_link # The path will be in the form of # /[resourceType]/[resourceId]/ .... /[resourceType]/[resourceId]/ or # /[resourceType]/[resourceId]/ .... /[resourceType]/ # The result of split will be in the form of # ["", [resourceType], [resourceId] ... ,[resourceType], [resourceId], ""] # In the first case, to extract the resourceId it will the element # before last ( at length -2 ) and the the type will before it # ( at length -3 ) # In the second case, to extract the resource type it will the element # before last ( at length -2 ) path_parts = resource_link.split("/") if len(path_parts) % 2 == 0: # request in form # /[resourceType]/[resourceId]/ .... /[resourceType]/[resourceId]/. return str(path_parts[-2]) return None
python
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. :rtype: str """ # For named based, the resource link is the full name if IsNameBased(resource_link): return TrimBeginningAndEndingSlashes(resource_link) # Padding the resource link with leading and trailing slashes if not already if resource_link[-1] != '/': resource_link = resource_link + '/' if resource_link[0] != '/': resource_link = '/' + resource_link # The path will be in the form of # /[resourceType]/[resourceId]/ .... /[resourceType]/[resourceId]/ or # /[resourceType]/[resourceId]/ .... /[resourceType]/ # The result of split will be in the form of # ["", [resourceType], [resourceId] ... ,[resourceType], [resourceId], ""] # In the first case, to extract the resourceId it will the element # before last ( at length -2 ) and the the type will before it # ( at length -3 ) # In the second case, to extract the resource type it will the element # before last ( at length -2 ) path_parts = resource_link.split("/") if len(path_parts) % 2 == 0: # request in form # /[resourceType]/[resourceId]/ .... /[resourceType]/[resourceId]/. return str(path_parts[-2]) return None
[ "def", "GetResourceIdOrFullNameFromLink", "(", "resource_link", ")", ":", "# For named based, the resource link is the full name", "if", "IsNameBased", "(", "resource_link", ")", ":", "return", "TrimBeginningAndEndingSlashes", "(", "resource_link", ")", "# Padding the resource link with leading and trailing slashes if not already", "if", "resource_link", "[", "-", "1", "]", "!=", "'/'", ":", "resource_link", "=", "resource_link", "+", "'/'", "if", "resource_link", "[", "0", "]", "!=", "'/'", ":", "resource_link", "=", "'/'", "+", "resource_link", "# The path will be in the form of ", "# /[resourceType]/[resourceId]/ .... /[resourceType]/[resourceId]/ or", "# /[resourceType]/[resourceId]/ .... /[resourceType]/", "# The result of split will be in the form of", "# [\"\", [resourceType], [resourceId] ... ,[resourceType], [resourceId], \"\"]", "# In the first case, to extract the resourceId it will the element", "# before last ( at length -2 ) and the the type will before it", "# ( at length -3 )", "# In the second case, to extract the resource type it will the element", "# before last ( at length -2 )", "path_parts", "=", "resource_link", ".", "split", "(", "\"/\"", ")", "if", "len", "(", "path_parts", ")", "%", "2", "==", "0", ":", "# request in form", "# /[resourceType]/[resourceId]/ .... /[resourceType]/[resourceId]/.", "return", "str", "(", "path_parts", "[", "-", "2", "]", ")", "return", "None" ]
Gets resource id or full name from resource link. :param str resource_link: :return: The resource id or full name from the resource link. :rtype: str
[ "Gets", "resource", "id", "or", "full", "name", "from", "resource", "link", "." ]
dd01b3c5d308c6da83cfcaa0ab7083351a476353
https://github.com/Azure/azure-cosmos-python/blob/dd01b3c5d308c6da83cfcaa0ab7083351a476353/azure/cosmos/base.py#L217-L252