Skip to content

Commit

Permalink
Fixed function signatures to uniformly use Optional[] as type hint wh…
Browse files Browse the repository at this point in the history
…ere appropriate
  • Loading branch information
glpatcern committed Oct 1, 2024
1 parent 2acec4e commit 15f0dea
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion cs3client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(
self._config: Config = config

def open_in_app(
self, auth_token: tuple, resource: Resource, view_mode: str = None, app: str = None
self, auth_token: tuple, resource: Resource, view_mode: Optional[str] = None, app: Optional[str] = None
) -> cs3apr.OpenInAppURL:
"""
Open a file in an app, given the resource, view mode (VIEW_MODE_VIEW_ONLY, VIEW_MODE_READ_ONLY,
Expand Down
2 changes: 1 addition & 1 deletion cs3client/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def list_file_versions(
return res.versions

def restore_file_version(
self, auth_token: tuple, resource: Resource, version_key: str, lock_id: str = None
self, auth_token: tuple, resource: Resource, version_key: str, lock_id: Optional[str] = None
) -> None:
"""
Restore a file to a previous version.
Expand Down
12 changes: 6 additions & 6 deletions cs3client/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def stat(self, auth_token: tuple, resource: Resource) -> cs3spr.ResourceInfo:
)
return res.info

def set_xattr(self, auth_token: tuple, resource: Resource, key: str, value: str, lock_id: str = None) -> None:
def set_xattr(self, auth_token: tuple, resource: Resource, key: str, value: str, lock_id: Optional[str] = None) -> None:
"""
Set the extended attribute <key> to <value> for a resource.
Expand All @@ -94,7 +94,7 @@ def set_xattr(self, auth_token: tuple, resource: Resource, key: str, value: str,
self._status_code_handler.handle_errors(res.status, "set extended attribute", resource.get_file_ref_str())
self._log.debug(f'msg="Invoked setxattr" trace="{res.status.trace}"')

def remove_xattr(self, auth_token: tuple, resource: Resource, key: str, lock_id: str = None) -> None:
def remove_xattr(self, auth_token: tuple, resource: Resource, key: str, lock_id: Optional[str] = None) -> None:
"""
Remove the extended attribute <key>.
Expand All @@ -113,7 +113,7 @@ def remove_xattr(self, auth_token: tuple, resource: Resource, key: str, lock_id:
self._log.debug(f'msg="Invoked UnsetArbitraryMetaData" trace="{res.status.trace}"')

def rename_file(
self, auth_token: tuple, resource: Resource, newresource: Resource, lock_id: str = None
self, auth_token: tuple, resource: Resource, newresource: Resource, lock_id: Optional[str] = None
) -> None:
"""
Rename/move resource to new resource.
Expand All @@ -133,7 +133,7 @@ def rename_file(
self._status_code_handler.handle_errors(res.status, "rename file", resource.get_file_ref_str())
self._log.debug(f'msg="Invoked Move" trace="{res.status.trace}"')

def remove_file(self, auth_token: tuple, resource: Resource, lock_id: str = None) -> None:
def remove_file(self, auth_token: tuple, resource: Resource, lock_id: Optional[str] = None) -> None:
"""
Remove a resource.
Expand Down Expand Up @@ -171,7 +171,7 @@ def touch_file(self, auth_token: tuple, resource: Resource) -> None:

def write_file(
self, auth_token: tuple, resource: Resource, content: Union[str, bytes], size: int,
app_name: str = None, lock_id: str = None
app_name: Optional[str] = None, lock_id: Optional[str] = None
) -> None:
"""
Write a file using the given userid as access token. The entire content is written
Expand Down Expand Up @@ -270,7 +270,7 @@ def write_file(
f'elapsedTimems="{(tend - tstart) * 1000:.1f}"'
)

def read_file(self, auth_token: tuple, resource: Resource, lock_id: str = None) -> Generator[bytes, None, None]:
def read_file(self, auth_token: tuple, resource: Resource, lock_id: Optional[str] = None) -> Generator[bytes, None, None]:
"""
Read a file. Note that the function is a generator, managed by the app server.
Expand Down
82 changes: 41 additions & 41 deletions cs3client/share.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def create_share(
return res.share

def list_existing_shares(
self, auth_token: tuple, filter_list: list[cs3scr.Filter] = None, page_size: int = 0, page_token: str = None
self, auth_token: tuple, filter_list: list[cs3scr.Filter] = None, page_size: int = 0, page_token: Optional[str] = None
) -> list[cs3scr.Share]:
"""
List shares based on a filter.
Expand All @@ -109,7 +109,7 @@ def list_existing_shares(
)
return (res.share_infos, res.next_page_token)

def get_share(self, auth_token: tuple, opaque_id: str = None, share_key: cs3scr.ShareKey = None) -> cs3scr.Share:
def get_share(self, auth_token: tuple, opaque_id: Optional[str] = None, share_key: Optional[cs3scr.ShareKey] = None) -> cs3scr.Share:
"""
Get a share by its opaque id or share key (combination of resource_id, grantee and owner),
one of them is required.
Expand Down Expand Up @@ -141,7 +141,7 @@ def get_share(self, auth_token: tuple, opaque_id: str = None, share_key: cs3scr.
)
return res.share

def remove_share(self, auth_token: tuple, opaque_id: str = None, share_key: cs3scr.ShareKey = None) -> None:
def remove_share(self, auth_token: tuple, opaque_id: Optional[str] = None, share_key: Optional[cs3scr.ShareKey] = None) -> None:
"""
Remove a share by its opaque id or share key (combination of resource_id, grantee and owner),
one of them is required.
Expand Down Expand Up @@ -175,9 +175,9 @@ def remove_share(self, auth_token: tuple, opaque_id: str = None, share_key: cs3s
def update_share(
self, auth_token: tuple,
role: str,
opaque_id: str = None,
share_key: cs3scr.ShareKey = None,
display_name: str = None
opaque_id: Optional[str] = None,
share_key: Optional[cs3scr.ShareKey] = None,
display_name: Optional[str] = None
) -> cs3scr.Share:
"""
Update a share by its opaque id.
Expand Down Expand Up @@ -216,7 +216,7 @@ def update_share(
return res.share

def list_received_existing_shares(
self, auth_token: tuple, filter_list: list = None, page_size: int = 0, page_token: str = None
self, auth_token: tuple, filter_list: Optional[list] = None, page_size: int = 0, page_token: Optional[str] = None
) -> list:
"""
List received existing shares.
Expand All @@ -240,7 +240,7 @@ def list_received_existing_shares(
return (res.share_infos, res.next_page_token)

def get_received_share(
self, auth_token: tuple, opaque_id: str = None, share_key: cs3scr.ShareKey = None
self, auth_token: tuple, opaque_id: Optional[str] = None, share_key: Optional[cs3scr.ShareKey] = None
) -> cs3scr.ReceivedShare:
"""
Get a received share by its opaque id or share key (combination of resource_id, grantee and owner),
Expand Down Expand Up @@ -313,12 +313,12 @@ def create_public_share(
auth_token: tuple,
resource_info: cs3spr.ResourceInfo,
role: str,
password: str = None,
expiration: cs3types.Timestamp = None,
description: str = None,
password: Optional[str] = None,
expiration: Optional[cs3types.Timestamp] = None,
description: Optional[str] = None,
internal: bool = False,
notify_uploads: bool = False,
notify_uploads_extra_recipients: list = None,
notify_uploads_extra_recipients: Optional[list] = None,
) -> cs3slr.PublicShare:
"""
Create a public share.
Expand Down Expand Up @@ -358,7 +358,7 @@ def create_public_share(
return res.share

def list_existing_public_shares(
self, auth_token: tuple, filter_list: list = None, page_size: int = 0, page_token: str = None, sign: bool = None
self, auth_token: tuple, filter_list: Optional[list] = None, page_size: int = 0, page_token: Optional[str] = None, sign: bool = False
) -> list:
"""
List existing public shares.
Expand All @@ -385,7 +385,7 @@ def list_existing_public_shares(
return (res.share_infos, res.next_page_token)

def get_public_share(
self, auth_token: tuple, opaque_id: str = None, token: str = None, sign: bool = False
self, auth_token: tuple, opaque_id: Optional[str] = None, token: Optional[str] = None, sign: bool = False
) -> cs3slr.PublicShare:
"""
Get a public share by its opaque id or token, one of them is required.
Expand Down Expand Up @@ -423,14 +423,14 @@ def update_public_share(
auth_token: tuple,
type: str,
role: str,
opaque_id: str = None,
token: str = None,
password: str = None,
expiration: cs3types.Timestamp = None,
notify_uploads_extra_recipients: str = None,
description: str = None,
display_name: str = None,
notify_uploads: bool = None,
opaque_id: Optional[str] = None,
token: Optional[str] = None,
password: Optional[str] = None,
expiration: Optional[cs3types.Timestamp] = None,
notify_uploads_extra_recipients: Optional[str] = None,
description: Optional[str] = None,
display_name: Optional[str] = None,
notify_uploads: bool = False,
) -> None:
"""
Update a public share by its opaque id or token. (one of them is required), role and type are required,
Expand Down Expand Up @@ -486,7 +486,7 @@ def update_public_share(
)
return res.share

def remove_public_share(self, auth_token: tuple, token: str = None, opaque_id: str = None) -> None:
def remove_public_share(self, auth_token: tuple, token: Optional[str] = None, opaque_id: Optional[str] = None) -> None:
"""
Remove a public share by its token or opaque id, one of them is required.
Expand Down Expand Up @@ -520,12 +520,12 @@ def _create_public_share_update(
cls,
type: str,
role: str,
password: str = None,
expiration: cs3types.Timestamp = None,
display_name: str = None,
description: str = None,
notify_uploads: bool = None,
notify_uploads_extra_recipients: str = None,
password: Optional[str] = None,
expiration: Optional[cs3types.Timestamp] = None,
display_name: Optional[str] = None,
description: Optional[str] = None,
notify_uploads: bool = False,
notify_uploads_extra_recipients: Optional[str] = None,
) -> cs3slr.PublicShare:
"""
Create a public share update object, based on the type the property will be updated,
Expand Down Expand Up @@ -567,7 +567,7 @@ def _create_public_share_update(

@classmethod
def _create_share_grant(
cls, opaque_id: str, idp: str, role: str, grantee_type: str, expiration: cs3types.Timestamp = None
cls, opaque_id: str, idp: str, role: str, grantee_type: str, expiration: Optional[cs3types.Timestamp] = None
) -> cs3scr.ShareGrant:
"""
Create a share grant object.
Expand Down Expand Up @@ -643,10 +643,10 @@ def create_public_share_filter(
cls,
filter_type: str,
resource_id: cs3spr.ResourceId = None,
owner_idp: str = None,
owner_opaque_id: str = None,
creator_idp: str = None,
creator_opaque_id: str = None,
owner_idp: Optional[str] = None,
owner_opaque_id: Optional[str] = None,
creator_idp: Optional[str] = None,
creator_opaque_id: Optional[str] = None,
) -> cs3slapi.ListPublicSharesRequest.Filter:
"""
Create a public share filter object, based on the filter type (can be TYPE_RESOURCE_ID, TYPE_OWNER,
Expand Down Expand Up @@ -688,13 +688,13 @@ def create_share_filter(
cls,
filter_type: str,
resource_id: cs3spr.ResourceId = None,
owner_idp: str = None,
owner_opaque_id: str = None,
creator_idp: str = None,
creator_opaque_id: str = None,
grantee_type: str = None,
space_id: str = None,
share_state: str = None,
owner_idp: Optional[str] = None,
owner_opaque_id: Optional[str] = None,
creator_idp: Optional[str] = None,
creator_opaque_id: Optional[str] = None,
grantee_type: Optional[str] = None,
space_id: Optional[str] = None,
share_state: Optional[str] = None,
) -> cs3scr.Filter:
"""
Create a share filter object, based on the filter type (can be TYPE_RESOURCE_ID, TYPE_OWNER, TYPE_CREATOR,
Expand Down
14 changes: 7 additions & 7 deletions cs3client/statuscodehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,53 @@ def __init__(self, log: logging.Logger, config: Config) -> None:
self._log = log
self._config = config

def _log_not_found_info(self, status: cs3status.Status, operation: str, status_msg: str, msg: str = None) -> None:
def _log_not_found_info(self, status: cs3status.Status, operation: str, status_msg: str, msg: Optional[str] = None) -> None:
self._log.info(
f'msg="Not found on {operation}" {msg + " " if msg else ""} '
f'userid="{self._config.auth_client_id if self._config.auth_client_id else "no_id_set"}" '
f'trace="{status.trace}" reason="{status_msg}"'
)

def _log_authentication_error(
self, status: cs3status.Status, operation: str, status_msg: str, msg: str = None
self, status: cs3status.Status, operation: str, status_msg: str, msg: Optional[str] = None
) -> None:
self._log.error(
f'msg="Authentication failed on {operation}" {msg + " " if msg else ""}'
f'userid="{self._config.auth_client_id if self._config.auth_client_id else "no_id_set"}" '
f'trace="{status.trace}" reason="{status_msg}"'
)

def _log_unknown_error(self, status: cs3status.Status, operation: str, status_msg: str, msg: str = None) -> None:
def _log_unknown_error(self, status: cs3status.Status, operation: str, status_msg: str, msg: Optional[str] = None) -> None:
self._log.error(
f'msg="Failed to {operation}, unknown error" {msg + " " if msg else ""}'
f'userid="{self._config.auth_client_id if self._config.auth_client_id else "no_id_set"}" '
f'trace="{status.trace}" reason="{status_msg}"'
)

def _log_precondition_info(
self, status: cs3status.Status, operation: str, status_msg: str, msg: str = None
self, status: cs3status.Status, operation: str, status_msg: str, msg: Optional[str] = None
) -> None:
self._log.info(
f'msg="Failed precondition on {operation}" {msg + " " if msg else ""}'
f'userid="{self._config.auth_client_id if self._config.auth_client_id else "no_id_set"}" '
f'trace="{status.trace}" reason="{status_msg}"'
)

def _log_already_exists(self, status: cs3status.Status, operation: str, status_msg: str, msg: str = None) -> None:
def _log_already_exists(self, status: cs3status.Status, operation: str, status_msg: str, msg: Optional[str] = None) -> None:
self._log.info(
f'msg="Already exists on {operation}" {msg + " " if msg else ""}'
f'userid="{self._config.auth_client_id if self._config.auth_client_id else "no_id_set"}" '
f'trace="{status.trace}" reason="{status_msg}"'
)

def _log_unimplemented(self, status: cs3status.Status, operation: str, status_msg: str, msg: str = None) -> None:
def _log_unimplemented(self, status: cs3status.Status, operation: str, status_msg: str, msg: Optional[str] = None) -> None:
self._log.info(
f'msg="Invoked {operation} on unimplemented feature" {msg + " " if msg else ""}'
f'userid="{self._config.auth_client_id if self._config.auth_client_id else "no_id_set"}" '
f'trace="{status.trace}" reason="{status_msg}"'
)

def handle_errors(self, status: cs3status.Status, operation: str, msg: str = None) -> None:
def handle_errors(self, status: cs3status.Status, operation: str, msg: Optional[str] = None) -> None:

if status.code == cs3code.CODE_OK:
return
Expand Down

0 comments on commit 15f0dea

Please sign in to comment.