def update_entity(self, table_name, partition_key, row_key, entity, content_type='application/atom+xml', if_match='*'): ''' Updates an existing entity in a table. The Update Entity operation replaces the entire entity and can be used to remove properties. entity: Required. The entity object to insert. Could be a dict format or entity object. partition_key: PartitionKey of the entity. row_key: RowKey of the entity. Content-Type: this is required and has to be set to application/atom+xml ''' _validate_not_none('table_name', table_name) _validate_not_none('partition_key', partition_key) _validate_not_none('row_key', row_key) _validate_not_none('entity', entity) _validate_not_none('content_type', content_type) request = HTTPRequest() request.method = 'PUT' request.host = _get_table_host(self.account_name, self.use_local_storage) request.path = '/' + str(table_name) + '(PartitionKey=\'' + str( partition_key) + '\',RowKey=\'' + str(row_key) + '\')' request.headers = [('Content-Type', _str_or_none(content_type)), ('If-Match', _str_or_none(if_match))] request.body = _get_request_body(convert_entity_to_xml(entity)) request.path, request.query = _update_request_uri_query_local_storage( request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request)
def insert_or_merge_entity(self, table_name, partition_key, row_key, entity, content_type='application/atom+xml'): ''' Merges an existing entity or inserts a new entity if it does not exist in the table. Because this operation can insert or update an entity, it is also known as an "upsert" operation. entity: Required. The entity object to insert. Could be a dict format or entity object. partition_key: PartitionKey of the entity. row_key: RowKey of the entity. Content-Type: this is required and has to be set to application/atom+xml ''' _validate_not_none('table_name', table_name) _validate_not_none('partition_key', partition_key) _validate_not_none('row_key', row_key) _validate_not_none('entity', entity) _validate_not_none('content_type', content_type) request = HTTPRequest() request.method = 'MERGE' request.host = self._get_host() request.path = '/' + str(table_name) + '(PartitionKey=\'' + str(partition_key) + '\',RowKey=\'' + str(row_key) + '\')' request.headers = [('Content-Type', _str_or_none(content_type))] request.body = _get_request_body(convert_entity_to_xml(entity)) request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _parse_response_for_dict_filter(response, filter=['etag'])
def query_entities(self, table_name, filter=None, select=None, top=None, next_partition_key=None, next_row_key=None): """ Get entities in a table; includes the $filter and $select options. table_name: Table to query. filter: Optional. Filter as described at http://msdn.microsoft.com/en-us/library/windowsazure/dd894031.aspx select: Optional. Property names to select from the entities. top: Optional. Maximum number of entities to return. next_partition_key: Optional. When top is used, the next partition key is stored in result.x_ms_continuation['NextPartitionKey'] next_row_key: Optional. When top is used, the next partition key is stored in result.x_ms_continuation['NextRowKey'] """ _validate_not_none('table_name', table_name) request = HTTPRequest() request.method = 'GET' request.host = self._get_host() request.path = '/' + _str(table_name) + '()' request.query = [ ('$filter', _str_or_none(filter)), ('$select', _str_or_none(select)), ('$top', _int_or_none(top)), ('NextPartitionKey', _str_or_none(next_partition_key)), ('NextRowKey', _str_or_none(next_row_key)) ] request.path, request.query = _update_request_uri_query_local_storage( request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _convert_response_to_feeds(response, _convert_xml_to_entity)
def insert_entity(self, table_name, entity, content_type='application/atom+xml'): ''' Inserts a new entity into a table. table_name: Table name. entity: Required. The entity object to insert. Could be a dict format or entity object. content_type: Required. Must be set to application/atom+xml ''' _validate_not_none('table_name', table_name) _validate_not_none('entity', entity) _validate_not_none('content_type', content_type) request = HTTPRequest() request.method = 'POST' request.host = self._get_host() request.path = '/' + _str(table_name) + '' request.headers = [('Content-Type', _str_or_none(content_type))] request.body = _get_request_body(_convert_entity_to_xml(entity)) request.path, request.query = _update_request_uri_query_local_storage( request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _convert_response_to_entity(response)
def merge_entity(self, table_name, partition_key, row_key, entity, content_type='application/atom+xml', if_match='*'): ''' Updates an existing entity by updating the entity's properties. This operation does not replace the existing entity as the Update Entity operation does. entity: Required. The entity object to insert. Can be a dict format or entity object. partition_key: PartitionKey of the entity. row_key: RowKey of the entity. Content-Type: this is required and has to be set to application/atom+xml ''' _validate_not_none('table_name', table_name) _validate_not_none('partition_key', partition_key) _validate_not_none('row_key', row_key) _validate_not_none('entity', entity) _validate_not_none('content_type', content_type) request = HTTPRequest() request.method = 'MERGE' request.host = _get_table_host(self.account_name, self.use_local_storage) request.path = '/' + str(table_name) + '(PartitionKey=\'' + str(partition_key) + '\',RowKey=\'' + str(row_key) + '\')' request.headers = [ ('Content-Type', _str_or_none(content_type)), ('If-Match', _str_or_none(if_match)) ] request.body = _get_request_body(convert_entity_to_xml(entity)) request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _parse_response_for_dict_filter(response, filter=['etag'])
def query_entities(self, table_name, filter=None, select=None, top=None, next_partition_key=None, next_row_key=None): ''' Get entities in a table; includes the $filter and $select options. table_name: the table to query filter: a filter as described at http://msdn.microsoft.com/en-us/library/windowsazure/dd894031.aspx select: the property names to select from the entities top: the maximum number of entities to return ''' _validate_not_none('table_name', table_name) request = HTTPRequest() request.method = 'GET' request.host = _get_table_host(self.account_name, self.use_local_storage) request.path = '/' + str(table_name) + '()' request.query = [ ('$filter', _str_or_none(filter)), ('$select', _str_or_none(select)), ('$top', _int_or_none(top)), ('NextPartitionKey', _str_or_none(next_partition_key)), ('NextRowKey', _str_or_none(next_row_key)) ] request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _convert_response_to_feeds(response, _convert_xml_to_entity)
def query_tables(self, table_name=None, top=None, next_table_name=None): ''' Returns a list of tables under the specified account. table_name: Optional. The specific table to query. top: Optional. Maximum number of tables to return. next_table_name: Optional. When top is used, the next table name is stored in result.x_ms_continuation['NextTableName'] ''' request = HTTPRequest() request.method = 'GET' request.host = self._get_host() if table_name is not None: uri_part_table_name = "('" + table_name + "')" else: uri_part_table_name = "" request.path = '/Tables' + uri_part_table_name + '' request.query = [('$top', _int_or_none(top)), ('NextTableName', _str_or_none(next_table_name))] request.path, request.query = _update_request_uri_query_local_storage( request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _ETreeXmlToObject.convert_response_to_feeds( response, _convert_etree_element_to_table)
def get_entity(self, table_name, partition_key, row_key, select=''): ''' Get an entity in a table; includes the $select options. partition_key: PartitionKey of the entity. row_key: RowKey of the entity. select: Property names to select. ''' _validate_not_none('table_name', table_name) _validate_not_none('partition_key', partition_key) _validate_not_none('row_key', row_key) _validate_not_none('select', select) request = HTTPRequest() request.method = 'GET' request.host = self._get_host() request.path = '/' + _str(table_name) + \ '(PartitionKey=\'' + _str(partition_key) + \ '\',RowKey=\'' + \ _str(row_key) + '\')?$select=' + \ _str(select) + '' request.path, request.query = _update_request_uri_query_local_storage( request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _convert_response_to_entity(response)
def delete_table(self, table_name, fail_not_exist=False): ''' table_name: Name of the table to delete. fail_not_exist: Specify whether throw exception when table doesn't exist. ''' _validate_not_none('table_name', table_name) request = HTTPRequest() request.method = 'DELETE' request.host = self._get_host() request.path = '/Tables(\'' + _str(table_name) + '\')' request.path, request.query = _update_request_uri_query_local_storage( request, self.use_local_storage) request.headers = _update_storage_table_header(request) if not fail_not_exist: try: self._perform_request(request) return True except WindowsAzureError as ex: _dont_fail_not_exist(ex) return False else: self._perform_request(request) return True
def create_table(self, table, fail_on_exist=False): ''' Creates a new table in the storage account. table: Name of the table to create. Table name may contain only alphanumeric characters and cannot begin with a numeric character. It is case-insensitive and must be from 3 to 63 characters long. fail_on_exist: Specify whether throw exception when table exists. ''' _validate_not_none('table', table) request = HTTPRequest() request.method = 'POST' request.host = self._get_host() request.path = '/Tables' request.body = _get_request_body(_convert_table_to_xml(table)) request.path, request.query = _update_request_uri_query_local_storage( request, self.use_local_storage) request.headers = _update_storage_table_header(request) if not fail_on_exist: try: self._perform_request(request) return True except WindowsAzureError as ex: _dont_fail_on_exist(ex) return False else: self._perform_request(request) return True
def create_table(self, table, fail_on_exist=False): ''' Creates a new table in the storage account. table: name of the table to create. fail_on_exist: specify whether throw exception when table exists. ''' _validate_not_none('table', table) request = HTTPRequest() request.method = 'POST' request.host = _get_table_host(self.account_name, self.use_local_storage) request.path = '/Tables' request.body = _get_request_body(convert_table_to_xml(table)) request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage) request.headers = _update_storage_table_header(request) if not fail_on_exist: try: self._perform_request(request) return True except WindowsAzureError as e: _dont_fail_on_exist(e) return False else: self._perform_request(request) return True
def delete_entity(self, table_name, partition_key, row_key, content_type='application/atom+xml', if_match='*'): ''' Deletes an existing entity in a table. partition_key: PartitionKey of the entity. row_key: RowKey of the entity. if_match: Required. Specifies the condition for which the delete should be performed. To force an unconditional delete, set If-Match to the wildcard character (*). Content-Type: this is required and has to be set to application/atom+xml ''' _validate_not_none('table_name', table_name) _validate_not_none('partition_key', partition_key) _validate_not_none('row_key', row_key) _validate_not_none('content_type', content_type) _validate_not_none('if_match', if_match) request = HTTPRequest() request.method = 'DELETE' request.host = _get_table_host(self.account_name, self.use_local_storage) request.path = '/' + str(table_name) + '(PartitionKey=\'' + str(partition_key) + '\',RowKey=\'' + str(row_key) + '\')' request.headers = [ ('Content-Type', _str_or_none(content_type)), ('If-Match', _str_or_none(if_match)) ] request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request)
def create_table(self, table, fail_on_exist=False): ''' Creates a new table in the storage account. table: name of the table to create. Table name may contain only alphanumeric characters and cannot begin with a numeric character. It is case-insensitive and must be from 3 to 63 characters long. fail_on_exist: specify whether throw exception when table exists. ''' _validate_not_none('table', table) request = HTTPRequest() request.method = 'POST' request.host = _get_table_host(self.account_name, self.use_local_storage) request.path = '/Tables' request.body = _get_request_body(convert_table_to_xml(table)) request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage) request.headers = _update_storage_table_header(request) if not fail_on_exist: try: self._perform_request(request) return True except WindowsAzureError as e: _dont_fail_on_exist(e) return False else: self._perform_request(request) return True
def delete_entity(self, table_name, partition_key, row_key, content_type='application/atom+xml', if_match='*'): ''' Deletes an existing entity in a table. table_name: Table name. partition_key: PartitionKey of the entity. row_key: RowKey of the entity. content_type: Required. Must be set to application/atom+xml if_match: Optional. Specifies the condition for which the delete should be performed. To force an unconditional delete, set to the wildcard character (*). ''' _validate_not_none('table_name', table_name) _validate_not_none('partition_key', partition_key) _validate_not_none('row_key', row_key) _validate_not_none('content_type', content_type) _validate_not_none('if_match', if_match) request = HTTPRequest() request.method = 'DELETE' request.host = self._get_host() request.path = '/' + _str(table_name) + '(PartitionKey=\'' + _str( partition_key) + '\',RowKey=\'' + _str(row_key) + '\')' request.headers = [('Content-Type', _str_or_none(content_type)), ('If-Match', _str_or_none(if_match))] request.path, request.query = _update_request_uri_query_local_storage( request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request)
def create_table(self, table, fail_on_exist=False): ''' Creates a new table in the storage account. table: name of the table to create. fail_on_exist: specify whether throw exception when table exists. ''' _validate_not_none('table', table) request = HTTPRequest() request.method = 'POST' request.host = _get_table_host(self.account_name, self.use_local_storage) request.path = '/Tables' request.body = _get_request_body(convert_table_to_xml(table)) request.path, request.query = _update_request_uri_query_local_storage( request, self.use_local_storage) request.headers = _update_storage_table_header(request) if not fail_on_exist: try: self._perform_request(request) return True except WindowsAzureError as e: _dont_fail_on_exist(e) return False else: self._perform_request(request) return True
def insert_or_merge_entity(self, table_name, partition_key, row_key, entity, content_type='application/atom+xml'): ''' Merges an existing entity or inserts a new entity if it does not exist in the table. Because this operation can insert or update an entity, it is also known as an "upsert" operation. entity: Required. The entity object to insert. Could be a dict format or entity object. partition_key: PartitionKey of the entity. row_key: RowKey of the entity. Content-Type: this is required and has to be set to application/atom+xml ''' _validate_not_none('table_name', table_name) _validate_not_none('partition_key', partition_key) _validate_not_none('row_key', row_key) _validate_not_none('entity', entity) _validate_not_none('content_type', content_type) request = HTTPRequest() request.method = 'MERGE' request.host = _get_table_host(self.account_name, self.use_local_storage) request.path = '/' + str(table_name) + '(PartitionKey=\'' + str(partition_key) + '\',RowKey=\'' + str(row_key) + '\')' request.headers = [('Content-Type', _str_or_none(content_type))] request.body = _get_request_body(convert_entity_to_xml(entity)) request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _parse_response_for_dict_filter(response, filter=['etag'])
def merge_entity(self, table_name, partition_key, row_key, entity, content_type='application/atom+xml', if_match='*'): ''' Updates an existing entity by updating the entity's properties. This operation does not replace the existing entity as the Update Entity operation does. entity: Required. The entity object to insert. Can be a dict format or entity object. partition_key: PartitionKey of the entity. row_key: RowKey of the entity. Content-Type: this is required and has to be set to application/atom+xml ''' _validate_not_none('table_name', table_name) _validate_not_none('partition_key', partition_key) _validate_not_none('row_key', row_key) _validate_not_none('entity', entity) _validate_not_none('content_type', content_type) request = HTTPRequest() request.method = 'MERGE' request.host = self._get_host() request.path = '/' + str(table_name) + '(PartitionKey=\'' + str(partition_key) + '\',RowKey=\'' + str(row_key) + '\')' request.headers = [ ('Content-Type', _str_or_none(content_type)), ('If-Match', _str_or_none(if_match)) ] request.body = _get_request_body(convert_entity_to_xml(entity)) request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _parse_response_for_dict_filter(response, filter=['etag'])
def query_entities(self, table_name, filter=None, select=None, top=None, next_partition_key=None, next_row_key=None): ''' Get entities in a table; includes the $filter and $select options. table_name: the table to query filter: a filter as described at http://msdn.microsoft.com/en-us/library/windowsazure/dd894031.aspx select: the property names to select from the entities top: the maximum number of entities to return ''' _validate_not_none('table_name', table_name) request = HTTPRequest() request.method = 'GET' request.host = self._get_host() request.path = '/' + str(table_name) + '()' request.query = [ ('$filter', _str_or_none(filter)), ('$select', _str_or_none(select)), ('$top', _int_or_none(top)), ('NextPartitionKey', _str_or_none(next_partition_key)), ('NextRowKey', _str_or_none(next_row_key)) ] request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _convert_response_to_feeds(response, _convert_xml_to_entity)
def query_tables(self, table_name = None, top=None, next_table_name=None): ''' Returns a list of tables under the specified account. table_name: Optional. The specific table to query. top: Optional. Maximum number of tables to return. next_table_name: Optional. When top is used, the next table name is stored in result.x_ms_continuation['NextTableName'] ''' request = HTTPRequest() request.method = 'GET' request.host = self._get_host() if table_name is not None: uri_part_table_name = "('" + table_name + "')" else: uri_part_table_name = "" request.path = '/Tables' + uri_part_table_name + '' request.query = [ ('$top', _int_or_none(top)), ('NextTableName', _str_or_none(next_table_name)) ] request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _convert_response_to_feeds(response, _convert_xml_to_table)
def get_table_service_properties(self): ''' Gets the properties of a storage account's Table service, including Windows Azure Storage Analytics. ''' request = HTTPRequest() request.method = 'GET' request.host = self._get_host() request.path = '/?restype=service&comp=properties' request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _parse_response(response, StorageServiceProperties)
def get_table_service_properties(self): ''' Gets the properties of a storage account's Table service, including Windows Azure Storage Analytics. ''' request = HTTPRequest() request.method = 'GET' request.host = _get_table_host(self.account_name, self.use_local_storage) request.path = '/?restype=service&comp=properties' request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _parse_response(response, StorageServiceProperties)
def update_entity(self, table_name, partition_key, row_key, entity, content_type='application/atom+xml', if_match='*'): ''' Updates an existing entity in a table. The Update Entity operation replaces the entire entity and can be used to remove properties. table_name: Table name. partition_key: PartitionKey of the entity. row_key: RowKey of the entity. entity: Required. The entity object to insert. Could be a dict format or entity object. content_type: Required. Must be set to application/atom+xml if_match: Optional. Specifies the condition for which the merge should be performed. To force an unconditional merge, set to the wildcard character (*). ''' _validate_not_none('table_name', table_name) _validate_not_none('partition_key', partition_key) _validate_not_none('row_key', row_key) _validate_not_none('entity', entity) _validate_not_none('content_type', content_type) request = HTTPRequest() request.method = 'PUT' request.host = self._get_host() request.path = '/' + \ _str(table_name) + '(PartitionKey=\'' + \ _str(partition_key) + '\',RowKey=\'' + _str(row_key) + '\')' request.headers = [('Content-Type', _str_or_none(content_type)), ('If-Match', _str_or_none(if_match))] request.body = _get_request_body(_convert_entity_to_xml(entity)) request.path, request.query = _update_request_uri_query_local_storage( request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _parse_response_for_dict_filter(response, filter=['etag'])
def update_entity(self, table_name, partition_key, row_key, entity, content_type='application/atom+xml', if_match='*',use_json='True'): ''' Updates an existing entity in a table. The Update Entity operation replaces the entire entity and can be used to remove properties. table_name: Table name. partition_key: PartitionKey of the entity. row_key: RowKey of the entity. entity: Required. The entity object to insert. Could be a dict format or entity object. content_type: Required. Must be set to application/atom+xml if_match: Optional. Specifies the condition for which the merge should be performed. To force an unconditional merge, set to the wildcard character (*). ''' _validate_not_none('table_name', table_name) _validate_not_none('partition_key', partition_key) _validate_not_none('row_key', row_key) _validate_not_none('entity', entity) _validate_not_none('content_type', content_type) request = HTTPRequest() request.method = 'PUT' request.host = self._get_host() request.path = '/' + \ _str(table_name) + '(PartitionKey=\'' + \ _str(partition_key) + '\',RowKey=\'' + _str(row_key) + '\')' request.headers = [ ('Content-Type', _str_or_none(content_type)), ('If-Match', _str_or_none(if_match)) ] if not use_json: request.body = _get_request_body(_convert_entity_to_xml(entity)) else: request.body = entity request.path, request.query = _update_request_uri_query_local_storage( request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _parse_response_for_dict_filter(response, filter=['etag'])
def set_table_service_properties(self, storage_service_properties): ''' Sets the properties of a storage account's Table Service, including Windows Azure Storage Analytics. storage_service_properties: a StorageServiceProperties object. ''' _validate_not_none('storage_service_properties', storage_service_properties) request = HTTPRequest() request.method = 'PUT' request.host = self._get_host() request.path = '/?restype=service&comp=properties' request.body = _get_request_body(_convert_class_to_xml(storage_service_properties)) request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _parse_response_for_dict(response)
def set_table_service_properties(self, storage_service_properties): ''' Sets the properties of a storage account's Table Service, including Windows Azure Storage Analytics. storage_service_properties: a StorageServiceProperties object. ''' _validate_not_none('storage_service_properties', storage_service_properties) request = HTTPRequest() request.method = 'PUT' request.host = _get_table_host(self.account_name, self.use_local_storage) request.path = '/?restype=service&comp=properties' request.body = _get_request_body(_convert_class_to_xml(storage_service_properties)) request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _parse_response_for_dict(response)
def query_entities(self, table_name, filter=None, select=None, top=None, next_partition_key=None, next_row_key=None): ''' Get entities in a table; includes the $filter and $select options. table_name: Table to query. filter: Optional. Filter as described at http://msdn.microsoft.com/en-us/library/windowsazure/dd894031.aspx select: Optional. Property names to select from the entities. top: Optional. Maximum number of entities to return. next_partition_key: Optional. When top is used, the next partition key is stored in result.x_ms_continuation['NextPartitionKey'] next_row_key: Optional. When top is used, the next partition key is stored in result.x_ms_continuation['NextRowKey'] ''' _validate_not_none('table_name', table_name) request = HTTPRequest() request.method = 'GET' request.host = self._get_host() request.path = '/' + _str(table_name) + '()' request.query = [('$filter', _str_or_none(filter)), ('$select', _str_or_none(select)), ('$top', _int_or_none(top)), ('NextPartitionKey', _str_or_none(next_partition_key)), ('NextRowKey', _str_or_none(next_row_key))] request.path, request.query = _update_request_uri_query_local_storage( request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _ETreeXmlToObject.convert_response_to_feeds( response, _convert_etree_element_to_entity)
def get_table_acl(self, table_name): ''' Returns details about any stored access policies specified on the table that may be used with Shared Access Signatures. table_name: Name of existing table. ''' _validate_not_none('table_name', table_name) request = HTTPRequest() request.method = 'GET' request.host = self._get_host() request.path = '/' + _str(table_name) + '?comp=acl' request.path, request.query = _update_request_uri_query_local_storage( request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _ETreeXmlToObject.parse_response(response, SignedIdentifiers)
def query_tables(self, table_name = None, top=None): ''' Returns a list of tables under the specified account. table_name: optional, the specific table to query top: the maximum number of tables to return ''' request = HTTPRequest() request.method = 'GET' request.host = _get_table_host(self.account_name, self.use_local_storage) if table_name is not None: uri_part_table_name = "('" + table_name + "')" else: uri_part_table_name = "" request.path = '/Tables' + uri_part_table_name + '' request.query = [('$top', _int_or_none(top))] request.path, request.query = _update_request_uri_query_local_storage(request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _convert_response_to_feeds(response, _convert_xml_to_table)
def set_table_acl(self, table_name, signed_identifiers=None): ''' Sets stored access policies for the table that may be used with Shared Access Signatures. table_name: Name of existing table. signed_identifiers: SignedIdentifers instance ''' _validate_not_none('table_name', table_name) request = HTTPRequest() request.method = 'PUT' request.host = self._get_host() request.path = '/' + _str(table_name) + '?comp=acl' request.body = _get_request_body( _convert_signed_identifiers_to_xml(signed_identifiers)) request.path, request.query = _update_request_uri_query_local_storage( request, self.use_local_storage) request.headers = _update_storage_table_header(request, content_type=None) self._perform_request(request)
def query_tables(self, table_name=None, top=None, next_table_name=None): ''' Returns a list of tables under the specified account. table_name: optional, the specific table to query top: the maximum number of tables to return ''' request = HTTPRequest() request.method = 'GET' request.host = self._get_host() if table_name is not None: uri_part_table_name = "('" + table_name + "')" else: uri_part_table_name = "" request.path = '/Tables' + uri_part_table_name + '' request.query = [('$top', _int_or_none(top)), ('NextTableName', _str_or_none(next_table_name))] request.path, request.query = _update_request_uri_query_local_storage( request, self.use_local_storage) request.headers = _update_storage_table_header(request) response = self._perform_request(request) return _convert_response_to_feeds(response, _convert_xml_to_table)
def commit_batch_requests(self): ''' Commits the batch requests. ''' batch_boundary = b'batch_' + _new_boundary() changeset_boundary = b'changeset_' + _new_boundary() # Commits batch only the requests list is not empty. if self.batch_requests: request = HTTPRequest() request.method = 'POST' request.host = self.batch_requests[0].host request.path = '/$batch' request.headers = [ ('Content-Type', 'multipart/mixed; boundary=' + \ batch_boundary.decode('utf-8')), ('Accept', 'application/atom+xml,application/xml'), ('Accept-Charset', 'UTF-8')] request.body = b'--' + batch_boundary + b'\n' request.body += b'Content-Type: multipart/mixed; boundary=' request.body += changeset_boundary + b'\n\n' content_id = 1 # Adds each request body to the POST data. for batch_request in self.batch_requests: request.body += b'--' + changeset_boundary + b'\n' request.body += b'Content-Type: application/http\n' request.body += b'Content-Transfer-Encoding: binary\n\n' request.body += batch_request.method.encode('utf-8') request.body += b' http://' request.body += batch_request.host.encode('utf-8') request.body += batch_request.path.encode('utf-8') request.body += b' HTTP/1.1\n' request.body += b'Content-ID: ' request.body += str(content_id).encode('utf-8') + b'\n' content_id += 1 # Add different headers for different type requests. if not batch_request.method == 'DELETE': request.body += \ b'Content-Type: application/atom+xml;type=entry\n' request.body += b'Content-Length: ' request.body += str(len(batch_request.body)).encode('utf-8') request.body += b'\n\n' request.body += batch_request.body + b'\n' else: for name, value in batch_request.headers: # If-Match should be already included in # batch_request.headers, but in case it is missing, # just add it. if name == 'If-Match': request.body += name.encode('utf-8') + b': ' request.body += value.encode('utf-8') + b'\n\n' break else: request.body += b'If-Match: *\n\n' request.body += b'--' + changeset_boundary + b'--' + b'\n' request.body += b'--' + batch_boundary + b'--' request.path, request.query = _update_request_uri_query(request) request.headers = _update_storage_table_header(request) auth = _sign_storage_table_request(request, self.account_name, self.account_key) request.headers.append(('Authorization', auth)) # Submit the whole request as batch request. response = self.perform_request(request) resp = response.body if response.status >= 300: raise HTTPError(response.status, _ERROR_BATCH_COMMIT_FAIL, self.respheader, resp) return resp
def commit_batch_requests(self): ''' Commits the batch requests. ''' batch_boundary = b'batch_' + _new_boundary() changeset_boundary = b'changeset_' + _new_boundary() # Commits batch only the requests list is not empty. if self.batch_requests: request = HTTPRequest() request.method = 'POST' request.host = self.batch_requests[0].host request.path = '/$batch' request.headers = [ ('Content-Type', 'multipart/mixed; boundary=' + \ batch_boundary.decode('utf-8')), ('Accept', 'application/atom+xml,application/xml'), ('Accept-Charset', 'UTF-8')] request.body = b'--' + batch_boundary + b'\n' request.body += b'Content-Type: multipart/mixed; boundary=' request.body += changeset_boundary + b'\n\n' content_id = 1 # Adds each request body to the POST data. for batch_request in self.batch_requests: request.body += b'--' + changeset_boundary + b'\n' request.body += b'Content-Type: application/http\n' request.body += b'Content-Transfer-Encoding: binary\n\n' request.body += batch_request.method.encode('utf-8') request.body += b' http://' request.body += batch_request.host.encode('utf-8') request.body += batch_request.path.encode('utf-8') request.body += b' HTTP/1.1\n' request.body += b'Content-ID: ' request.body += str(content_id).encode('utf-8') + b'\n' content_id += 1 # Add different headers for different type requests. if not batch_request.method == 'DELETE': request.body += \ b'Content-Type: application/atom+xml;type=entry\n' for name, value in batch_request.headers: if name == 'If-Match': request.body += name.encode('utf-8') + b': ' request.body += value.encode('utf-8') + b'\n' break request.body += b'Content-Length: ' request.body += str(len(batch_request.body)).encode('utf-8') request.body += b'\n\n' request.body += batch_request.body + b'\n' else: for name, value in batch_request.headers: # If-Match should be already included in # batch_request.headers, but in case it is missing, # just add it. if name == 'If-Match': request.body += name.encode('utf-8') + b': ' request.body += value.encode('utf-8') + b'\n\n' break else: request.body += b'If-Match: *\n\n' request.body += b'--' + changeset_boundary + b'--' + b'\n' request.body += b'--' + batch_boundary + b'--' request.path, request.query = _update_request_uri_query(request) request.headers = _update_storage_table_header(request) auth = _sign_storage_table_request(request, self.account_name, self.account_key) request.headers.append(('Authorization', auth)) # Submit the whole request as batch request. response = self.perform_request(request) if response.status >= 300: raise HTTPError(response.status, _ERROR_BATCH_COMMIT_FAIL, self.respheader, response.body) # http://www.odata.org/documentation/odata-version-2-0/batch-processing/ # The body of a ChangeSet response is either a response for all the # successfully processed change request within the ChangeSet, # formatted exactly as it would have appeared outside of a batch, # or a single response indicating a failure of the entire ChangeSet. responses = self._parse_batch_response(response.body) if responses and responses[0].status >= 300: self._report_batch_error(responses[0])
def commit_batch_requests(self): ''' Commits the batch requests. ''' batch_boundary = b'batch_' + _new_boundary() changeset_boundary = b'changeset_' + _new_boundary() # Commits batch only the requests list is not empty. if self.batch_requests: request = HTTPRequest() request.method = 'POST' request.host = self.batch_requests[0].host request.path = '/$batch' request.headers = [ ('Content-Type', 'multipart/mixed; boundary=' + \ batch_boundary.decode('utf-8')), ('Accept', 'application/atom+xml,application/xml'), ('Accept-Charset', 'UTF-8')] request.body = b'--' + batch_boundary + b'\n' request.body += b'Content-Type: multipart/mixed; boundary=' request.body += changeset_boundary + b'\n\n' content_id = 1 # Adds each request body to the POST data. for batch_request in self.batch_requests: request.body += b'--' + changeset_boundary + b'\n' request.body += b'Content-Type: application/http\n' request.body += b'Content-Transfer-Encoding: binary\n\n' request.body += batch_request.method.encode('utf-8') request.body += b' http://' request.body += batch_request.host.encode('utf-8') request.body += batch_request.path.encode('utf-8') request.body += b' HTTP/1.1\n' request.body += b'Content-ID: ' request.body += str(content_id).encode('utf-8') + b'\n' content_id += 1 # Add different headers for different type requests. if not batch_request.method == 'DELETE': request.body += \ b'Content-Type: application/atom+xml;type=entry\n' request.body += b'Content-Length: ' request.body += str(len( batch_request.body)).encode('utf-8') request.body += b'\n\n' request.body += batch_request.body + b'\n' else: for name, value in batch_request.headers: # If-Match should be already included in # batch_request.headers, but in case it is missing, # just add it. if name == 'If-Match': request.body += name.encode('utf-8') + b': ' request.body += value.encode('utf-8') + b'\n\n' break else: request.body += b'If-Match: *\n\n' request.body += b'--' + changeset_boundary + b'--' + b'\n' request.body += b'--' + batch_boundary + b'--' request.path, request.query = _update_request_uri_query(request) request.headers = _update_storage_table_header(request) auth = _sign_storage_table_request(request, self.account_name, self.account_key) request.headers.append(('Authorization', auth)) # Submit the whole request as batch request. response = self.perform_request(request) resp = response.body if response.status >= 300: raise HTTPError(response.status, _ERROR_BATCH_COMMIT_FAIL, self.respheader, resp) return resp
def commit_batch_requests(self): ''' Commits the batch requests. ''' batch_boundary = 'batch_a2e9d677-b28b-435e-a89e-87e6a768a431' changeset_boundary = 'changeset_8128b620-b4bb-458c-a177-0959fb14c977' #Commits batch only the requests list is not empty. if self.batch_requests: request = HTTPRequest() request.method = 'POST' request.host = self.batch_requests[0].host request.path = '/$batch' request.headers = [('Content-Type', 'multipart/mixed; boundary=' + batch_boundary), ('Accept', 'application/atom+xml,application/xml'), ('Accept-Charset', 'UTF-8')] request.body = '--' + batch_boundary + '\n' request.body += 'Content-Type: multipart/mixed; boundary=' + changeset_boundary + '\n\n' content_id = 1 # Adds each request body to the POST data. for batch_request in self.batch_requests: request.body += '--' + changeset_boundary + '\n' request.body += 'Content-Type: application/http\n' request.body += 'Content-Transfer-Encoding: binary\n\n' request.body += batch_request.method + ' http://' + batch_request.host + batch_request.path + ' HTTP/1.1\n' request.body += 'Content-ID: ' + str(content_id) + '\n' content_id += 1 # Add different headers for different type requests. if not batch_request.method == 'DELETE': request.body += 'Content-Type: application/atom+xml;type=entry\n' request.body += 'Content-Length: ' + str(len(batch_request.body)) + '\n\n' request.body += batch_request.body + '\n' else: find_if_match = False for name, value in batch_request.headers: #If-Match should be already included in batch_request.headers, but in case it is missing, just add it. if name == 'If-Match': request.body += name + ': ' + value + '\n\n' break else: request.body += 'If-Match: *\n\n' request.body += '--' + changeset_boundary + '--' + '\n' request.body += '--' + batch_boundary + '--' request.path, request.query = _update_request_uri_query(request) request.headers = _update_storage_table_header(request) auth = _sign_storage_table_request(request, self.account_name, self.account_key) request.headers.append(('Authorization', auth)) #Submit the whole request as batch request. response = self.perform_request(request) resp = response.body if response.status >= 300: raise HTTPError(status, azure._ERROR_BATCH_COMMIT_FAIL, self.respheader, resp) return resp
def commit_batch_requests(self): """ Commits the batch requests. """ batch_boundary = 'batch_a2e9d677-b28b-435e-a89e-87e6a768a431' changeset_boundary = 'changeset_8128b620-b4bb-458c-a177-0959fb14c977' # Commits batch only the requests list is not empty. if self.batch_requests: request = HTTPRequest() request.method = 'POST' request.host = self.batch_requests[0].host request.path = '/$batch' request.headers = [( 'Content-Type', 'multipart/mixed; boundary=' + batch_boundary), ('Accept', 'application/atom+xml,application/xml'), ('Accept-Charset', 'UTF-8')] request.body = '--' + batch_boundary + '\n' request.body += 'Content-Type: multipart/mixed; boundary=' + \ changeset_boundary + '\n\n' content_id = 1 # Adds each request body to the POST data. for batch_request in self.batch_requests: request.body += '--' + changeset_boundary + '\n' request.body += 'Content-Type: application/http\n' request.body += 'Content-Transfer-Encoding: binary\n\n' request.body += batch_request.method + ' http://' + \ batch_request.host + batch_request.path + ' HTTP/1.1\n' request.body += 'Content-ID: ' + str(content_id) + '\n' content_id += 1 # Add different headers for different type requests. if not batch_request.method == 'DELETE': request.body += 'Content-Type: application/atom+xml;type=entry\n' request.body += 'Content-Length: ' + \ str(len(batch_request.body)) + '\n\n' request.body += batch_request.body + '\n' else: for name, value in batch_request.headers: # If-Match should be already included in # batch_request.headers, but in case it is missing, # just add it. if name == 'If-Match': request.body += name + ': ' + value + '\n\n' break else: request.body += 'If-Match: *\n\n' request.body += '--' + changeset_boundary + '--' + '\n' request.body += '--' + batch_boundary + '--' request.path, request.query = _update_request_uri_query(request) request.headers = _update_storage_table_header(request) auth = _sign_storage_table_request(request, self.account_name, self.account_key) request.headers.append(('Authorization', auth)) # Submit the whole request as batch request. response = self.perform_request(request) resp = response.body if response.status >= 300: raise HTTPError( status, azure._ERROR_BATCH_COMMIT_FAIL, self.respheader, resp) return resp
def commit_batch_requests(self): ''' Commits the batch requests. ''' batch_boundary = b'batch_' + _new_boundary() changeset_boundary = b'changeset_' + _new_boundary() # Commits batch only the requests list is not empty. if self.batch_requests: request = HTTPRequest() request.method = 'POST' request.host = self.batch_requests[0].host request.path = '/$batch' request.headers = [ ('Content-Type', 'multipart/mixed; boundary=' + \ batch_boundary.decode('utf-8')), ('Accept', 'application/atom+xml,application/xml'), ('Accept-Charset', 'UTF-8')] request.body = b'--' + batch_boundary + b'\n' request.body += b'Content-Type: multipart/mixed; boundary=' request.body += changeset_boundary + b'\n\n' content_id = 1 # Adds each request body to the POST data. for batch_request in self.batch_requests: request.body += b'--' + changeset_boundary + b'\n' request.body += b'Content-Type: application/http\n' request.body += b'Content-Transfer-Encoding: binary\n\n' request.body += batch_request.method.encode('utf-8') request.body += b' http://' request.body += batch_request.host.encode('utf-8') request.body += batch_request.path.encode('utf-8') request.body += b' HTTP/1.1\n' request.body += b'Content-ID: ' request.body += str(content_id).encode('utf-8') + b'\n' content_id += 1 # Add different headers for different type requests. if not batch_request.method == 'DELETE': request.body += \ b'Content-Type: application/atom+xml;type=entry\n' for name, value in batch_request.headers: if name == 'If-Match': request.body += name.encode('utf-8') + b': ' request.body += value.encode('utf-8') + b'\n' break request.body += b'Content-Length: ' request.body += str(len( batch_request.body)).encode('utf-8') request.body += b'\n\n' request.body += batch_request.body + b'\n' else: for name, value in batch_request.headers: # If-Match should be already included in # batch_request.headers, but in case it is missing, # just add it. if name == 'If-Match': request.body += name.encode('utf-8') + b': ' request.body += value.encode('utf-8') + b'\n\n' break else: request.body += b'If-Match: *\n\n' request.body += b'--' + changeset_boundary + b'--' + b'\n' request.body += b'--' + batch_boundary + b'--' request.path, request.query = _update_request_uri_query(request) request.headers = _update_storage_table_header(request) self.authentication.sign_request(request) # Submit the whole request as batch request. response = self.perform_request(request) if response.status >= 300: raise HTTPError(response.status, _ERROR_BATCH_COMMIT_FAIL, self.respheader, response.body) # http://www.odata.org/documentation/odata-version-2-0/batch-processing/ # The body of a ChangeSet response is either a response for all the # successfully processed change request within the ChangeSet, # formatted exactly as it would have appeared outside of a batch, # or a single response indicating a failure of the entire ChangeSet. responses = self._parse_batch_response(response.body) if responses and responses[0].status >= 300: self._report_batch_error(responses[0])