Skip to content

Commit cc17caf

Browse files
DropboxBotBrent Bumann
andauthored
Automated Spec Update (dropbox#396)
28dfbe46c05026fdd867e4fea67cd0ea9acfbca9 Change Notes: file_tagging Namespace - Add BaseTagError unions - Remove BaseError, BaseTagError extends BaseError unions - Update RemoveTagError extends BaseTagError union to remove tag_not_exists_for_this_path - Update RemoveTagError extends BaseTagError union to include tag_not_present - Update Comments Co-authored-by: DropboxBot <DropboxBot@users.noreply.github.com> Co-authored-by: Brent Bumann <bbumann@dropbox.com>
1 parent 0eddf8b commit cc17caf

File tree

2 files changed

+34
-107
lines changed

2 files changed

+34
-107
lines changed

dropbox/files.py

Lines changed: 33 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -50,61 +50,35 @@ def _process_custom_annotations(self, annotation_type, field_path, processor):
5050

5151
AddTagArg_validator = bv.Struct(AddTagArg)
5252

53-
class BaseError(bb.Union):
53+
class BaseTagError(bb.Union):
5454
"""
5555
This class acts as a tagged union. Only one of the ``is_*`` methods will
5656
return true. To get the associated value of a tag (if one exists), use the
5757
corresponding ``get_*`` method.
58-
59-
:ivar files.BaseError.unknown: Action failed.
60-
:ivar files.BaseError.transient: Action failed. Try again.
61-
:ivar files.BaseError.input_validation: Action failed due to wrong params.
62-
:ivar files.BaseError.cancelled: Action cancelled.
6358
"""
6459

6560
_catch_all = 'other'
6661
# Attribute is overwritten below the class definition
67-
unknown = None
68-
# Attribute is overwritten below the class definition
69-
transient = None
70-
# Attribute is overwritten below the class definition
71-
input_validation = None
72-
# Attribute is overwritten below the class definition
73-
cancelled = None
74-
# Attribute is overwritten below the class definition
7562
other = None
7663

77-
def is_unknown(self):
78-
"""
79-
Check if the union tag is ``unknown``.
80-
81-
:rtype: bool
82-
"""
83-
return self._tag == 'unknown'
84-
85-
def is_transient(self):
86-
"""
87-
Check if the union tag is ``transient``.
88-
89-
:rtype: bool
90-
"""
91-
return self._tag == 'transient'
92-
93-
def is_input_validation(self):
64+
@classmethod
65+
def path(cls, val):
9466
"""
95-
Check if the union tag is ``input_validation``.
67+
Create an instance of this class set to the ``path`` tag with value
68+
``val``.
9669
97-
:rtype: bool
70+
:param LookupError val:
71+
:rtype: BaseTagError
9872
"""
99-
return self._tag == 'input_validation'
73+
return cls('path', val)
10074

101-
def is_cancelled(self):
75+
def is_path(self):
10276
"""
103-
Check if the union tag is ``cancelled``.
77+
Check if the union tag is ``path``.
10478
10579
:rtype: bool
10680
"""
107-
return self._tag == 'cancelled'
81+
return self._tag == 'path'
10882

10983
def is_other(self):
11084
"""
@@ -114,42 +88,15 @@ def is_other(self):
11488
"""
11589
return self._tag == 'other'
11690

117-
def _process_custom_annotations(self, annotation_type, field_path, processor):
118-
super(BaseError, self)._process_custom_annotations(annotation_type, field_path, processor)
119-
120-
BaseError_validator = bv.Union(BaseError)
121-
122-
class BaseTagError(BaseError):
123-
"""
124-
This class acts as a tagged union. Only one of the ``is_*`` methods will
125-
return true. To get the associated value of a tag (if one exists), use the
126-
corresponding ``get_*`` method.
127-
128-
:ivar files.BaseTagError.feature_not_supported: Tags are not turned on for
129-
your team. Please turn on the feature.
130-
:ivar files.BaseTagError.path_not_found: Path not found.
131-
"""
132-
133-
# Attribute is overwritten below the class definition
134-
feature_not_supported = None
135-
# Attribute is overwritten below the class definition
136-
path_not_found = None
137-
138-
def is_feature_not_supported(self):
139-
"""
140-
Check if the union tag is ``feature_not_supported``.
141-
142-
:rtype: bool
143-
"""
144-
return self._tag == 'feature_not_supported'
145-
146-
def is_path_not_found(self):
91+
def get_path(self):
14792
"""
148-
Check if the union tag is ``path_not_found``.
93+
Only call this if :meth:`is_path` is true.
14994
150-
:rtype: bool
95+
:rtype: LookupError
15196
"""
152-
return self._tag == 'path_not_found'
97+
if not self.is_path():
98+
raise AttributeError("tag 'path' not set")
99+
return self._value
153100

154101
def _process_custom_annotations(self, annotation_type, field_path, processor):
155102
super(BaseTagError, self)._process_custom_annotations(annotation_type, field_path, processor)
@@ -162,7 +109,8 @@ class AddTagError(BaseTagError):
162109
return true. To get the associated value of a tag (if one exists), use the
163110
corresponding ``get_*`` method.
164111
165-
:ivar files.AddTagError.too_many_tags: Item already has max supported tags.
112+
:ivar files.AddTagError.too_many_tags: The item already has the maximum
113+
supported number of tags.
166114
"""
167115

168116
# Attribute is overwritten below the class definition
@@ -6888,20 +6836,20 @@ class RemoveTagError(BaseTagError):
68886836
return true. To get the associated value of a tag (if one exists), use the
68896837
corresponding ``get_*`` method.
68906838
6891-
:ivar files.RemoveTagError.tag_not_exists_for_this_path: That tag doesn't
6892-
exist at this path.
6839+
:ivar files.RemoveTagError.tag_not_present: That tag doesn't exist at this
6840+
path.
68936841
"""
68946842

68956843
# Attribute is overwritten below the class definition
6896-
tag_not_exists_for_this_path = None
6844+
tag_not_present = None
68976845

6898-
def is_tag_not_exists_for_this_path(self):
6846+
def is_tag_not_present(self):
68996847
"""
6900-
Check if the union tag is ``tag_not_exists_for_this_path``.
6848+
Check if the union tag is ``tag_not_present``.
69016849
69026850
:rtype: bool
69036851
"""
6904-
return self._tag == 'tag_not_exists_for_this_path'
6852+
return self._tag == 'tag_not_present'
69056853

69066854
def _process_custom_annotations(self, annotation_type, field_path, processor):
69076855
super(RemoveTagError, self)._process_custom_annotations(annotation_type, field_path, processor)
@@ -10616,35 +10564,14 @@ def _process_custom_annotations(self, annotation_type, field_path, processor):
1061610564
('tag_text', AddTagArg.tag_text.validator),
1061710565
]
1061810566

