def _getitem(cls, key): if isinstance(key, tuple): f = cls.aliases[key[0].lower()] if key[0].lower() in cls.aliases else key[0] t = cls.aliases[key[1].lower()] if key[1].lower() in cls.aliases else key[1] with scoped_session() as session: return session.query(cls).filter(and_(cls.from_unit==f, cls.to_unit==t)).one().factor else: raise TypeError('Usage requires syntax Dimension["from_unit", "to_unit"]')
def get_by_symbol(cls, symbol): """Get the value of a constant with the given symbol.""" if symbol.lower() in cls.aliases: symbol = cls.aliases[symbol.lower()] with scoped_session() as session: return session.query(cls).filter(cls.symbol == symbol).one().value