Source code for helios.core.structure

"""Base data structures for the SDK."""


[docs]class RecordCollection: """ Class for handling query records. Attributes: records (list of :class:`Record <helios.core.structure.Record>`): Raw record data for debugging purposes. """ def __init__(self, records=None): self._records = records or [] @property def failed(self): """Records for queries that failed.""" return [x for x in self._records if not x.ok] @property def succeeded(self): """Records for queries that succeeded.""" return [x for x in self._records if x.ok]
[docs]class Record: """ Individual query record. Args: url (str): API URL. parameters (dict): All parameters for current function or method call. content: Returned content. To be defined by method. error (exception): Exception that occurred, if any. """ def __init__(self, url=None, parameters=None, content=None, error=None): self.url = url self._parameters = parameters self.content = content self.error = error @staticmethod def _get_public_params(params): """ Returns parameters dictionary with leading underscore params removed. Non-public parameters in this case contain a leading underscore. Args: params (dict): Parameter dictionary. Returns: dict: Public parameters. """ output = {} for k, v in params.items(): if not k.startswith('_') and not k == 'self': output[k] = v return output @property def ok(self): """ Check if failure occurred. Returns: bool: False if error occurred, and True otherwise. """ if self.error: return False return True @property def parameters(self): """ Function call parameters. Returns: dict: Parameters dictionary. """ return self._get_public_params(self._parameters)
[docs]class ImageRecord(Record): """ Record class for images. Args: name (str): Name of image. filename (str): Full path to image file that was written. """ def __init__(self, name=None, filename=None, **kwargs): super().__init__(**kwargs) self.name = name self.filename = filename @property def image(self): """ Alias for Record content attribute. Returns: PIL.Image.Image: Image data. """ return self.content