Skip to content

Commit b5cda04

Browse files
author
Jens Kürten
committed
more docstrings
1 parent 3d6730e commit b5cda04

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

csfunctions/service/file_upload.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818

1919

2020
def _generate_lock_id():
21+
"""Generate a random 12-character lock ID."""
2122
return "".join(choice(ascii_letters) for i in range(12)) # nosec
2223

2324

2425
class FileUploadService(BaseService):
2526
def _create_new_file(self, filename: str, parent_object_id: str, persno: str, check_access: bool = True) -> str:
26-
"""Creates a new (empty) file attached to the parent object and returns the cdb_object_id."""
27+
"""Create a new empty file attached to the parent object."""
2728
response_json = self.request(
2829
endpoint="/file_upload/create",
2930
method="POST",
@@ -37,6 +38,7 @@ def _create_new_file(self, filename: str, parent_object_id: str, persno: str, ch
3738
def _get_presigned_write_urls(
3839
self, file_object_id: str, filesize: int, lock_id: str, persno: str, check_access: bool = True
3940
) -> PresignedWriteUrls:
41+
"""Request presigned URLs for uploading file chunks."""
4042
response_json = self.request(
4143
endpoint=f"/file_upload/{file_object_id}/generate_presigned_url",
4244
method="POST",
@@ -50,7 +52,7 @@ def _get_presigned_write_urls(
5052
def _upload_from_stream(
5153
self, presigned_urls: PresignedWriteUrls, stream: BinaryIO
5254
) -> tuple[PresignedWriteUrls, str]:
53-
"""Upload file stream in chunks using presigned URLs and return updated context + sha256 hash."""
55+
"""Upload file stream in chunks and return updated presigned URLs and sha256 hash."""
5456
etags: list[str] = []
5557
sha256 = hashlib.sha256()
5658
for url in presigned_urls.urls:
@@ -70,6 +72,7 @@ def _upload_from_stream(
7072

7173
@staticmethod
7274
def _get_stream_size(stream: BinaryIO) -> int:
75+
"""Get the size of a seekable stream."""
7376
if not stream.seekable():
7477
raise ValueError("Stream is not seekable; size cannot be determined.")
7578
current_pos = stream.tell()
@@ -89,6 +92,7 @@ def _complete_upload(
8992
sha256: str | None = None,
9093
delete_derived_files: bool = True,
9194
) -> None:
95+
"""Mark the upload as complete and finalize the file."""
9296
self.request(
9397
endpoint=f"/file_upload/{file_object_id}/complete",
9498
method="POST",
@@ -106,6 +110,7 @@ def _complete_upload(
106110
def _abort_upload(
107111
self, file_object_id: str, lock_id: str, persno: str, presigned_write_urls: PresignedWriteUrls
108112
) -> None:
113+
"""Abort an ongoing file upload."""
109114
self.request(
110115
endpoint=f"/file_upload/{file_object_id}/abort",
111116
method="POST",

0 commit comments

Comments
 (0)