Skip to content

Commit

Permalink
fix: url error on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dmyersturnbull committed Nov 5, 2021
1 parent 4df9e48 commit 4414a4c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/test_fancy_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def test_read_write_insecure(self):
bad_type = TypedDfBuilder("a").recommended_only().build()
with pytest.raises(UnsupportedOperationError):
# noinspection HttpUrlsUsage
secure_type.read_file("http://google.com") # nosec
secure_type.read_url("http://google.com") # nosec
secure = secure_type.new_df()
bad = bad_type.new_df()
for fmt in FileFormat:
Expand Down
2 changes: 1 addition & 1 deletion typeddfs/_mixins/_full_io_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _call_read(
) -> pd.DataFrame:
fmt = cls._get_fmt(path)
# noinspection HttpUrlsUsage
if isinstance(path, str) and path.startswith("http://"):
if str(path).startswith("http://"):
raise UnsupportedOperationError("Cannot read from http with .secure() enabled")
cls._check_io_ok(path, fmt)
kwargs = cls._get_read_kwargs(fmt, path)
Expand Down
6 changes: 6 additions & 0 deletions typeddfs/abs_dfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def read_file(
Returns:
An instance of this class
"""
if any((str(path).startswith(x + "://") for x in ["http", "https", "ftp"])):
# just save some pain -- better than a weird error in .resolve()
raise ValueError(f"Cannot read from URL {path}; use read_url instead")
path = Path(path).resolve()
t: DfTyping = cls.get_typing()
if attrs is None:
Expand Down Expand Up @@ -166,6 +169,9 @@ def write_file(
InvalidDfError: If the DataFrame is not valid for this type
ValueError: If the type of a column or index name is non-str
"""
if any((str(path).startswith(x + "://") for x in ["http", "https", "ftp"])):
# just save some pain -- better than a weird error in .resolve()
raise ValueError(f"Cannot write to URL {path}")
path = Path(path).resolve()
t = self.__class__.get_typing()
file_hash = file_hash is True or file_hash is None and t.io.file_hash
Expand Down

0 comments on commit 4414a4c

Please sign in to comment.