Skip to content

Commit

Permalink
Fix a TypeError in get_public_* functions when passing 'path' paramet…
Browse files Browse the repository at this point in the history
…er (see issue #7)
  • Loading branch information
ivknv committed Mar 26, 2019
1 parent a7808d7 commit 2117a01
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 133 deletions.
Binary file modified docs/locales/ru/LC_MESSAGES/docs.mo
Binary file not shown.
282 changes: 167 additions & 115 deletions docs/locales/ru/LC_MESSAGES/docs.po

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions tests/resources_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,11 @@ def test_patch(self):

self.yadisk.patch(path, {"test_property": None})
self.assertIsNone(self.yadisk.get_meta(path).custom_properties)

def test_issue7(self):
# See https://github.com/ivknv/yadisk/issues/7

try:
self.yadisk.public_listdir("any value here", path="any value here")
except yadisk.exceptions.PathNotFoundError:
pass
12 changes: 10 additions & 2 deletions yadisk/api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,9 @@ class GetPublicMetaRequest(APIRequest):
:param session: an instance of :any:`requests.Session` with prepared headers
:param public_key: public key or public URL of the resource
:param path: relative path to a resource in a public folder.
By specifying the key of the published folder in `public_key`,
you can request metainformation for any resource in the folder.
:param offset: offset from the beginning of the list of nested resources
:param limit: maximum number of nested elements to be included in the list
:param sort: `str`, field to be used as a key to sort children resources
Expand Down Expand Up @@ -671,6 +674,7 @@ class GetPublicDownloadLinkRequest(APIRequest):
:param session: an instance of :any:`requests.Session` with prepared headers
:param public_key: public key or public URL of the resource
:param path: relative path to the resource within the public folder
:param fields: list of keys to be included in the response
:returns: :any:`LinkObject`
Expand All @@ -679,13 +683,17 @@ class GetPublicDownloadLinkRequest(APIRequest):
url = "https://cloud-api.yandex.net/v1/disk/public/resources/download"
method = "GET"

def __init__(self, session, public_key, fields=None, **kwargs):
def __init__(self, session, public_key, path=None, fields=None, **kwargs):
APIRequest.__init__(self, session, {"public_key": public_key,
"path": path,
"fields": fields}, **kwargs)

def process_args(self, public_key, fields):
def process_args(self, public_key, path, fields):
self.params["public_key"] = public_key

if path is not None:
self.params["path"] = path;

if fields is not None:
self.params["fields"] = ",".join(fields)

Expand Down
46 changes: 30 additions & 16 deletions yadisk/functions/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ def is_file(session, path, **kwargs):
except PathNotFoundError:
return False

def _listdir(get_meta_function, session, path, **kwargs):
def _listdir(get_meta_function, session, path, kwargs):
# kwargs is passed this way to avoid a TypeError sometimes (see issue https://github.com/ivknv/yadisk/issues/7)
kwargs = dict(kwargs)
kwargs.setdefault("limit", 10000)

Expand Down Expand Up @@ -341,7 +342,7 @@ def listdir(session, path, **kwargs):
:returns: generator of :any:`ResourceObject`
"""

return _listdir(get_meta, session, path, **kwargs)
return _listdir(get_meta, session, path, kwargs) # NOT A TYPO!

def mkdir(session, path, **kwargs):
"""
Expand Down Expand Up @@ -626,7 +627,7 @@ def save_to_disk(session, public_key, **kwargs):
or a link to the resource otherwise.
:param session: an instance of :any:`requests.Session` with prepared headers
:param public_key: public key or public URL of the resource
:param public_key: public key or public URL of the public resource
:param name: filename of the saved resource
:param path: path to the copied resource in the public folder
:param save_path: path to the destination directory (downloads directory by default)
Expand All @@ -650,7 +651,10 @@ def get_public_meta(session, public_key, **kwargs):
Get meta-information about a public resource.
:param session: an instance of :any:`requests.Session` with prepared headers
:param public_key: public key or public URL of the resource
:param public_key: public key or public URL of the public resource
:param path: relative path to a resource in a public folder.
By specifying the key of the published folder in `public_key`,
you can request metainformation for any resource in the folder.
:param offset: offset from the beginning of the list of nested resources
:param limit: maximum number of nested elements to be included in the list
:param sort: `str`, field to be used as a key to sort children resources
Expand All @@ -675,7 +679,8 @@ def public_exists(session, public_key, **kwargs):
Check whether the public resource exists.
:param session: an instance of :any:`requests.Session` with prepared headers
:param public_key: public key or public URL of the resource
:param public_key: public key or public URL of the public resource
:param path: relative path to the resource within the public folder
:param timeout: `float` or `tuple`, request timeout
:param headers: `dict` or `None`, additional request headers
:param n_retries: `int`, maximum number of retries
Expand All @@ -691,7 +696,10 @@ def public_listdir(session, public_key, **kwargs):
Get contents of a public directory.
:param session: an instance of :any:`requests.Session` with prepared headers
:param public_key: public key or public URL of the resource
:param public_key: public key or public URL of the public resource
:param path: relative path to the resource in the public folder.
By specifying the key of the published folder in `public_key`,
you can request contents of any nested folder.
:param limit: number of children resources to be included in the response
:param offset: number of children resources to be skipped in the response
:param preview_size: size of the file preview
Expand All @@ -705,14 +713,15 @@ def public_listdir(session, public_key, **kwargs):
:returns: generator of :any:`PublicResourceObject`
"""

return _listdir(get_public_meta, session, public_key, **kwargs)
return _listdir(get_public_meta, session, public_key, kwargs) # NOT A TYPO!

def get_public_type(session, public_key, **kwargs):
"""
Get public resource type.
:param session: an instance of :any:`requests.Session` with prepared headers
:param public_key: public key or public URL of the resource
:param public_key: public key or public URL of the public resource
:param path: relative path to the resource within the public folder
:param timeout: `float` or `tuple`, request timeout
:param headers: `dict` or `None`, additional request headers
:param n_retries: `int`, maximum number of retries
Expand All @@ -725,10 +734,11 @@ def get_public_type(session, public_key, **kwargs):

def is_public_dir(session, public_key, **kwargs):
"""
Check whether `public_key` is a public directory.
Check whether the public resource is a public directory.
:param session: an instance of :any:`requests.Session` with prepared headers
:param public_key: public key or public URL of the resource
:param public_key: public key or public URL of the public resource
:param path: relative path to the resource within the public folder
:param timeout: `float` or `tuple`, request timeout
:param headers: `dict` or `None`, additional request headers
:param n_retries: `int`, maximum number of retries
Expand All @@ -744,10 +754,11 @@ def is_public_dir(session, public_key, **kwargs):

def is_public_file(session, public_key, **kwargs):
"""
Check whether `public_key` is a public file.
Check whether the public resource is a public file.
:param session: an instance of :any:`requests.Session` with prepared headers
:param public_key: public key or public URL of the resource
:param public_key: public key or public URL of the public resource
:param path: relative path to the resource within the public folder
:param timeout: `float` or `tuple`, request timeout
:param headers: `dict` or `None`, additional request headers
:param n_retries: `int`, maximum number of retries
Expand Down Expand Up @@ -780,7 +791,7 @@ def trash_listdir(session, path, **kwargs):
:returns: generator of :any:`TrashResourceObject`
"""

return _listdir(get_trash_meta, session, path, **kwargs)
return _listdir(get_trash_meta, session, path, kwargs) # NOT A TYPO!

def get_trash_type(session, path, **kwargs):
"""
Expand Down Expand Up @@ -977,7 +988,8 @@ def get_public_download_link(session, public_key, **kwargs):
Get a download link for a public resource.
:param session: an instance of :any:`requests.Session` with prepared headers
:param public_key: public key or public URL of the resource
:param public_key: public key or public URL of the public resource
:param path: relative path to the resource within the public folder
:param fields: list of keys to be included in the response
:param timeout: `float` or `tuple`, request timeout
:param headers: `dict` or `None`, additional request headers
Expand All @@ -997,8 +1009,9 @@ def download_public(session, public_key, file_or_path, **kwargs):
Download the public resource.
:param session: an instance of :any:`requests.Session` with prepared headers
:param public_key: public key or public URL of the resource
:param path_or_file: destination path or file-like object
:param public_key: public key or public URL of the public resource
:param file_or_path: destination path or file-like object
:param path: relative path to the resource within the public folder
:param timeout: `float` or `tuple`, request timeout
:param headers: `dict` or `None`, additional request headers
:param n_retries: `int`, maximum number of retries
Expand Down Expand Up @@ -1037,6 +1050,7 @@ def attempt():

temp_kwargs.pop("n_retries", None)
temp_kwargs.pop("retry_interval", None)
temp_kwargs.pop("path", None)

try:
timeout = temp_kwargs["timeout"]
Expand Down
12 changes: 12 additions & 0 deletions yadisk/yadisk.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,9 @@ def get_public_meta(self, public_key, **kwargs):
Get meta-information about a public resource.
:param public_key: public key or public URL of the resource
:param path: relative path to a resource in a public folder.
By specifying the key of the published folder in `public_key`,
you can request metainformation for any resource in the folder.
:param offset: offset from the beginning of the list of nested resources
:param limit: maximum number of nested elements to be included in the list
:param sort: `str`, field to be used as a key to sort children resources
Expand All @@ -618,6 +621,7 @@ def public_exists(self, public_key, **kwargs):
Check whether the public resource exists.
:param public_key: public key or public URL of the resource
:param path: relative path to the resource within the public folder
:param timeout: `float` or `tuple`, request timeout
:param headers: `dict` or `None`, additional request headers
:param n_retries: `int`, maximum number of retries
Expand All @@ -633,6 +637,9 @@ def public_listdir(self, public_key, **kwargs):
Get contents of a public directory.
:param public_key: public key or public URL of the resource
:param path: relative path to the resource in the public folder.
By specifying the key of the published folder in `public_key`,
you can request contents of any nested folder.
:param limit: number of children resources to be included in the response
:param offset: number of children resources to be skipped in the response
:param preview_size: size of the file preview
Expand All @@ -653,6 +660,7 @@ def get_public_type(self, public_key, **kwargs):
Get public resource type.
:param public_key: public key or public URL of the resource
:param path: relative path to the resource within the public folder
:param timeout: `float` or `tuple`, request timeout
:param headers: `dict` or `None`, additional request headers
:param n_retries: `int`, maximum number of retries
Expand All @@ -668,6 +676,7 @@ def is_public_dir(self, public_key, **kwargs):
Check whether `public_key` is a public directory.
:param public_key: public key or public URL of the resource
:param path: relative path to the resource within the public folder
:param timeout: `float` or `tuple`, request timeout
:param headers: `dict` or `None`, additional request headers
:param n_retries: `int`, maximum number of retries
Expand All @@ -683,6 +692,7 @@ def is_public_file(self, public_key, **kwargs):
Check whether `public_key` is a public file.
:param public_key: public key or public URL of the resource
:param path: relative path to the resource within the public folder
:param timeout: `float` or `tuple`, request timeout
:param headers: `dict` or `None`, additional request headers
:param n_retries: `int`, maximum number of retries
Expand Down Expand Up @@ -858,6 +868,7 @@ def get_public_download_link(self, public_key, **kwargs):
Get a download link for a public resource.
:param public_key: public key or public URL of the resource
:param path: relative path to the resource within the public folder
:param fields: list of keys to be included in the response
:param timeout: `float` or `tuple`, request timeout
:param headers: `dict` or `None`, additional request headers
Expand All @@ -876,6 +887,7 @@ def download_public(self, public_key, file_or_path, **kwargs):
:param public_key: public key or public URL of the resource
:param file_or_path: destination path or file-like object
:param path: relative path to the resource within the public folder
:param timeout: `float` or `tuple`, request timeout
:param headers: `dict` or `None`, additional request headers
:param n_retries: `int`, maximum number of retries
Expand Down

0 comments on commit 2117a01

Please sign in to comment.