Esempio n. 1
0
    def __init__(self, path=None, new=False, autoload=True, autosave=False,
                 encoding="utf-8", return_unicode=PY3,
                 ):
        # set encoding
        if not encoding:
            warn("``encoding=None`` is deprecated as of Passlib 1.6, "
                 "and will cause a ValueError in Passlib 1.8, "
                 "use ``return_unicode=False`` instead.",
                 DeprecationWarning, stacklevel=2)
            encoding = "utf-8"
            return_unicode = False
        elif not is_ascii_codec(encoding):
            # htpasswd/htdigest files assumes 1-byte chars, and use ":" separator,
            # so only ascii-compatible encodings are allowed.
            raise ValueError("encoding must be 7-bit ascii compatible")
        self.encoding = encoding

        # set other attrs
        self.return_unicode = return_unicode
        self.autosave = autosave
        self._path = path
        self._mtime = 0

        # init db
        if not autoload:
            warn("``autoload=False`` is deprecated as of Passlib 1.6, "
                 "and will be removed in Passlib 1.8, use ``new=True`` instead",
                 DeprecationWarning, stacklevel=2)
            new = True
        if path and not new:
            self.load()
        else:
            self._records = OrderedDict()
Esempio n. 2
0
 def safe_summary(self, encoded):
     from django.contrib.auth.hashers import mask_hash
     from django.utils.translation import ugettext_noop as _
     handler = self.passlib_handler
     items = [
         # since this is user-facing, we're reporting passlib's name,
         # without the distracting PASSLIB_HASHER_PREFIX prepended.
         (_('algorithm'), handler.name),
     ]
     if hasattr(handler, "parsehash"):
         kwds = handler.parsehash(encoded, sanitize=mask_hash)
         for key, value in iteritems(kwds):
             key = self._translate_kwds.get(key, key)
             items.append((_(key), value))
     return OrderedDict(items)
Esempio n. 3
0
 def _load_lines(self, lines):
     """load from sequence of lists"""
     # XXX: found reference that "#" comment lines may be supported by
     #      htpasswd, should verify this, and figure out how to handle them.
     #      if true, this would also affect what can be stored in user field.
     # XXX: if multiple entries for a key, should we use the first one
     #      or the last one? going w/ first entry for now.
     # XXX: how should this behave if parsing fails? currently
     #      it will contain everything that was loaded up to error.
     #      could clear / restore old state instead.
     parse = self._parse_record
     records = self._records = OrderedDict()
     for idx, line in enumerate(lines):
         key, value = parse(line, idx+1)
         if key not in records:
             records[key] = value