async_.py 10.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
# -*- coding: utf-8 -*-
# Auto-generated by Stone, do not modify.
# @generated
# flake8: noqa
# pylint: skip-file
try:
    from . import stone_validators as bv
    from . import stone_base as bb
except (ImportError, SystemError, ValueError):
    # Catch errors raised when importing a relative module when not in a package.
    # This makes testing this file directly (outside of a package) easier.
    import stone_validators as bv
    import stone_base as bb

class LaunchResultBase(bb.Union):
    """
    Result returned by methods that launch an asynchronous job. A method who may
    either launch an asynchronous job, or complete the request synchronously,
    can use this union by extending it, and adding a 'complete' field with the
    type of the synchronous response. See :class:`LaunchEmptyResult` for an
    example.

    This class acts as a tagged union. Only one of the ``is_*`` methods will
    return true. To get the associated value of a tag (if one exists), use the
    corresponding ``get_*`` method.

27 28 29
    :ivar str async.LaunchResultBase.async_job_id: This response indicates that
        the processing is asynchronous. The string is an id that can be used to
        obtain the status of the asynchronous job.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
    """

    _catch_all = None

    @classmethod
    def async_job_id(cls, val):
        """
        Create an instance of this class set to the ``async_job_id`` tag with
        value ``val``.

        :param str val:
        :rtype: LaunchResultBase
        """
        return cls('async_job_id', val)

    def is_async_job_id(self):
        """
        Check if the union tag is ``async_job_id``.

        :rtype: bool
        """
        return self._tag == 'async_job_id'

    def get_async_job_id(self):
        """
        This response indicates that the processing is asynchronous. The string
        is an id that can be used to obtain the status of the asynchronous job.

        Only call this if :meth:`is_async_job_id` is true.

        :rtype: str
        """
        if not self.is_async_job_id():
            raise AttributeError("tag 'async_job_id' not set")
        return self._value

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

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    def __repr__(self):
        return 'LaunchResultBase(%r, %r)' % (self._tag, self._value)

LaunchResultBase_validator = bv.Union(LaunchResultBase)

class LaunchEmptyResult(LaunchResultBase):
    """
    Result returned by methods that may either launch an asynchronous job or
    complete synchronously. Upon synchronous completion of the job, no
    additional information is returned.

    This class acts as a tagged union. Only one of the ``is_*`` methods will
    return true. To get the associated value of a tag (if one exists), use the
    corresponding ``get_*`` method.

84 85
    :ivar async.LaunchEmptyResult.complete: The job finished synchronously and
        successfully.
86 87 88 89 90 91 92 93 94 95 96 97 98
    """

    # Attribute is overwritten below the class definition
    complete = None

    def is_complete(self):
        """
        Check if the union tag is ``complete``.

        :rtype: bool
        """
        return self._tag == 'complete'

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

102 103 104 105 106
    def __repr__(self):
        return 'LaunchEmptyResult(%r, %r)' % (self._tag, self._value)

LaunchEmptyResult_validator = bv.Union(LaunchEmptyResult)

107
class PollArg(bb.Struct):
108 109 110
    """
    Arguments for methods that poll the status of an asynchronous job.

111 112
    :ivar async.PollArg.async_job_id: Id of the asynchronous job. This is the
        value of a response returned from the method that launched the job.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
    """

    __slots__ = [
        '_async_job_id_value',
        '_async_job_id_present',
    ]

    _has_required_fields = True

    def __init__(self,
                 async_job_id=None):
        self._async_job_id_value = None
        self._async_job_id_present = False
        if async_job_id is not None:
            self.async_job_id = async_job_id

    @property
    def async_job_id(self):
        """
        Id of the asynchronous job. This is the value of a response returned
        from the method that launched the job.

        :rtype: str
        """
        if self._async_job_id_present:
            return self._async_job_id_value
        else:
            raise AttributeError("missing required field 'async_job_id'")

    @async_job_id.setter
    def async_job_id(self, val):
        val = self._async_job_id_validator.validate(val)
        self._async_job_id_value = val
        self._async_job_id_present = True

    @async_job_id.deleter
    def async_job_id(self):
        self._async_job_id_value = None
        self._async_job_id_present = False

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

156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
    def __repr__(self):
        return 'PollArg(async_job_id={!r})'.format(
            self._async_job_id_value,
        )

PollArg_validator = bv.Struct(PollArg)

class PollResultBase(bb.Union):
    """
    Result returned by methods that poll for the status of an asynchronous job.
    Unions that extend this union should add a 'complete' field with a type of
    the information returned upon job completion. See :class:`PollEmptyResult`
    for an example.

    This class acts as a tagged union. Only one of the ``is_*`` methods will
    return true. To get the associated value of a tag (if one exists), use the
    corresponding ``get_*`` method.

174 175
    :ivar async.PollResultBase.in_progress: The asynchronous job is still in
        progress.
176 177 178 179 180 181 182 183 184 185 186 187 188 189
    """

    _catch_all = None
    # Attribute is overwritten below the class definition
    in_progress = None

    def is_in_progress(self):
        """
        Check if the union tag is ``in_progress``.

        :rtype: bool
        """
        return self._tag == 'in_progress'

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

