[Python-modules-commits] [python-dropbox] 01/04: New upstream version 8.7.0

Michael Fladischer fladi at moszumanska.debian.org
Mon Feb 5 09:02:56 UTC 2018


This is an automated email from the git hooks/post-receive script.

fladi pushed a commit to branch debian/master
in repository python-dropbox.

commit fc2a19269d09962d2591ccd8ce2f6fc844a6d387
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date:   Sun Feb 4 14:24:56 2018 +0100

    New upstream version 8.7.0
---
 PKG-INFO                  |  4 +--
 README.rst                |  2 +-
 dropbox.egg-info/PKG-INFO |  4 +--
 dropbox/dropbox.py        | 76 ++++++++++++++++++++++++++++++++++++++++-------
 dropbox/exceptions.py     | 11 +++++++
 test/test_dropbox.py      | 56 ++++++++++++++++++++++++++++++++++
 6 files changed, 138 insertions(+), 15 deletions(-)

diff --git a/PKG-INFO b/PKG-INFO
index 56c6132..6b0341e 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: dropbox
-Version: 8.6.0
+Version: 8.7.0
 Summary: Official Dropbox API Client
 Home-page: http://www.dropbox.com/developers
 Author: Dropbox
@@ -9,7 +9,7 @@ License: MIT License
 Description: Dropbox for Python
         ==================
         
-        .. image:: https://travis-ci.org/dropbox/dropbox-sdk-python.svg?branch=v8.6.0
+        .. image:: https://travis-ci.org/dropbox/dropbox-sdk-python.svg?branch=v8.7.0
             :target: https://travis-ci.org/dropbox/dropbox-sdk-python
         
         .. image:: https://readthedocs.org/projects/dropbox-sdk-python/badge/?version=stable
diff --git a/README.rst b/README.rst
index 2121575..c51fcd0 100644
--- a/README.rst
+++ b/README.rst
@@ -1,7 +1,7 @@
 Dropbox for Python
 ==================
 
-.. image:: https://travis-ci.org/dropbox/dropbox-sdk-python.svg?branch=v8.6.0
+.. image:: https://travis-ci.org/dropbox/dropbox-sdk-python.svg?branch=v8.7.0
     :target: https://travis-ci.org/dropbox/dropbox-sdk-python
 
 .. image:: https://readthedocs.org/projects/dropbox-sdk-python/badge/?version=stable
diff --git a/dropbox.egg-info/PKG-INFO b/dropbox.egg-info/PKG-INFO
index 56c6132..6b0341e 100644
--- a/dropbox.egg-info/PKG-INFO
+++ b/dropbox.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: dropbox
-Version: 8.6.0
+Version: 8.7.0
 Summary: Official Dropbox API Client
 Home-page: http://www.dropbox.com/developers
 Author: Dropbox
@@ -9,7 +9,7 @@ License: MIT License
 Description: Dropbox for Python
         ==================
         
-        .. image:: https://travis-ci.org/dropbox/dropbox-sdk-python.svg?branch=v8.6.0
+        .. image:: https://travis-ci.org/dropbox/dropbox-sdk-python.svg?branch=v8.7.0
             :target: https://travis-ci.org/dropbox/dropbox-sdk-python
         
         .. image:: https://readthedocs.org/projects/dropbox-sdk-python/badge/?version=stable
