Current File : //usr/lib/python2.7/site-packages/passlib/handlers/misc.pyc
�
�;Xc@sdZddlZddlZeje�ZddlmZddlm	Z	m
Z
ddlmZm
Z
mZddljjZdddgZdejjejfd	��YZe
d
�Zd
Zdejjejfd��YZdejfd��YZdS(
s.passlib.handlers.misc - misc generic handlers
i����N(twarn(t
to_native_strtstr_consteq(tunicodetutunicode_or_bytes_typest
unix_disabledt
unix_fallbackt	plaintextcBsPeZdZdZdZed��Zed�Zd�Z	eed��Z
RS(s�This class provides the fallback behavior for unix shadow files, and follows the :ref:`password-hash-api`.

    This class does not implement a hash, but instead provides fallback
    behavior as found in /etc/shadow on most unix variants.
    If used, should be the last scheme in the context.

    * this class will positively identify all hash strings.
    * for security, passwords will always hash to ``!``.
    * it rejects all passwords if the hash is NOT an empty string (``!`` or ``*`` are frequently used).
    * by default it rejects all passwords if the hash is an empty string,
      but if ``enable_wildcard=True`` is passed to verify(),
      all passwords will be allowed through if the hash is an empty string.

    .. deprecated:: 1.6
        This has been deprecated due to its "wildcard" feature,
        and will be removed in Passlib 1.8. Use :class:`unix_disabled` instead.
    Rtenable_wildcardcCs,t|t�rtStjj|d��dS(Nthash(t
isinstanceRtTruetuhtexctExpectedStringError(tclsR
((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pytidentify.scKs0tdt�tt|�j|�||_dS(Nsf'unix_fallback' is deprecated, and will be removed in Passlib 1.8; please use 'unix_disabled' instead.(RtDeprecationWarningtsuperRt__init__R	(tselfR	tkwds((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyR5scCs|jr|jStd�SdS(Nt!(tchecksumR(Rtsecret((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyt_calc_checksum=s	cCsFtj|�t|t�s4tjj|d��n|r>tS|SdS(NR
(R
tvalidate_secretRRRRtFalse(RRR
R	((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pytverifyEs
(senable_wildcard(t__name__t
__module__t__doc__tnametcontext_kwdstclassmethodRRRRR(((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyRs	s*!cBs�eZdZdZdZdZeee��Z	de
jkrNed�Z
ned�Z
edd��Zed��Zed��Zed	��Zejd
ddd
�edd���Zedd��Zed��ZRS(sThis class provides disabled password behavior for unix shadow files,
    and follows the :ref:`password-hash-api`.

    This class does not implement a hash, but instead matches the "disabled account"
    strings found in ``/etc/shadow`` on most Unix variants. "encrypting" a password
    will simply return the disabled account marker. It will reject all passwords,
    no matter the hash string. The :meth:`~passlib.ifc.PasswordHash.hash`
    method supports one optional keyword:

    :type marker: str
    :param marker:
        Optional marker string which overrides the platform default
        used to indicate a disabled account.

        If not specified, this will default to ``"*"`` on BSD systems,
        and use the Linux default ``"!"`` for all other platforms.
        (:attr:`!unix_disabled.default_marker` will contain the default value)

    .. versionadded:: 1.6
        This class was added as a replacement for the now-deprecated
        :class:`unix_fallback` class, which had some undesirable features.
    Rtmarkertbsdt*RcKsVtt|�j|�}|dk	rR|j|�sFtd|��n||_n|S(Nsinvalid marker: %r(RRtusingtNoneRt
ValueErrortdefault_marker(RR$Rtsubcls((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyR'xscCsZt|t�rt}n-t|t�r0t}ntjj|d��|pY|d|kS(NR
i(RRt
_MARKER_CHARStbytest
_MARKER_BYTESR
RR(RR
tstart((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyR�s		cCs5tj|�|j|�s1tjj|��ntS(N(R
RRRtInvalidHashErrorR(RRR
((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyR�s
cKsm|r,tj||�|j|�j|�Stj|�|j}|rW|j|�s]t�t|dd�S(NtparamR$(	R
twarn_hash_settings_deprecationR'R
RR*RtAssertionErrorR(RRRR$((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyR
�s
	t
deprecateds1.7tremoveds2.0cCsy|j|�s$tjj|��nQ|rGtj|�t|dd�S|dk	rh|jd|�}n|j|�SdS(NR1tconfigR$(	RR
RR0RRR(R'R
(RRR6R$((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pytgenhash�s
cCsh|jd�}|dk	rdt|dd�}|j|�rN|j|�}n|rd||7}qdn|S(NtR1R
(R
R(RRtenable(RR
tout((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pytdisable�scCstt|dd�}xI|jD]>}|j|�r|t|�}|rK|Std��qqWtjj|��dS(NR1R
scannot restore original hash(Rt_disable_prefixest
startswithtlenR)R
RR0(RR
tprefixtorig((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyR9�s(smarker(N(RRR R!tsetting_kwdsR"ttupletstrR,R<tsystplatformRR*R#R(R'RRR
R
tdeprecated_methodR7R;R9(((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyRRs&
cBs�eZdZdZd
ZdZdZed��Zedd��Z
edd��Zej
ddd	d
�ed���Zej
ddd	d
�edd���ZRS(s~This class stores passwords in plaintext, and follows the :ref:`password-hash-api`.

    The :meth:`~passlib.ifc.PasswordHash.hash`, :meth:`~passlib.ifc.PasswordHash.genhash`, and :meth:`~passlib.ifc.PasswordHash.verify` methods all require the
    following additional contextual keyword:

    :type encoding: str
    :param encoding:
        This controls the character encoding to use (defaults to ``utf-8``).

        This encoding will be used to encode :class:`!unicode` passwords
        under Python 2, and decode :class:`!bytes` hashes under Python 3.

    .. versionchanged:: 1.6
        The ``encoding`` keyword was added.
    Rtencodingsutf-8cCs,t|t�rtStjj|d��dS(NR
(RRRR
RR(RR
((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyR�scCs/tj|�|s|j}nt||d�S(NR(R
Rtdefault_encodingR(RRRG((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyR
�s
cCsa|s|j}nt||d�}|j|�sHtjj|��nt|j||�|�S(NR
(RHRRR
RR0RR
(RRR
RG((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyR�sR4s1.7R5s2.0cCs
|jd�S(NR8(R
(R((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyt	genconfig�scCs7|j|�s$tjj|��n|j|d|�S(NRG(RR
RR0R
(RRR6RG((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyR7s((sencodingN(RRR R!RAR"RHR#RR(R
RR
RFRIR7(((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyR�s(R RDtloggingt	getLoggerRtlogtwarningsRt
passlib.utilsRRtpasslib.utils.compatRRRtpasslib.utils.handlerstutilsthandlersR
t__all__tifctDisabledHasht
StaticHandlerRR,R.tMinimalHandlerRR(((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyt<module>s	"6"~