Mutable
is a class within the sqlalchemy.ext.mutable
module of the SQLAlchemy project.
sqlalchemy-utils (project documentation and PyPI package information) is a code library with various helper functions and new data types that make it easier to use SQLAlchemy when building projects that involve more specific storage requirements such as currency. The wide array of data types includes ranged values and aggregated attributes.
sqlalchemy-utils / sqlalchemy_utils / types / password.py
# password.py
import weakref
import six
from sqlalchemy import types
from sqlalchemy.dialects import oracle, postgresql, sqlite
from sqlalchemy.ext.mutable import Mutable
from ..exceptions import ImproperlyConfigured
from .scalar_coercible import ScalarCoercible
passlib = None
try:
import passlib
from passlib.context import LazyCryptContext
except ImportError:
pass
class Password(Mutable, object):
@classmethod
def coerce(cls, key, value):
if isinstance(value, Password):
return value
if isinstance(value, (six.string_types, six.binary_type)):
return cls(value, secret=True)
super(Password, cls).coerce(key, value)
def __init__(self, value, context=None, secret=False):
self.hash = value if not secret else None
self.secret = value if secret else None
if isinstance(self.hash, six.text_type):
self.hash = self.hash.encode('utf8')
self.context = weakref.proxy(context) if context is not None else None
def __eq__(self, value):
if self.hash is None or value is None:
return self.hash is value
## ... source file continues with no further Mutable examples...