193 194 195 196 197 198 199 200 201 202 203 204 205 206
    def __repr__(self):
        return 'PollResultBase(%r, %r)' % (self._tag, self._value)

PollResultBase_validator = bv.Union(PollResultBase)

class PollEmptyResult(PollResultBase):
    """
    Result returned by methods that poll for the status of an asynchronous job.
    Upon completion of the job, no additional information is returned.

    This class acts as a tagged union. Only one of the ``is_*`` methods will
    return true. To get the associated value of a tag (if one exists), use the
    corresponding ``get_*`` method.

207 208
    :ivar async.PollEmptyResult.complete: The asynchronous job has completed
        successfully.
209 210 211 212 213 214 215 216 217 218 219 220 221
    """

    # Attribute is overwritten below the class definition
    complete = None

    def is_complete(self):
        """
        Check if the union tag is ``complete``.

        :rtype: bool
        """
        return self._tag == 'complete'

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

225 226 227 228 229 230 231 232 233 234 235 236 237
    def __repr__(self):
        return 'PollEmptyResult(%r, %r)' % (self._tag, self._value)

PollEmptyResult_validator = bv.Union(PollEmptyResult)

class PollError(bb.Union):
    """
    Error returned by methods for polling the status of asynchronous job.

    This class acts as a tagged union. Only one of the ``is_*`` methods will
    return true. To get the associated value of a tag (if one exists), use the
    corresponding ``get_*`` method.

238 239 240 241
    :ivar async.PollError.invalid_async_job_id: The job ID is invalid.
    :ivar async.PollError.internal_error: Something went wrong with the job on
        Dropbox's end. You'll need to verify that the action you were taking
        succeeded, and if not, try again. This should happen very rarely.
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
    """

    _catch_all = 'other'
    # Attribute is overwritten below the class definition
    invalid_async_job_id = None
    # Attribute is overwritten below the class definition
    internal_error = None
    # Attribute is overwritten below the class definition
    other = None

    def is_invalid_async_job_id(self):
        """
        Check if the union tag is ``invalid_async_job_id``.

        :rtype: bool
        """
        return self._tag == 'invalid_async_job_id'

    def is_internal_error(self):
        """
        Check if the union tag is ``internal_error``.

        :rtype: bool
        """
        return self._tag == 'internal_error'

    def is_other(self):
        """
        Check if the union tag is ``other``.

        :rtype: bool
        """
        return self._tag == 'other'

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

279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
    def __repr__(self):
        return 'PollError(%r, %r)' % (self._tag, self._value)

PollError_validator = bv.Union(PollError)

AsyncJobId_validator = bv.String(min_length=1)
LaunchResultBase._async_job_id_validator = AsyncJobId_validator
LaunchResultBase._tagmap = {
    'async_job_id': LaunchResultBase._async_job_id_validator,
}

LaunchEmptyResult._complete_validator = bv.Void()
LaunchEmptyResult._tagmap = {
    'complete': LaunchEmptyResult._complete_validator,
}
LaunchEmptyResult._tagmap.update(LaunchResultBase._tagmap)

LaunchEmptyResult.complete = LaunchEmptyResult('complete')

PollArg._async_job_id_validator = AsyncJobId_validator
PollArg._all_field_names_ = set(['async_job_id'])
PollArg._all_fields_ = [('async_job_id', PollArg._async_job_id_validator)]

PollResultBase._in_progress_validator = bv.Void()
PollResultBase._tagmap = {
    'in_progress': PollResultBase._in_progress_validator,
}

PollResultBase.in_progress = PollResultBase('in_progress')

PollEmptyResult._complete_validator = bv.Void()
PollEmptyResult._tagmap = {
    'complete': PollEmptyResult._complete_validator,
}
PollEmptyResult._tagmap.update(PollResultBase._tagmap)

PollEmptyResult.complete = PollEmptyResult('complete')

PollError._invalid_async_job_id_validator = bv.Void()
PollError._internal_error_validator = bv.Void()
PollError._other_validator = bv.Void()
PollError._tagmap = {
    'invalid_async_job_id': PollError._invalid_async_job_id_validator,
    'internal_error': PollError._internal_error_validator,
    'other': PollError._other_validator,
}

PollError.invalid_async_job_id = PollError('invalid_async_job_id')
PollError.internal_error = PollError('internal_error')
PollError.other = PollError('other')

ROUTES = {
}