-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More aggressively validate ambiguous file paths #62
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import locale | ||
import posixpath | ||
import sys | ||
import warnings | ||
|
||
from cached_property import cached_property | ||
import six | ||
|
@@ -90,6 +91,7 @@ def is_ambiguous(self): | |
"""Returns true if it cannot be determined if the path is a | ||
file or directory | ||
""" | ||
warnings.warn('this function is deprecated and will be removed in stor 2.0') | ||
return not self.endswith('/') and not self.ext | ||
|
||
def _get_parts(self): | ||
|
@@ -286,11 +288,17 @@ def __init__(self, pth, mode='r', encoding=None, **kwargs): | |
use binary mode OR explicitly set an encoding when reading/writing text (because | ||
writers from different computers may store data on OBS in different ways). | ||
Python 3 only. | ||
Raises: | ||
ValueError: if the mode is not valid or the path is ambiguous (see ``stor.copy``) | ||
""" | ||
if mode not in self._VALID_MODES: | ||
raise ValueError('invalid mode for file: %r' % mode) | ||
if six.PY2 and encoding: # pragma: no cover | ||
raise TypeError('encoding not supported in Python 2') | ||
# TODO (jtratner): in stor 2.0 remove this explicit check and the warning | ||
if pth.endswith('/'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you want the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't call to |
||
raise ValueError('file paths may not end with trailing slash') | ||
utils.validate_file_path(pth, _warn=True) | ||
self._path = pth | ||
self.mode = mode | ||
self._kwargs = kwargs | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -688,18 +688,16 @@ def open(self, mode='r', encoding=None, swift_upload_options=None): | |
("r" or "rb") and writing ("w", "wb") | ||
encoding (str): text encoding to use. Defaults to | ||
``locale.getpreferredencoding(False)`` (Python 3 only) | ||
swift_upload_options (dict): DEPRECATED (use `stor.settings.use()` | ||
instead). A dictionary of arguments that will be | ||
passed as keyword args to `SwiftPath.upload` if any writes | ||
occur on the opened resource. | ||
|
||
swift_upload_options (dict): DEPRECATED (use `stor.settings.use()` instead). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Returns: | ||
SwiftFile: The swift object. | ||
|
||
Raises: | ||
SwiftError: A swift client error occurred. | ||
""" | ||
swift_upload_options = swift_upload_options or {} | ||
if swift_upload_options: | ||
warnings.warn('swift_upload_options will be removed in stor 2.0') | ||
return SwiftFile(self, mode=mode, encoding=encoding, **swift_upload_options) | ||
|
||
@_swift_retry(exceptions=(ConditionNotMetError, UnavailableError)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem discussed elsewhere in PR?