Skip to content

Commit

Permalink
Updated spec
Browse files Browse the repository at this point in the history
  • Loading branch information
starforever committed Jun 13, 2019
1 parent 287bdf7 commit a58eb06
Show file tree
Hide file tree
Showing 21 changed files with 30,000 additions and 18,533 deletions.
2 changes: 1 addition & 1 deletion dropbox/async.py
Expand Up @@ -4,4 +4,4 @@
# flake8: noqa
# pylint: skip-file
# If you have issues importing this module because Python recognizes it as a keyword, use async_ instead.
from async_ import *
from .async_ import *
26 changes: 13 additions & 13 deletions dropbox/async_.py
Expand Up @@ -38,7 +38,7 @@ def async_job_id(cls, val):
value ``val``.
:param str val:
:rtype: async_.LaunchResultBase
:rtype: LaunchResultBase
"""
return cls('async_job_id', val)

Expand All @@ -63,8 +63,8 @@ def get_async_job_id(self):
raise AttributeError("tag 'async_job_id' not set")
return self._value

def _process_custom_annotations(self, annotation_type, processor):
super(LaunchResultBase, self)._process_custom_annotations(annotation_type, processor)
def _process_custom_annotations(self, annotation_type, field_path, processor):
super(LaunchResultBase, self)._process_custom_annotations(annotation_type, field_path, processor)

def __repr__(self):
return 'LaunchResultBase(%r, %r)' % (self._tag, self._value)
Expand Down Expand Up @@ -96,8 +96,8 @@ def is_complete(self):
"""
return self._tag == 'complete'

def _process_custom_annotations(self, annotation_type, processor):
super(LaunchEmptyResult, self)._process_custom_annotations(annotation_type, processor)
def _process_custom_annotations(self, annotation_type, field_path, processor):
super(LaunchEmptyResult, self)._process_custom_annotations(annotation_type, field_path, processor)

def __repr__(self):
return 'LaunchEmptyResult(%r, %r)' % (self._tag, self._value)
Expand Down Expand Up @@ -150,8 +150,8 @@ def async_job_id(self):
self._async_job_id_value = None
self._async_job_id_present = False

def _process_custom_annotations(self, annotation_type, processor):
super(PollArg, self)._process_custom_annotations(annotation_type, processor)
def _process_custom_annotations(self, annotation_type, field_path, processor):
super(PollArg, self)._process_custom_annotations(annotation_type, field_path, processor)

