Skip to content

Commit 030d686

Browse files
committed
Refactor file handler access to use get_handler()
Replaced direct access to file.handler with file.get_handler() in directupload.py, nativeupload.py, and packaging.py for improved encapsulation and consistency. Also made minor formatting improvements in nativeupload.py.
1 parent 56e4e64 commit 030d686

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

dvuploader/directupload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ async def _upload_singlepart(
250250
"headers": headers,
251251
"url": ticket["url"],
252252
"content": upload_bytes(
253-
file=file.handler, # type: ignore
253+
file=file.get_handler(), # type: ignore
254254
progress=progress,
255255
pbar=pbar,
256256
hash_func=file.checksum._hash_fun,

dvuploader/nativeupload.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ async def native_upload(
9292
}
9393

9494
files_new = [file for file in files if not file.to_replace]
95-
files_new_metadata = [file for file in files if file.to_replace and file._unchanged_data]
96-
files_replace = [file for file in files if file.to_replace and not file._unchanged_data]
95+
files_new_metadata = [
96+
file for file in files if file.to_replace and file._unchanged_data
97+
]
98+
files_replace = [
99+
file for file in files if file.to_replace and not file._unchanged_data
100+
]
97101

98102
# These are not in a package but need a metadtata update, ensure even for zips
99103
for file in files_new_metadata:
@@ -114,7 +118,7 @@ async def native_upload(
114118
file.file_name, # type: ignore
115119
total=file._size,
116120
),
117-
file
121+
file,
118122
)
119123
for file in files_replace
120124
]
@@ -269,11 +273,12 @@ async def _single_native_upload(
269273
)
270274

271275
json_data = _get_json_data(file)
276+
handler = file.get_handler()
272277

273278
files = {
274279
"file": (
275280
file.file_name,
276-
file.handler,
281+
handler,
277282
file.mimeType,
278283
),
279284
"jsonData": (
@@ -374,8 +379,10 @@ async def _update_metadata(
374379
if _tab_extension(dv_path) in file_mapping:
375380
file_id = file_mapping[_tab_extension(dv_path)]
376381
elif (
377-
file.file_name and _is_zip(file.file_name)
378-
and not file._is_inside_zip and not file._enforce_metadata_update
382+
file.file_name
383+
and _is_zip(file.file_name)
384+
and not file._is_inside_zip
385+
and not file._enforce_metadata_update
379386
):
380387
# When the file is a zip package it will be unpacked and thus
381388
# the expected file name of the zip will not be in the

dvuploader/packaging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def zip_files(
9595
with zipfile.ZipFile(path, "w") as zip_file:
9696
for file in files:
9797
zip_file.writestr(
98-
data=file.handler.read(), # type: ignore
98+
data=file.get_handler().read(), # type: ignore
9999
zinfo_or_arcname=_create_arcname(file),
100100
)
101101
file._is_inside_zip = True

0 commit comments

Comments
 (0)