"""Generic project-wide utilities.""" import datetime import strict_rfc3339 class DotDict(dict): """Simple wrapper around dict to access its items using dot notation.""" def __getattr__(self, item): """Get item from dictionary by it's key, using dot-notation. Args: item (str): a dictionary key. Returns: value, or None if there is no item with such key. """ return self.get(item) def __setattr__(self, key, value): """Set value in dictionary, using dot-notation. Args: key (str): item key value: item value """ self[key] = value def to_datetime(date): """Convert RFC 3339 date string to UTC datetime instance. Args: date (string): RFC 3339 date string with offset. Returns: datetime.datetime: UTC datetime object. """ timestamp = strict_rfc3339.rfc3339_to_timestamp(date) return datetime.datetime.utcfromtimestamp(timestamp)