def __repr__(self):
return 'PollArg(async_job_id={!r})'.format(
Expand Down Expand Up @@ -187,8 +187,8 @@ def is_in_progress(self):
"""
return self._tag == 'in_progress'

def _process_custom_annotations(self, annotation_type, processor):
super(PollResultBase, self)._process_custom_annotations(annotation_type, processor)
def _process_custom_annotations(self, annotation_type, field_path, processor):
super(PollResultBase, self)._process_custom_annotations(annotation_type, field_path, processor)

def __repr__(self):
return 'PollResultBase(%r, %r)' % (self._tag, self._value)
Expand Down Expand Up @@ -219,8 +219,8 @@ def is_complete(self):
"""
return self._tag == 'complete'

def _process_custom_annotations(self, annotation_type, processor):
super(PollEmptyResult, self)._process_custom_annotations(annotation_type, processor)
def _process_custom_annotations(self, annotation_type, field_path, processor):
super(PollEmptyResult, self)._process_custom_annotations(annotation_type, field_path, processor)

def __repr__(self):
return 'PollEmptyResult(%r, %r)' % (self._tag, self._value)
Expand Down Expand Up @@ -273,8 +273,8 @@ def is_other(self):
"""
return self._tag == 'other'

def _process_custom_annotations(self, annotation_type, processor):
super(PollError, self)._process_custom_annotations(annotation_type, processor)
def _process_custom_annotations(self, annotation_type, field_path, processor):
super(PollError, self)._process_custom_annotations(annotation_type, field_path, processor)

def __repr__(self):
return 'PollError(%r, %r)' % (self._tag, self._value)
Expand Down
146 changes: 119 additions & 27 deletions dropbox/auth.py
Expand Up @@ -21,9 +21,9 @@ class AccessError(bb.Union):
return true. To get the associated value of a tag (if one exists), use the
corresponding ``get_*`` method.
:ivar InvalidAccountTypeError auth.AccessError.invalid_account_type: Current
:ivar InvalidAccountTypeError AccessError.invalid_account_type: Current
account type cannot access the resource.
:ivar PaperAccessError auth.AccessError.paper_access_denied: Current account
:ivar PaperAccessError AccessError.paper_access_denied: Current account
cannot access Paper.
"""

Expand All @@ -37,8 +37,8 @@ def invalid_account_type(cls, val):
Create an instance of this class set to the ``invalid_account_type`` tag
with value ``val``.
:param auth.InvalidAccountTypeError val:
:rtype: auth.AccessError
:param InvalidAccountTypeError val:
:rtype: AccessError
"""
return cls('invalid_account_type', val)

Expand All @@ -48,8 +48,8 @@ def paper_access_denied(cls, val):
Create an instance of this class set to the ``paper_access_denied`` tag
with value ``val``.
:param auth.PaperAccessError val:
:rtype: auth.AccessError
:param PaperAccessError val:
:rtype: AccessError
"""
return cls('paper_access_denied', val)

Expand Down Expand Up @@ -83,7 +83,7 @@ def get_invalid_account_type(self):
Only call this if :meth:`is_invalid_account_type` is true.
:rtype: auth.InvalidAccountTypeError
:rtype: InvalidAccountTypeError
"""
if not self.is_invalid_account_type():
raise AttributeError("tag 'invalid_account_type' not set")
Expand All @@ -95,14 +95,14 @@ def get_paper_access_denied(self):
Only call this if :meth:`is_paper_access_denied` is true.
:rtype: auth.PaperAccessError
:rtype: PaperAccessError
"""
if not self.is_paper_access_denied():
raise AttributeError("tag 'paper_access_denied' not set")
return self._value

def _process_custom_annotations(self, annotation_type, processor):
super(AccessError, self)._process_custom_annotations(annotation_type, processor)
def _process_custom_annotations(self, annotation_type, field_path, processor):
super(AccessError, self)._process_custom_annotations(annotation_type, field_path, processor)

def __repr__(self):
return 'AccessError(%r, %r)' % (self._tag, self._value)
Expand All @@ -124,6 +124,8 @@ class AuthError(bb.Union):
'Dropbox-API-Select-Admin' is not a Dropbox Business team admin.
:ivar auth.AuthError.user_suspended: The user has been suspended.
:ivar auth.AuthError.expired_access_token: The access token has expired.
:ivar TokenScopeError AuthError.missing_scope: The access token does not
have the required scope to access the route.
"""

_catch_all = 'other'
Expand All @@ -140,6 +142,17 @@ class AuthError(bb.Union):
# Attribute is overwritten below the class definition
other = None

@classmethod
def missing_scope(cls, val):
"""
Create an instance of this class set to the ``missing_scope`` tag with
value ``val``.
:param TokenScopeError val:
:rtype: AuthError
"""
return cls('missing_scope', val)

def is_invalid_access_token(self):
"""
Check if the union tag is ``invalid_access_token``.
Expand Down Expand Up @@ -180,6 +193,14 @@ def is_expired_access_token(self):
"""
return self._tag == 'expired_access_token'

def is_missing_scope(self):
"""
Check if the union tag is ``missing_scope``.
:rtype: bool
"""
return self._tag == 'missing_scope'

def is_other(self):
"""
Check if the union tag is ``other``.
Expand All @@ -188,8 +209,20 @@ def is_other(self):
"""
return self._tag == 'other'

def _process_custom_annotations(self, annotation_type, processor):
super(AuthError, self)._process_custom_annotations(annotation_type, processor)
def get_missing_scope(self):
"""
The access token does not have the required scope to access the route.
Only call this if :meth:`is_missing_scope` is true.
:rtype: TokenScopeError
"""
if not self.is_missing_scope():
raise AttributeError("tag 'missing_scope' not set")
return self._value

def _process_custom_annotations(self, annotation_type, field_path, processor):
super(AuthError, self)._process_custom_annotations(annotation_type, field_path, processor)

def __repr__(self):
return 'AuthError(%r, %r)' % (self._tag, self._value)
Expand Down Expand Up @@ -240,8 +273,8 @@ def is_other(self):
"""
return self._tag == 'other'

def _process_custom_annotations(self, annotation_type, processor):
super(InvalidAccountTypeError, self)._process_custom_annotations(annotation_type, processor)
def _process_custom_annotations(self, annotation_type, field_path, processor):
super(InvalidAccountTypeError, self)._process_custom_annotations(annotation_type, field_path, processor)

def __repr__(self):
return 'InvalidAccountTypeError(%r, %r)' % (self._tag, self._value)
Expand Down Expand Up @@ -291,8 +324,8 @@ def is_other(self):
"""
return self._tag == 'other'

def _process_custom_annotations(self, annotation_type, processor):
super(PaperAccessError, self)._process_custom_annotations(annotation_type, processor)
def _process_custom_annotations(self, annotation_type, field_path, processor):
super(PaperAccessError, self)._process_custom_annotations(annotation_type, field_path, processor)

def __repr__(self):
return 'PaperAccessError(%r, %r)' % (self._tag, self._value)
Expand Down Expand Up @@ -335,7 +368,7 @@ def reason(self):
"""
The reason why the app is being rate limited.
:rtype: auth.RateLimitReason
:rtype: RateLimitReason
"""
if self._reason_present:
return self._reason_value
Expand Down Expand Up @@ -377,8 +410,8 @@ def retry_after(self):
self._retry_after_value = None
self._retry_after_present = False

def _process_custom_annotations(self, annotation_type, processor):
super(RateLimitError, self)._process_custom_annotations(annotation_type, processor)
def _process_custom_annotations(self, annotation_type, field_path, processor):
super(RateLimitError, self)._process_custom_annotations(annotation_type, field_path, processor)

def __repr__(self):
return 'RateLimitError(reason={!r}, retry_after={!r})'.format(
Expand Down Expand Up @@ -432,8 +465,8 @@ def is_other(self):
"""
return self._tag == 'other'

def _process_custom_annotations(self, annotation_type, processor):
super(RateLimitReason, self)._process_custom_annotations(annotation_type, processor)
def _process_custom_annotations(self, annotation_type, field_path, processor):
super(RateLimitReason, self)._process_custom_annotations(annotation_type, field_path, processor)

def __repr__(self):
return 'RateLimitReason(%r, %r)' % (self._tag, self._value)
Expand Down Expand Up @@ -515,8 +548,8 @@ def oauth1_token_secret(self):
self._oauth1_token_secret_value = None
self._oauth1_token_secret_present = False

def _process_custom_annotations(self, annotation_type, processor):
super(TokenFromOAuth1Arg, self)._process_custom_annotations(annotation_type, processor)
def _process_custom_annotations(self, annotation_type, field_path, processor):
super(TokenFromOAuth1Arg, self)._process_custom_annotations(annotation_type, field_path, processor)

def __repr__(self):
return 'TokenFromOAuth1Arg(oauth1_token={!r}, oauth1_token_secret={!r})'.format(
Expand Down Expand Up @@ -570,8 +603,8 @@ def is_other(self):
"""
return self._tag == 'other'

def _process_custom_annotations(self, annotation_type, processor):
super(TokenFromOAuth1Error, self)._process_custom_annotations(annotation_type, processor)
def _process_custom_annotations(self, annotation_type, field_path, processor):
super(TokenFromOAuth1Error, self)._process_custom_annotations(annotation_type, field_path, processor)

def __repr__(self):
return 'TokenFromOAuth1Error(%r, %r)' % (self._tag, self._value)
Expand Down Expand Up @@ -621,8 +654,8 @@ def oauth2_token(self):
self._oauth2_token_value = None
self._oauth2_token_present = False

def _process_custom_annotations(self, annotation_type, processor):
super(TokenFromOAuth1Result, self)._process_custom_annotations(annotation_type, processor)
def _process_custom_annotations(self, annotation_type, field_path, processor):
super(TokenFromOAuth1Result, self)._process_custom_annotations(annotation_type, field_path, processor)

def __repr__(self):
return 'TokenFromOAuth1Result(oauth2_token={!r})'.format(
Expand All @@ -631,6 +664,59 @@ def __repr__(self):

TokenFromOAuth1Result_validator = bv.Struct(TokenFromOAuth1Result)

class TokenScopeError(bb.Struct):
"""
:ivar auth.TokenScopeError.required_scope: The required scope to access the
route.
"""

__slots__ = [
'_required_scope_value',
'_required_scope_present',
]

_has_required_fields = True

def __init__(self,
required_scope=None):
self._required_scope_value = None
self._required_scope_present = False
if required_scope is not None:
self.required_scope = required_scope

@property
def required_scope(self):
"""
The required scope to access the route.
:rtype: str
"""
if self._required_scope_present:
return self._required_scope_value
else:
raise AttributeError("missing required field 'required_scope'")

@required_scope.setter
def required_scope(self, val):
val = self._required_scope_validator.validate(val)
self._required_scope_value = val
self._required_scope_present = True

@required_scope.deleter
def required_scope(self):
self._required_scope_value = None
self._required_scope_present = False

def _process_custom_annotations(self, annotation_type, field_path, processor):
super(TokenScopeError, self)._process_custom_annotations(annotation_type, field_path, processor)

def __repr__(self):
return 'TokenScopeError(required_scope={!r})'.format(
self._required_scope_value,
)

TokenScopeError_validator = bv.Struct(TokenScopeError)

AccessError._invalid_account_type_validator = InvalidAccountTypeError_validator
AccessError._paper_access_denied_validator = PaperAccessError_validator
AccessError._other_validator = bv.Void()
Expand All @@ -647,13 +733,15 @@ def __repr__(self):
AuthError._invalid_select_admin_validator = bv.Void()
AuthError._user_suspended_validator = bv.Void()
AuthError._expired_access_token_validator = bv.Void()
AuthError._missing_scope_validator = TokenScopeError_validator
AuthError._other_validator = bv.Void()
AuthError._tagmap = {
'invalid_access_token': AuthError._invalid_access_token_validator,
'invalid_select_user': AuthError._invalid_select_user_validator,
'invalid_select_admin': AuthError._invalid_select_admin_validator,
'user_suspended': AuthError._user_suspended_validator,
'expired_access_token': AuthError._expired_access_token_validator,
'missing_scope': AuthError._missing_scope_validator,
'other': AuthError._other_validator,
}

Expand Down Expand Up @@ -742,6 +830,10 @@ def __repr__(self):
TokenFromOAuth1Result._all_field_names_ = set(['oauth2_token'])
TokenFromOAuth1Result._all_fields_ = [('oauth2_token', TokenFromOAuth1Result._oauth2_token_validator)]

TokenScopeError._required_scope_validator = bv.String()
TokenScopeError._all_field_names_ = set(['required_scope'])
TokenScopeError._all_fields_ = [('required_scope', TokenScopeError._required_scope_validator)]

token_from_oauth1 = bb.Route(
'token/from_oauth1',
1,
Expand Down

0 comments on commit a58eb06

Please sign in to comment.