10619-
BaseError._unknown_validator = bv.Void()
10620-
BaseError._transient_validator = bv.Void()
10621-
BaseError._input_validation_validator = bv.Void()
10622-
BaseError._cancelled_validator = bv.Void()
10623-
BaseError._other_validator = bv.Void()
10624-
BaseError._tagmap = {
10625-
'unknown': BaseError._unknown_validator,
10626-
'transient': BaseError._transient_validator,
10627-
'input_validation': BaseError._input_validation_validator,
10628-
'cancelled': BaseError._cancelled_validator,
10629-
'other': BaseError._other_validator,
10630-
}
10631-
10632-
BaseError.unknown = BaseError('unknown')
10633-
BaseError.transient = BaseError('transient')
10634-
BaseError.input_validation = BaseError('input_validation')
10635-
BaseError.cancelled = BaseError('cancelled')
10636-
BaseError.other = BaseError('other')
10637-
10638-
BaseTagError._feature_not_supported_validator = bv.Void()
10639-
BaseTagError._path_not_found_validator = bv.Void()
10567+
BaseTagError._path_validator = LookupError_validator
10568+
BaseTagError._other_validator = bv.Void()
1064010569
BaseTagError._tagmap = {
10641-
'feature_not_supported': BaseTagError._feature_not_supported_validator,
10642-
'path_not_found': BaseTagError._path_not_found_validator,
10570+
'path': BaseTagError._path_validator,
10571+
'other': BaseTagError._other_validator,
1064310572
}
10644-
BaseTagError._tagmap.update(BaseError._tagmap)
1064510573

10646-
BaseTagError.feature_not_supported = BaseTagError('feature_not_supported')
10647-
BaseTagError.path_not_found = BaseTagError('path_not_found')
10574+
BaseTagError.other = BaseTagError('other')
1064810575

1064910576
AddTagError._too_many_tags_validator = bv.Void()
1065010577
AddTagError._tagmap = {
@@ -12112,13 +12039,13 @@ def _process_custom_annotations(self, annotation_type, field_path, processor):
1211212039
('tag_text', RemoveTagArg.tag_text.validator),
1211312040
]
1211412041

12115-
RemoveTagError._tag_not_exists_for_this_path_validator = bv.Void()
12042+
RemoveTagError._tag_not_present_validator = bv.Void()
1211612043
RemoveTagError._tagmap = {
12117-
'tag_not_exists_for_this_path': RemoveTagError._tag_not_exists_for_this_path_validator,
12044+
'tag_not_present': RemoveTagError._tag_not_present_validator,
1211812045
}
1211912046
RemoveTagError._tagmap.update(BaseTagError._tagmap)
1212012047

12121-
RemoveTagError.tag_not_exists_for_this_path = RemoveTagError('tag_not_exists_for_this_path')
12048+
RemoveTagError.tag_not_present = RemoveTagError('tag_not_present')
1212212049

1212312050
RestoreArg.path.validator = WritePath_validator
1212412051
RestoreArg.rev.validator = Rev_validator

spec

0 commit comments

Comments
 (0)