Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tables] Updates for apiview & sphinx docs #18134

Merged
16 commits merged into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/tables/azure-data-tables/azure/data/tables/_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __getattr__(self, name):
:param name:name of entity entry
:type name: str
:return: TableEntity dictionary
:rtype: dict[str,str]
:rtype: Dict[str,str]
"""
try:
return self[name]
Expand Down
74 changes: 57 additions & 17 deletions sdk/tables/azure-data-tables/azure/data/tables/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,15 @@ def __init__(
self.delete = kwargs.pop("delete", None) or ("d" in _str)

def __or__(self, other):
# type: (TableSasPermissions) -> TableSasPermissions
return TableSasPermissions(_str=str(self) + str(other))

def __add__(self, other):
# type: (TableSasPermissions) -> TableSasPermissions
return TableSasPermissions(_str=str(self) + str(other))

def __str__(self):
# type: () -> TableSasPermissions
return (
("r" if self.read else "")
+ ("a" if self.add else "")
Expand All @@ -416,9 +419,10 @@ def __str__(self):
@classmethod
def from_string(
cls,
permission, # type: str
permission,
**kwargs
):
# Type: (str, Dict[str, Any]) -> AccountSasPermissions
"""Create AccountSasPermissions from a string.

To specify read, write, delete, etc. permissions you need only to
Expand All @@ -428,8 +432,8 @@ def from_string(
:param str permission: Specify permissions in
the string with the first letter of the word.
:keyword callable cls: A custom type or function that will be passed the direct response
:return: A AccountSasPermissions object
:rtype: ~azure.data.tables.AccountSasPermissions
:return: An AccountSasPermissions object
:rtype: :class:`~azure.data.tables.AccountSasPermissions`
"""
p_read = "r" in permission
p_add = "a" in permission
Expand Down Expand Up @@ -486,14 +490,14 @@ class TableItem(object):
"""

def __init__(self, table_name, **kwargs):
# type: (str, **Any) -> None
# type: (str, Dict[str, Any]) -> None
self.table_name = table_name
self.api_version = kwargs.get("version")
self.date = kwargs.get("date") or kwargs.get("Date")

@classmethod
def _from_generated(cls, generated, **kwargs):
# type: (obj, **Any) -> cls
# type: (obj, Dict[str, Any) -> cls
return cls(generated.table_name, **kwargs)


Expand Down Expand Up @@ -541,12 +545,18 @@ def __init__(self, message, response, parts):
class BatchErrorException(HttpResponseError):
"""There is a failure in batch operations.

:param str message: The message of the exception.
:param message: The message of the exception.
:type message: str
:param response: Server response to be deserialized.
:param list parts: A list of the parts in multipart response.
:type response: str
:param parts: A list of the parts in multipart response.
:type parts: :class:`~azure.core.pipeline.transport.HttpResponse`
:param args: Args to be passed to :class:`~azure.core.exceptions.HttpResponseError`
:type args: List[:class:`~azure.core.pipeline.transport.HttpResponse`]
"""

def __init__(self, message, response, parts, *args, **kwargs):
# type: (str, str, HttpResponse, List[HttpResponse], Dict[str, Any]) -> None
self.parts = parts
super(BatchErrorException, self).__init__(
message=message, response=response, *args, **kwargs
Expand All @@ -557,28 +567,57 @@ class BatchTransactionResult(object):
"""The result of a successful batch operation, can be used by a user to
recreate a request in the case of BatchErrorException

:param List[HttpRequest] requests: The requests of the batch
:param List[HttpResponse] results: The HTTP response of each request
:param requests: The requests of the batch
:type requests: List[~azure.core.pipeline.HttpRequest]
:param results: The HTTP response of each request
:type results: List[~azure.core.pipeline.HttpResponse]
:param entities: Entities submitted for the batch
:type entities: List[~azure.data.tables.TableEntity]
"""

def __init__(self, requests, results, entities):
# type: (List[HttpRequest], List[HttpResponse], List[TableEntity]) -> None
self.requests = requests
self.results = results
self.entities = entities

def get_entity(self, row_key):
# type: (str) -> Union[Dict[str], TableEntity]
"""Get entity for a given row key

:param row_key: The row_key correlating to an entity
:type row_key: str
:return: TableEntity or Dictionary submitted
:rtype: Union[Dict[str], TableEntity]
"""
for entity in self.entities:
if entity["RowKey"] == row_key:
return entity
return None

def get_request(self, row_key):
# type: (str) -> HttpRequest
"""Get request for a given row key

:param row_key: The row_key correlating to an entity
:type row_key: str
:return: HTTP Request for a row key
:rtype: :class:`~azure.core.pipeline.transport.HttpRequest`
"""
for i, entity in enumerate(self.entities):
if entity["RowKey"] == row_key:
return self.requests[i]
return None

def get_result(self, row_key):
# type: (str) -> HttpResponse
"""Get response for a given row key

:param row_key: The row_key correlating to an entity
:type row_key: str
:return: HTTP Response for a row key
:rtype: :class:`~azure.core.pipeline.HttpResponse`
"""
for i, entity in enumerate(self.entities):
if entity["RowKey"] == row_key:
return self.results[i]
Expand Down Expand Up @@ -609,9 +648,8 @@ class ResourceTypes(object):
Access to object-level APIs for tables (e.g. Get/Create/Query Entity etc.)
"""

def __init__(
self, service=False, object=False
): # pylint: disable=redefined-builtin
def __init__(self, service=False, object=False): # pylint: disable=redefined-builtin
# type: (bool, bool) -> None
self.service = service
self.object = object
self._str = ("s" if self.service else "") + ("o" if self.object else "")
Expand All @@ -621,6 +659,7 @@ def __str__(self):

@classmethod
def from_string(cls, string):
# type: (str) -> ResourceTypes
"""Create a ResourceTypes from a string.

To specify service, container, or object you need only to
Expand All @@ -630,7 +669,7 @@ def from_string(cls, string):
:param str string: Specify service, container, or object in
in the string with the first letter of the word.
:return: A ResourceTypes object
:rtype: ~azure.data.tables.ResourceTypes
:rtype: :class:`~azure.data.tables.ResourceTypes`
"""
res_service = "s" in string
res_object = "o" in string
Expand Down Expand Up @@ -696,17 +735,18 @@ def __str__(self):

@classmethod
def from_string(cls, permission, **kwargs):
# type: (str, Dict[str]) -> AccountSasPermissions
"""Create AccountSasPermissions from a string.

To specify read, write, delete, etc. permissions you need only to
include the first letter of the word in the string. E.g. for read and write
permissions you would provide a string "rw".

:param str permission: Specify permissions in
the string with the first letter of the word.
:param permission: Specify permissions in the string with the first letter of the word.
:type permission: str
:keyword callable cls: A custom type or function that will be passed the direct response
:return: A AccountSasPermissions object
:rtype: ~azure.data.tables.AccountSasPermissions
:return: An AccountSasPermissions object
:rtype: :class:`~azure.data.tables.AccountSasPermissions`
"""
p_read = "r" in permission
p_write = "w" in permission
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def send(self, request):
:param request: The PipelineRequest object
:type request: ~azure.core.pipeline.PipelineRequest
:return: Returns the PipelineResponse or raises error if maximum retries exceeded.
:rtype: ~azure.core.pipeline.PipelineResponse
:rtype: :class:`~azure.core.pipeline.PipelineResponse`
:raises: ~azure.core.exceptions.AzureError if maximum retries exceeded.
:raises: ~azure.core.exceptions.ClientAuthenticationError if authentication
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _parameter_filter_substitution(parameters, query_filter):
# type: (Dict[str, str], str) -> str
"""Replace user defined parameter in filter
:param parameters: User defined parameters
:param filter: Filter for querying
:param str query_filter: Filter for querying
"""
if parameters:
filter_strings = query_filter.split(' ')
Expand Down
18 changes: 7 additions & 11 deletions sdk/tables/azure-data-tables/azure/data/tables/_table_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,10 @@ def update_entity(
:param entity: The properties for the table entity.
:type entity: TableEntity or dict[str,str]
:param mode: Merge or Replace entity
:type mode: ~azure.data.tables.UpdateMode
:type mode: :class:`~azure.data.tables.UpdateMode`
:keyword str etag: Etag of the entity
:keyword ~azure.core.MatchConditions match_condition: MatchCondition
:keyword match_condition: MatchCondition
:paramtype match_condition: :class:`~azure.core.MatchConditions`
:return: None
:raises ValueError:

Expand Down Expand Up @@ -294,8 +295,6 @@ def _batch_update_entity(
:param query_options: Parameter group.
:type query_options: ~azure.data.tables.models.QueryOptions
:return: None
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
"""

_format = None
Expand Down Expand Up @@ -402,8 +401,6 @@ def _batch_merge_entity(
:param query_options: Parameter group.
:type query_options: ~azure.data.tables.models.QueryOptions
:return: None
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
"""

_format = None
Expand Down Expand Up @@ -490,7 +487,8 @@ def delete_entity(
:param row_key: The row key of the entity.
:type row_key: str
:keyword str etag: Etag of the entity
:keyword ~azure.core.MatchConditions match_condition: MatchCondition
:keyword match_condition: MatchCondition
:paramtype match_condition: :class:`~azure.core.MatchConditions`
:raises ValueError:

.. admonition:: Example:
Expand Down Expand Up @@ -560,8 +558,6 @@ def _batch_delete_entity(
:param query_options: Parameter group.
:type query_options: ~azure.data.tables.models.QueryOptions
:return: None
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
"""

_format = None
Expand Down Expand Up @@ -632,8 +628,8 @@ def upsert_entity(

:param entity: The properties for the table entity.
:type entity: TableEntity or dict[str,str]
:param mode: Merge or Replace and Insert on fail
:type mode: ~azure.data.tables.UpdateMode
:param mode: Merge or Replace entity
:type mode: :class:`~azure.data.tables.UpdateMode`
:raises ValueError:

.. admonition:: Example:
Expand Down
Loading