Skip to content

Commit a589a1c

Browse files
Return normalized file paths from file utility helper
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 0861230 commit a589a1c

3 files changed

Lines changed: 18 additions & 14 deletions

File tree

hyperbrowser/client/file_utils.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import os
2+
from os import PathLike
3+
from typing import Union
24

35
from hyperbrowser.exceptions import HyperbrowserError
46

57

68
def ensure_existing_file_path(
7-
file_path: str,
9+
file_path: Union[str, PathLike[str]],
810
*,
911
missing_file_message: str,
1012
not_file_message: str,
11-
) -> None:
12-
if not os.path.exists(file_path):
13+
) -> str:
14+
normalized_path = os.fspath(file_path)
15+
if not os.path.exists(normalized_path):
1316
raise HyperbrowserError(missing_file_message)
14-
if not os.path.isfile(file_path):
17+
if not os.path.isfile(normalized_path):
1518
raise HyperbrowserError(not_file_message)
19+
return normalized_path

hyperbrowser/client/managers/async_manager/session.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ async def upload_file(
115115
self, id: str, file_input: Union[str, PathLike[str], IO]
116116
) -> UploadFileResponse:
117117
if isinstance(file_input, (str, PathLike)):
118-
file_path = os.fspath(file_input)
119-
ensure_existing_file_path(
120-
file_path,
121-
missing_file_message=f"Upload file not found at path: {file_path}",
122-
not_file_message=f"Upload file path must point to a file: {file_path}",
118+
raw_file_path = os.fspath(file_input)
119+
file_path = ensure_existing_file_path(
120+
raw_file_path,
121+
missing_file_message=f"Upload file not found at path: {raw_file_path}",
122+
not_file_message=f"Upload file path must point to a file: {raw_file_path}",
123123
)
124124
try:
125125
with open(file_path, "rb") as file_obj:

hyperbrowser/client/managers/sync_manager/session.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ def upload_file(
107107
self, id: str, file_input: Union[str, PathLike[str], IO]
108108
) -> UploadFileResponse:
109109
if isinstance(file_input, (str, PathLike)):
110-
file_path = os.fspath(file_input)
111-
ensure_existing_file_path(
112-
file_path,
113-
missing_file_message=f"Upload file not found at path: {file_path}",
114-
not_file_message=f"Upload file path must point to a file: {file_path}",
110+
raw_file_path = os.fspath(file_input)
111+
file_path = ensure_existing_file_path(
112+
raw_file_path,
113+
missing_file_message=f"Upload file not found at path: {raw_file_path}",
114+
not_file_message=f"Upload file path must point to a file: {raw_file_path}",
115115
)
116116
try:
117117
with open(file_path, "rb") as file_obj:

0 commit comments

Comments
 (0)