|
11 | 11 | import stone_validators as bv |
12 | 12 | import stone_base as bb |
13 | 13 |
|
| 14 | +class InvalidPathRootError(object): |
| 15 | + """ |
| 16 | + :ivar path_root: The latest path root id for user's team if the user is |
| 17 | + still in a team. |
| 18 | + """ |
| 19 | + |
| 20 | + __slots__ = [ |
| 21 | + '_path_root_value', |
| 22 | + '_path_root_present', |
| 23 | + ] |
| 24 | + |
| 25 | + _has_required_fields = False |
| 26 | + |
| 27 | + def __init__(self, |
| 28 | + path_root=None): |
| 29 | + self._path_root_value = None |
| 30 | + self._path_root_present = False |
| 31 | + if path_root is not None: |
| 32 | + self.path_root = path_root |
| 33 | + |
| 34 | + @property |
| 35 | + def path_root(self): |
| 36 | + """ |
| 37 | + The latest path root id for user's team if the user is still in a team. |
| 38 | +
|
| 39 | + :rtype: str |
| 40 | + """ |
| 41 | + if self._path_root_present: |
| 42 | + return self._path_root_value |
| 43 | + else: |
| 44 | + return None |
| 45 | + |
| 46 | + @path_root.setter |
| 47 | + def path_root(self, val): |
| 48 | + if val is None: |
| 49 | + del self.path_root |
| 50 | + return |
| 51 | + val = self._path_root_validator.validate(val) |
| 52 | + self._path_root_value = val |
| 53 | + self._path_root_present = True |
| 54 | + |
| 55 | + @path_root.deleter |
| 56 | + def path_root(self): |
| 57 | + self._path_root_value = None |
| 58 | + self._path_root_present = False |
| 59 | + |
| 60 | + def __repr__(self): |
| 61 | + return 'InvalidPathRootError(path_root={!r})'.format( |
| 62 | + self._path_root_value, |
| 63 | + ) |
| 64 | + |
| 65 | +InvalidPathRootError_validator = bv.Struct(InvalidPathRootError) |
| 66 | + |
| 67 | +class PathRoot(bb.Union): |
| 68 | + """ |
| 69 | + This class acts as a tagged union. Only one of the ``is_*`` methods will |
| 70 | + return true. To get the associated value of a tag (if one exists), use the |
| 71 | + corresponding ``get_*`` method. |
| 72 | +
|
| 73 | + :ivar home: Paths are relative to the authenticating user's home directory, |
| 74 | + whether or not that user belongs to a team. |
| 75 | + :ivar member_home: Paths are relative to the authenticating team member's |
| 76 | + home directory. (This results in :field:`PathRootError.invalid' if the |
| 77 | + user does not belong to a team.) |
| 78 | + :ivar str team: Paths are relative to the given team directory. (This |
| 79 | + results in :field:`PathRootError.invalid` if the user is not a member of |
| 80 | + the team associated with that path root id.) |
| 81 | + :ivar user_home: Paths are relative to the user's home directory. (This |
| 82 | + results in ``PathRootError.invalid`` if the belongs to a team.) |
| 83 | + :ivar str shared_folder: Paths are relative to given shared folder id (This |
| 84 | + results in :field:`PathRootError.no_permission` if you don't have access |
| 85 | + to this shared folder.) |
| 86 | + """ |
| 87 | + |
| 88 | + _catch_all = 'other' |
| 89 | + # Attribute is overwritten below the class definition |
| 90 | + home = None |
| 91 | + # Attribute is overwritten below the class definition |
| 92 | + member_home = None |
| 93 | + # Attribute is overwritten below the class definition |
| 94 | + user_home = None |
| 95 | + # Attribute is overwritten below the class definition |
| 96 | + other = None |
| 97 | + |
| 98 | + @classmethod |
| 99 | + def team(cls, val): |
| 100 | + """ |
| 101 | + Create an instance of this class set to the ``team`` tag with value |
| 102 | + ``val``. |
| 103 | +
|
| 104 | + :param str val: |
| 105 | + :rtype: PathRoot |
| 106 | + """ |
| 107 | + return cls('team', val) |
| 108 | + |
| 109 | + @classmethod |
| 110 | + def shared_folder(cls, val): |
| 111 | + """ |
| 112 | + Create an instance of this class set to the ``shared_folder`` tag with |
| 113 | + value ``val``. |
| 114 | +
|
| 115 | + :param str val: |
| 116 | + :rtype: PathRoot |
| 117 | + """ |
| 118 | + return cls('shared_folder', val) |
| 119 | + |
| 120 | + def is_home(self): |
| 121 | + """ |
| 122 | + Check if the union tag is ``home``. |
| 123 | +
|
| 124 | + :rtype: bool |
| 125 | + """ |
| 126 | + return self._tag == 'home' |
| 127 | + |
| 128 | + def is_member_home(self): |
| 129 | + """ |
| 130 | + Check if the union tag is ``member_home``. |
| 131 | +
|
| 132 | + :rtype: bool |
| 133 | + """ |
| 134 | + return self._tag == 'member_home' |
| 135 | + |
| 136 | + def is_team(self): |
| 137 | + """ |
| 138 | + Check if the union tag is ``team``. |
| 139 | +
|
| 140 | + :rtype: bool |
| 141 | + """ |
| 142 | + return self._tag == 'team' |
| 143 | + |
| 144 | + def is_user_home(self): |
| 145 | + """ |
| 146 | + Check if the union tag is ``user_home``. |
| 147 | +
|
| 148 | + :rtype: bool |
| 149 | + """ |
| 150 | + return self._tag == 'user_home' |
| 151 | + |
| 152 | + def is_shared_folder(self): |
| 153 | + """ |
| 154 | + Check if the union tag is ``shared_folder``. |
| 155 | +
|
| 156 | + :rtype: bool |
| 157 | + """ |
| 158 | + return self._tag == 'shared_folder' |
| 159 | + |
| 160 | + def is_other(self): |
| 161 | + """ |
| 162 | + Check if the union tag is ``other``. |
| 163 | +
|
| 164 | + :rtype: bool |
| 165 | + """ |
| 166 | + return self._tag == 'other' |
| 167 | + |
| 168 | + def get_team(self): |
| 169 | + """ |
| 170 | + Paths are relative to the given team directory. (This results in |
| 171 | + ``PathRootError.invalid`` if the user is not a member of the team |
| 172 | + associated with that path root id.) |
| 173 | +
|
| 174 | + Only call this if :meth:`is_team` is true. |
| 175 | +
|
| 176 | + :rtype: str |
| 177 | + """ |
| 178 | + if not self.is_team(): |
| 179 | + raise AttributeError("tag 'team' not set") |
| 180 | + return self._value |
| 181 | + |
| 182 | + def get_shared_folder(self): |
| 183 | + """ |
| 184 | + Paths are relative to given shared folder id (This results in |
| 185 | + ``PathRootError.no_permission`` if you don't have access to this shared |
| 186 | + folder.) |
| 187 | +
|
| 188 | + Only call this if :meth:`is_shared_folder` is true. |
| 189 | +
|
| 190 | + :rtype: str |
| 191 | + """ |
| 192 | + if not self.is_shared_folder(): |
| 193 | + raise AttributeError("tag 'shared_folder' not set") |
| 194 | + return self._value |
| 195 | + |
| 196 | + def __repr__(self): |
| 197 | + return 'PathRoot(%r, %r)' % (self._tag, self._value) |
| 198 | + |
| 199 | +PathRoot_validator = bv.Union(PathRoot) |
| 200 | + |
| 201 | +class PathRootError(bb.Union): |
| 202 | + """ |
| 203 | + This class acts as a tagged union. Only one of the ``is_*`` methods will |
| 204 | + return true. To get the associated value of a tag (if one exists), use the |
| 205 | + corresponding ``get_*`` method. |
| 206 | +
|
| 207 | + :ivar InvalidPathRootError invalid: The path root id value in |
| 208 | + Dropbox-API-Path-Root header is no longer valid. |
| 209 | + :ivar no_permission: You don't have permission to access the path root id in |
| 210 | + Dropbox-API-Path-Root header. |
| 211 | + """ |
| 212 | + |
| 213 | + _catch_all = 'other' |
| 214 | + # Attribute is overwritten below the class definition |
| 215 | + no_permission = None |
| 216 | + # Attribute is overwritten below the class definition |
| 217 | + other = None |
| 218 | + |
| 219 | + @classmethod |
| 220 | + def invalid(cls, val): |
| 221 | + """ |
| 222 | + Create an instance of this class set to the ``invalid`` tag with value |
| 223 | + ``val``. |
| 224 | +
|
| 225 | + :param InvalidPathRootError val: |
| 226 | + :rtype: PathRootError |
| 227 | + """ |
| 228 | + return cls('invalid', val) |
| 229 | + |
| 230 | + def is_invalid(self): |
| 231 | + """ |
| 232 | + Check if the union tag is ``invalid``. |
| 233 | +
|
| 234 | + :rtype: bool |
| 235 | + """ |
| 236 | + return self._tag == 'invalid' |
| 237 | + |
| 238 | + def is_no_permission(self): |
| 239 | + """ |
| 240 | + Check if the union tag is ``no_permission``. |
| 241 | +
|
| 242 | + :rtype: bool |
| 243 | + """ |
| 244 | + return self._tag == 'no_permission' |
| 245 | + |
| 246 | + def is_other(self): |
| 247 | + """ |
| 248 | + Check if the union tag is ``other``. |
| 249 | +
|
| 250 | + :rtype: bool |
| 251 | + """ |
| 252 | + return self._tag == 'other' |
| 253 | + |
| 254 | + def get_invalid(self): |
| 255 | + """ |
| 256 | + The path root id value in Dropbox-API-Path-Root header is no longer |
| 257 | + valid. |
| 258 | +
|
| 259 | + Only call this if :meth:`is_invalid` is true. |
| 260 | +
|
| 261 | + :rtype: InvalidPathRootError |
| 262 | + """ |
| 263 | + if not self.is_invalid(): |
| 264 | + raise AttributeError("tag 'invalid' not set") |
| 265 | + return self._value |
| 266 | + |
| 267 | + def __repr__(self): |
| 268 | + return 'PathRootError(%r, %r)' % (self._tag, self._value) |
| 269 | + |
| 270 | +PathRootError_validator = bv.Union(PathRootError) |
| 271 | + |
14 | 272 | Date_validator = bv.Timestamp(u'%Y-%m-%d') |
15 | 273 | DisplayName_validator = bv.String(min_length=1, pattern=u'[^/:?*<>"|]*') |
16 | 274 | DropboxTimestamp_validator = bv.Timestamp(u'%Y-%m-%dT%H:%M:%SZ') |
17 | 275 | EmailAddress_validator = bv.String(max_length=255, pattern=u"^['&A-Za-z0-9._%+-]+@[A-Za-z0-9-][A-Za-z0-9.-]*.[A-Za-z]{2,15}$") |
18 | 276 | NamePart_validator = bv.String(min_length=1, max_length=100, pattern=u'[^/:?*<>"|]*') |
19 | 277 | NamespaceId_validator = bv.String(pattern=u'[-_0-9a-zA-Z:]+') |
| 278 | +PathRootId_validator = NamespaceId_validator |
20 | 279 | SessionId_validator = bv.String() |
21 | 280 | SharedFolderId_validator = NamespaceId_validator |
| 281 | +InvalidPathRootError._path_root_validator = bv.Nullable(PathRootId_validator) |
| 282 | +InvalidPathRootError._all_field_names_ = set(['path_root']) |
| 283 | +InvalidPathRootError._all_fields_ = [('path_root', InvalidPathRootError._path_root_validator)] |
| 284 | + |
| 285 | +PathRoot._home_validator = bv.Void() |
| 286 | +PathRoot._member_home_validator = bv.Void() |
| 287 | +PathRoot._team_validator = PathRootId_validator |
| 288 | +PathRoot._user_home_validator = bv.Void() |
| 289 | +PathRoot._shared_folder_validator = PathRootId_validator |
| 290 | +PathRoot._other_validator = bv.Void() |
| 291 | +PathRoot._tagmap = { |
| 292 | + 'home': PathRoot._home_validator, |
| 293 | + 'member_home': PathRoot._member_home_validator, |
| 294 | + 'team': PathRoot._team_validator, |
| 295 | + 'user_home': PathRoot._user_home_validator, |
| 296 | + 'shared_folder': PathRoot._shared_folder_validator, |
| 297 | + 'other': PathRoot._other_validator, |
| 298 | +} |
| 299 | + |
| 300 | +PathRoot.home = PathRoot('home') |
| 301 | +PathRoot.member_home = PathRoot('member_home') |
| 302 | +PathRoot.user_home = PathRoot('user_home') |
| 303 | +PathRoot.other = PathRoot('other') |
| 304 | + |
| 305 | +PathRootError._invalid_validator = InvalidPathRootError_validator |
| 306 | +PathRootError._no_permission_validator = bv.Void() |
| 307 | +PathRootError._other_validator = bv.Void() |
| 308 | +PathRootError._tagmap = { |
| 309 | + 'invalid': PathRootError._invalid_validator, |
| 310 | + 'no_permission': PathRootError._no_permission_validator, |
| 311 | + 'other': PathRootError._other_validator, |
| 312 | +} |
| 313 | + |
| 314 | +PathRootError.no_permission = PathRootError('no_permission') |
| 315 | +PathRootError.other = PathRootError('other') |
| 316 | + |
22 | 317 | ROUTES = { |
23 | 318 | } |
24 | 319 |
|
0 commit comments