diff --git a/dropbox/dropbox.py b/dropbox/dropbox.py
index 3e8f745..055d8dd 100644
--- a/dropbox/dropbox.py
+++ b/dropbox/dropbox.py
@@ -6,7 +6,7 @@ __all__ = [
 
 # This should always be 0.0.0 in master. Only update this after tagging
 # before release.
-__version__ = '8.6.0'
+__version__ = '8.7.0'
 
 import contextlib
 import json
@@ -22,6 +22,11 @@ from .auth import (
     AuthError_validator,
     RateLimitError_validator,
 )
+from .common import (
+    PathRoot,
+    PathRoot_validator,
+    PathRootError_validator
+)
 from .base import DropboxBase
 from .base_team import DropboxTeamBase
 from .exceptions import (
@@ -29,6 +34,7 @@ from .exceptions import (
     AuthError,
     BadInputError,
     HttpError,
+    PathRootError,
     InternalServerError,
     RateLimitError,
 )
@@ -42,6 +48,9 @@ from .session import (
     pinned_session,
 )
 
+PATH_ROOT_HEADER = 'Dropbox-API-Path-Root'
+HTTP_STATUS_INVALID_PATH_ROOT = 422
+
 class RouteResult(object):
     """The successful result of a call to a route."""
 
@@ -182,6 +191,35 @@ class _DropboxTransport(object):
 
         self._timeout = timeout
 
+    def clone(
+            self,
+            oauth2_access_token=None,
+            max_retries_on_error=None,
+            max_retries_on_rate_limit=None,
+            user_agent=None,
+            session=None,
+            headers=None,
+            timeout=None):
+        """
+        Creates a new copy of the Dropbox client with the same defaults unless modified by
+        arguments to clone()
+
+        See constructor for original parameter descriptions.
+
+        :return: New instance of Dropbox clent
+        :rtype: Dropbox
+        """
+
+        return self.__class__(
+            oauth2_access_token or self._oauth2_access_token,
+            max_retries_on_error or self._max_retries_on_error,
+            max_retries_on_rate_limit or self._max_retries_on_rate_limit,
+            user_agent or self._user_agent,
+            session or self._session,
+            headers or self._headers,
+            timeout or self._timeout
+        )
+
     def request(self,
                 route,
                 namespace,
@@ -421,6 +459,10 @@ class _DropboxTransport(object):
             err = stone_serializers.json_compat_obj_decode(
                 AuthError_validator, r.json()['error'])
             raise AuthError(request_id, err)
+        elif r.status_code == HTTP_STATUS_INVALID_PATH_ROOT:
+            err = stone_serializers.json_compat_obj_decode(
+                PathRootError_validator, r.json()['error'])
+            raise PathRootError(request_id, err)
         elif r.status_code == 429:
             err = None
             if r.headers.get('content-type') == 'application/json':
@@ -479,6 +521,28 @@ class _DropboxTransport(object):
                 for c in http_resp.iter_content(chunksize):
                     f.write(c)
 
+    def with_path_root(self, path_root):
+        """
+        Creates a clone of the Dropbox instance with the Dropbox-API-Path-Root header
+        as the appropriate serialized instance of PathRoot.
+
+        For more information, see
+        https://www.dropbox.com/developers/reference/namespace-guide#pathrootmodes
+
+        :param PathRoot path_root: instance of PathRoot to serialize into the headers field
+        :return: A :class: `Dropbox`
+        :rtype: Dropbox
+        """
+
+        if not isinstance(path_root, PathRoot):
+            raise ValueError("path_root must be an instance of PathRoot")
+
+        return self.clone(
+            headers={
+                PATH_ROOT_HEADER: stone_serializers.json_encode(PathRoot_validator, path_root)
+            }
+        )
+
 class Dropbox(_DropboxTransport, DropboxBase):
     """
     Use this class to make requests to the Dropbox API using a user's access
@@ -532,12 +596,4 @@ class DropboxTeam(_DropboxTransport, DropboxTeamBase):
 
         new_headers = self._headers.copy() if self._headers else {}
         new_headers[select_header_name] = team_member_id
-        return Dropbox(
-            self._oauth2_access_token,
-            max_retries_on_error=self._max_retries_on_error,
-            max_retries_on_rate_limit=self._max_retries_on_rate_limit,
-            timeout=self._timeout,
-            user_agent=self._raw_user_agent,
-            session=self._session,
-            headers=new_headers,
-        )
+        return self.clone(headers=new_headers)
diff --git a/dropbox/exceptions.py b/dropbox/exceptions.py
index 3dcead5..12ac045 100644
--- a/dropbox/exceptions.py
+++ b/dropbox/exceptions.py
@@ -46,6 +46,17 @@ class HttpError(DropboxException):
             self.status_code, self.body)
 
 
+class PathRootError(HttpError):
+    """Error caused by an invalid path root."""
+
+    def __init__(self, request_id, error=None):
+        super(PathRootError, self).__init__(request_id, 422, None)
+        self.error = error
+
+    def __repr__(self):
+        return 'PathRootError({!r}, {!r})'.format(self.request_id, self.error)
+
+
 class BadInputError(HttpError):
     """Errors due to bad input parameters to an API Operation."""
 
diff --git a/test/test_dropbox.py b/test/test_dropbox.py
index 13ad1c7..a4ed8d1 100644
--- a/test/test_dropbox.py
+++ b/test/test_dropbox.py
@@ -22,15 +22,22 @@ from dropbox import (
     DropboxOAuth2Flow,
     DropboxTeam,
     session,
+    stone_serializers,
 )
+from dropbox.dropbox import PATH_ROOT_HEADER
 from dropbox.exceptions import (
     ApiError,
     AuthError,
     BadInputError,
+    PathRootError,
 )
 from dropbox.files import (
     ListFolderError,
 )
+from dropbox.common import (
+    PathRoot,
+    PathRoot_validator,
+)
 
 def _token_from_env_or_die(env_name='DROPBOX_TOKEN'):
     oauth2_token = os.environ.get(env_name)
@@ -137,5 +144,54 @@ class TestDropbox(unittest.TestCase):
             team_member_id = r.members[0].profile.team_member_id
             dbxt.as_user(team_member_id).files_list_folder('')
 
+    @dbx_from_env
+    def test_with_path_root_constructor(self, dbx):
+        # Verify valid mode types
+        for path_root in (
+            PathRoot.home,
+            PathRoot.root("123"),
+            PathRoot.namespace_id("123"),
+        ):
+            dbx_new = dbx.with_path_root(path_root)
+            self.assertIsNot(dbx_new, dbx)
+
+            expected = stone_serializers.json_encode(PathRoot_validator, path_root)
+            self.assertEqual(dbx_new._headers.get(PATH_ROOT_HEADER), expected)
+
+        # verify invalid mode raises ValueError
+        with self.assertRaises(ValueError):
+            dbx.with_path_root(None)
+
+    @dbx_from_env
+    def test_path_root(self, dbx):
+        root_info = dbx.users_get_current_account().root_info
+        root_ns = root_info.root_namespace_id
+        home_ns = root_info.home_namespace_id
+
+        # verify home mode
+        dbxpr = dbx.with_path_root(PathRoot.home)
+        dbxpr.files_list_folder('')
+
+        # verify root mode
+        dbxpr = dbx.with_path_root(PathRoot.root(root_ns))
+        dbxpr.files_list_folder('')
+
+        # verify namespace_id mode
+        dbxpr = dbx.with_path_root(PathRoot.namespace_id(home_ns))
+        dbxpr.files_list_folder('')
+
+    @dbx_from_env
+    def test_path_root_err(self, dbx):
+        # verify invalid namespace return is_no_permission error
+        dbxpr = dbx.with_path_root(PathRoot.namespace_id("1234567890"))
+        with self.assertRaises(PathRootError) as cm:
+            dbxpr.files_list_folder('')
+        self.assertTrue(cm.exception.error.is_no_permission())
+
+        dbxpr = dbx.with_path_root(PathRoot.root("1234567890"))
+        with self.assertRaises(PathRootError) as cm:
+            dbxpr.files_list_folder('')
+        self.assertTrue(cm.exception.error.is_invalid_root())
+
 if __name__ == '__main__':
     unittest.main()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-dropbox.git



More information about the Python-modules-commits mailing list