def get_extra(self, key, default=None): # TODO SP: in the Django implementation, if the node is not stored, # we can't get an extra. In the SQLA one, because this is simply a # column, we could still return one if it exists. try: return get_attr(self.dbnode.extras, key) except (KeyError, IndexError) as e: if default: return default else: raise AttributeError
def get_attr(self, key, default=_NO_DEFAULT): exception = AttributeError("Attribute '{}' does not exist".format(key)) has_default = default is not _NO_DEFAULT if self._to_be_stored: try: return self._attrs_cache[key] except KeyError: if has_default: return default raise exception else: try: return get_attr(self.dbnode.attributes, key) except (KeyError, IndexError): if has_default: return default else: raise exception
def _get_db_extra(self, key, default=None): try: return get_attr(self.dbnode.extras, key) except (KeyError, AttributeError): raise AttributeError("DbExtra {} does not exist".format(key))
def _get_db_attr(self, key): try: return get_attr(self.dbnode.attributes, key) except (KeyError, IndexError): raise AttributeError("Attribute '{}' does not exist".format(key))
def _get_db_extra(self, key): try: return get_attr(self._extras(), key) except (KeyError, AttributeError): raise AttributeError("DbExtra {} does not exist".format(key))