AnonSec Shell
Server IP : 85.193.89.191  /  Your IP : 3.23.92.143
Web Server : Apache
System : Linux 956367-cx40159.tmweb.ru 3.10.0-1160.105.1.el7.x86_64 #1 SMP Thu Dec 7 15:39:45 UTC 2023 x86_64
User : bitrix ( 600)
PHP Version : 8.1.27
Disable Function : NONE
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python2.7/site-packages/passlib/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /lib/python2.7/site-packages/passlib//context.pyc
�
j^�Xc@�s)dZddlmZddlZddlZeje�ZddlZddl	Z	ddl
mZddlm
Z
mZmZddlmZmZddlmZmZmZmZmZmZmZmZddlmZdd	lm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*dd
l+m,Z,m-Z-ddd
gZ.e/�Z0d�Z1e2dg�Z3e4de5de5de5de1de5�Z6d�Z7e8e9d��Z:e2ddg�Z;dZ<d
e/fd��YZ=de/fd��YZ>de/fd��YZ?de?fd��YZ@dS(s-passlib.context - CryptContext implementationi����(twith_statementN(twarn(tExpectedStringErrortExpectedTypeErrortPasslibConfigWarning(tget_crypt_handlert_validate_handler_name(thandlerstto_bytest
to_unicodet
splitcommatas_boolttimertrngt
getrandstr(tBASE64_CHARS(t	iteritemst	num_typestirangetPY2tPY3tunicodetSafeConfigParsertNativeStringIOtBytesIOtunicode_or_bytes_typestnative_string_types(tdeprecated_methodtmemoized_propertytCryptContexttLazyCryptContexttCryptPolicycC�sS|jd�r&t|jd��dSyt|�SWntk
rNt|�SXdS(s>parse vary_rounds string to percent as [0,1) float, or integert%g{�G�z�?N(tendswithtfloattrstriptintt
ValueError(tvalue((s3/usr/lib/python2.7/site-packages/passlib/context.pyt_coerce_vary_rounds)s
tsaltt
min_roundst
max_roundstdefault_roundstvary_roundst	salt_sizecC�st|jd�|kS(s3detect if handler is registered or a custom handlerN(RtnametNone(thandler((s3/usr/lib/python2.7/site-packages/passlib/context.pyt_is_handler_registeredBscC�stS(s
    dummy function patched into handler.needs_update() by _CryptConfig
    when hash alg has been deprecated for context.
    (tTrue(thashtsecret((s3/usr/lib/python2.7/site-packages/passlib/context.pyt_always_needs_updateFsttruncate_errorsaThe CryptPolicy class has been deprecated as of Passlib 1.6, and will be removed in Passlib 1.8. cB�seZdZeddd��Zeddd��Zeed��Zeed��Zd�Z	dZeZ
d�Zd	�Zd
�Zed�Zdded�Zdd
�Zdd�Zdd�Zeed�Zed�Zdd�Zddd�ZRS(s
    .. deprecated:: 1.6
        This class has been deprecated, and will be removed in Passlib 1.8.
        All of its functionality has been rolled into :class:`CryptContext`.

    This class previously stored the configuration options for the
    CryptContext class. In the interest of interface simplification,
    all of this class' functionality has been rolled into the CryptContext
    class itself.
    The documentation for this class is now focused on  documenting how to
    migrate to the new api. Additionally, where possible, the deprecation
    warnings issued by the CryptPolicy methods will list the replacement call
    that should be used.

    Constructors
    ============
    CryptPolicy objects can be constructed directly using any of
    the keywords accepted by :class:`CryptContext`. Direct uses of the
    :class:`!CryptPolicy` constructor should either pass the keywords
    directly into the CryptContext constructor, or to :meth:`CryptContext.update`
    if the policy object was being used to update an existing context object.

    In addition to passing in keywords directly,
    CryptPolicy objects can be constructed by the following methods:

    .. automethod:: from_path
    .. automethod:: from_string
    .. automethod:: from_source
    .. automethod:: from_sources
    .. automethod:: replace

    Introspection
    =============
    All of the informational methods provided by this class have been deprecated
    by identical or similar methods in the :class:`CryptContext` class:

    .. automethod:: has_schemes
    .. automethod:: schemes
    .. automethod:: iter_handlers
    .. automethod:: get_handler
    .. automethod:: get_options
    .. automethod:: handler_is_deprecated
    .. automethod:: get_min_verify_time

    Exporting
    =========
    .. automethod:: iter_config
    .. automethod:: to_dict
    .. automethod:: to_file
    .. automethod:: to_string

    .. note::
        CryptPolicy are immutable.
        Use the :meth:`replace` method to mutate existing instances.

    .. deprecated:: 1.6
    tpasslibsutf-8cC�s3ttdtdd�|dtj|||��S(sWcreate a CryptPolicy instance from a local file.

        .. deprecated:: 1.6

        Creating a new CryptContext from a file, which was previously done via
        ``CryptContext(policy=CryptPolicy.from_path(path))``, can now be
        done via ``CryptContext.from_path(path)``.
        See :meth:`CryptContext.from_path` for details.

        Updating an existing CryptContext from a file, which was previously done
        ``context.policy = CryptPolicy.from_path(path)``, can now be
        done via ``context.load_path(path)``.
        See :meth:`CryptContext.load_path` for details.
        s�Instead of ``CryptPolicy.from_path(path)``, use ``CryptContext.from_path(path)``  or ``context.load_path(path)`` for an existing CryptContext.t
stacklevelit_internal_context(Rt	_preambletDeprecationWarningRt	from_path(tclstpathtsectiontencoding((s3/usr/lib/python2.7/site-packages/passlib/context.pyR<�s

cC�s3ttdtdd�|dtj|||��S(sUcreate a CryptPolicy instance from a string.

        .. deprecated:: 1.6

        Creating a new CryptContext from a string, which was previously done via
        ``CryptContext(policy=CryptPolicy.from_string(data))``, can now be
        done via ``CryptContext.from_string(data)``.
        See :meth:`CryptContext.from_string` for details.

        Updating an existing CryptContext from a string, which was previously done
        ``context.policy = CryptPolicy.from_string(data)``, can now be
        done via ``context.load(data)``.
        See :meth:`CryptContext.load` for details.
        s�Instead of ``CryptPolicy.from_string(source)``, use ``CryptContext.from_string(source)`` or ``context.load(source)`` for an existing CryptContext.R8iR9(RR:R;Rtfrom_string(R=tsourceR?R@((s3/usr/lib/python2.7/site-packages/passlib/context.pyRA�s

c�s�|r ttdtdd�nt�t�r3�St�t�rU|dt���St�ttf�s�t	dt
��f��nXt�fd�dD��s��jd�r�|dtj
���S|dtj���Sd	S(
s�create a CryptPolicy instance from some source.

        this method autodetects the source type, and invokes
        the appropriate constructor automatically. it attempts
        to detect whether the source is a configuration string, a filepath,
        a dictionary, or an existing CryptPolicy instance.

        .. deprecated:: 1.6

        Create a new CryptContext, which could previously be done via
        ``CryptContext(policy=CryptPolicy.from_source(source))``, should
        now be done using an explicit method: the :class:`CryptContext`
        constructor itself, :meth:`CryptContext.from_path`,
        or :meth:`CryptContext.from_string`.

        Updating an existing CryptContext, which could previously be done via
        ``context.policy = CryptPolicy.from_source(source)``, should
        now be done using an explicit method: :meth:`CryptContext.update`,
        or :meth:`CryptContext.load`.
        s�Instead of ``CryptPolicy.from_source()``, use ``CryptContext.from_string(path)``  or ``CryptContext.from_path(source)``, as appropriate.R8iR9sAsource must be CryptPolicy, dict, config string, or file path: %rc3�s|]}|�kVqdS(N((t.0tc(RB(s3/usr/lib/python2.7/site-packages/passlib/context.pys	<genexpr>�ss

	s 	./\;:N(RR:R;t
isinstanceRtdictRtbytesRt	TypeErrorttypetanytstripRAR<(R=RBt_warn((RBs3/usr/lib/python2.7/site-packages/passlib/context.pytfrom_source�s,cC�s�|r ttdtdd�nt|�dkrAtd��nt|�dkrj|j|ddt�Si}x9|D]1}|j|j|dt�jj	dt
��qwW|d	t|��S(
s�create a CryptPolicy instance by merging multiple sources.

        each source is interpreted as by :meth:`from_source`,
        and the results are merged together.

        .. deprecated:: 1.6
            Instead of using this method to merge multiple policies together,
            a :class:`CryptContext` instance should be created, and then
            the multiple sources merged together via :meth:`CryptContext.load`.
        swInstead of ``CryptPolicy.from_sources()``, use the various CryptContext constructors  followed by ``context.update()``.R8iisno sources specifiediRLtresolveR9(RR:R;tlenR%RMtFalsetupdatet_contexttto_dictR2R(R=tsourcesRLtkwdsRB((s3/usr/lib/python2.7/site-packages/passlib/context.pytfrom_sources�s
/cO�s�|jr#ttdtdd�nttdtdd�|g}|rY|j|�n|ro|j|�ntj|dt�S(s�create a new CryptPolicy, optionally updating parts of the
        existing configuration.

        .. deprecated:: 1.6
            Callers of this method should :meth:`CryptContext.update` or
            :meth:`CryptContext.copy` instead.
        sXInstead of ``context.policy.replace()``, use ``context.update()`` or ``context.copy()``.R8iszInstead of ``CryptPolicy().replace()``, create a CryptContext instance and use ``context.update()`` or ``context.copy()``.RL(	t_stub_policyRR:R;textendtappendRRVRP(tselftargsRURT((s3/usr/lib/python2.7/site-packages/passlib/context.pytreplaces	
	cO�s�|jdd�}|rqt|t�s-t�||_|jdt�|_|pT|s�td||f��no|r�t|�dkr�t	d��n|r�t	d��n|d}nt
tdtd	d
�t|�|_dS(NR9RWsunexpected args: %r %ris%only one positional argument accepteds&cannot specify positional arg and kwdsis�Instead of constructing a CryptPolicy instance, create a CryptContext directly, or use ``context.update()`` and ``context.load()`` to reconfigure existing CryptContext instances.R8i(
tpopR/RERtAssertionErrorRRRPRWRORHRR:R;(RZR[RUtcontext((s3/usr/lib/python2.7/site-packages/passlib/context.pyt__init__0s 	&

cC�sM|jr#ttdtdd�nttdtdd�t|jj��S(s�return True if policy defines *any* schemes for use.

        .. deprecated:: 1.6
            applications should use ``bool(context.schemes())`` instead.
            see :meth:`CryptContext.schemes`.
        sMInstead of ``context.policy.has_schemes()``, use ``bool(context.schemes())``.R8isoInstead of ``CryptPolicy().has_schemes()``, create a CryptContext instance and use ``bool(context.schemes())``.(RWRR:R;tboolRRtschemes(RZ((s3/usr/lib/python2.7/site-packages/passlib/context.pythas_schemesIs	
cC�sS|jr#ttdtdd�nttdtdd�|jjdtdt�S(s�return iterator over handlers defined in policy.

        .. deprecated:: 1.6
            applications should use ``context.schemes(resolve=True))`` instead.
            see :meth:`CryptContext.schemes`.
        sUInstead of ``context.policy.iter_handlers()``, use ``context.schemes(resolve=True)``.R8iswInstead of ``CryptPolicy().iter_handlers()``, create a CryptContext instance and use ``context.schemes(resolve=True)``.RNtunconfigured(RWRR:R;RRRbR2(RZ((s3/usr/lib/python2.7/site-packages/passlib/context.pyt
iter_handlers]s	
cC�sY|jr#ttdtdd�nttdtdd�t|jjd|dt��S(s�return list of schemes defined in policy.

        .. deprecated:: 1.6
            applications should use :meth:`CryptContext.schemes` instead.
        sCInstead of ``context.policy.schemes()``, use ``context.schemes()``.R8iseInstead of ``CryptPolicy().schemes()``, create a CryptContext instance and use ``context.schemes()``.RNRd(RWRR:R;tlistRRRbR2(RZRN((s3/usr/lib/python2.7/site-packages/passlib/context.pyRbqs	
cC�s|jr#ttdtdd�nttdtdd�y|jj||dt�SWn!tk
rz|rs�q{dSnXdS(s8return handler as specified by name, or default handler.

        .. deprecated:: 1.6
            applications should use :meth:`CryptContext.handler` instead,
            though note that the ``required`` keyword has been removed,
            and the new method will always act as if ``required=True``.
        sGInstead of ``context.policy.get_handler()``, use ``context.handler()``.R8isiInstead of ``CryptPolicy().get_handler()``, create a CryptContext instance and use ``context.handler()``.RdN(	RWRR:R;RRR0R2tKeyErrorR/(RZR.tcategorytrequired((s3/usr/lib/python2.7/site-packages/passlib/context.pytget_handler�s	

cC�stdtdd�dS(srget min_verify_time setting for policy.

        .. deprecated:: 1.6
            min_verify_time option will be removed entirely in passlib 1.8

        .. versionchanged:: 1.7
            this method now always returns the value automatically
            calculated by :meth:`CryptContext.min_verify_time`,
            any value specified by policy is ignored.
        snget_min_verify_time() and min_verify_time option is deprecated and ignored, and will be removed in Passlib 1.8R8ii(RR;(RZRh((s3/usr/lib/python2.7/site-packages/passlib/context.pytget_min_verify_time�scC�so|jr#ttdtdd�nttdtdd�t|d�rU|j}n|jjj||�dS(sLreturn dictionary of options specific to a given handler.

        .. deprecated:: 1.6
            this method has no direct replacement in the 1.6 api, as there
            is not a clearly defined use-case. however, examining the output of
            :meth:`CryptContext.to_dict` should serve as the closest alternative.
        s=``context.policy.get_options()`` will no longer be available.R8is<``CryptPolicy().get_options()`` will no longer be available.R.i(	RWRR:R;thasattrR.RRt_configt_get_record_options_with_flag(RZR.Rh((s3/usr/lib/python2.7/site-packages/passlib/context.pytget_options�s		
cC�sk|jr#ttdtdd�nttdtdd�t|d�rU|j}n|jj||�jS(sBcheck if handler has been deprecated by policy.

        .. deprecated:: 1.6
            this method has no direct replacement in the 1.6 api, as there
            is not a clearly defined use-case. however, examining the output of
            :meth:`CryptContext.to_dict` should serve as the closest alternative.
        sG``context.policy.handler_is_deprecated()`` will no longer be available.R8isF``CryptPolicy().handler_is_deprecated()`` will no longer be available.R.(	RWRR:R;RlR.RRR0t
deprecated(RZR.Rh((s3/usr/lib/python2.7/site-packages/passlib/context.pythandler_is_deprecated�s		
c�s�|jr#ttdtdd�nttdtdd�|j�|rj�fd��d��t}n�j�d����fd��jj|�D�S(	s�iterate over key/value pairs representing the policy object.

        .. deprecated:: 1.6
            applications should use :meth:`CryptContext.to_dict` instead.
        sOInstead of ``context.policy.iter_config()``, use ``context.to_dict().items()``.R8isqInstead of ``CryptPolicy().iter_config()``, create a CryptContext instance and use ``context.to_dict().items()``.c�s�j|�jdd�S(Nt__t.(t_render_config_keyR\(tkey(R_(s3/usr/lib/python2.7/site-packages/passlib/context.pyt
render_key�scS�s+t|ttf�r'dj|�}n|S(Ns, (RERfttupletjoin(R&((s3/usr/lib/python2.7/site-packages/passlib/context.pytrender_value�scS�s|S(N((R&((s3/usr/lib/python2.7/site-packages/passlib/context.pyt<lambda>�sc3�s-|]#\}}�|��|�fVqdS(N((RCRuR&(RvRy(s3/usr/lib/python2.7/site-packages/passlib/context.pys	<genexpr>�s(	RWRR:R;RRRPRtRmtiter_config(RZtiniRN((R_RvRys3/usr/lib/python2.7/site-packages/passlib/context.pyR{�s 	
					cC�sJ|jr#ttdtdd�nttdtdd�|jj|�S(s�export policy object as dictionary of options.

        .. deprecated:: 1.6
            applications should use :meth:`CryptContext.to_dict` instead.
        sCInstead of ``context.policy.to_dict()``, use ``context.to_dict()``.R8iseInstead of ``CryptPolicy().to_dict()``, create a CryptContext instance and use ``context.to_dict()``.(RWRR:R;RRRS(RZRN((s3/usr/lib/python2.7/site-packages/passlib/context.pyRSs	
cC�sx|jr#ttdtdd�nttdtdd�|jjd|�}trg|jd�}n|j|�dS(s�export policy to file.

        .. deprecated:: 1.6
            applications should use :meth:`CryptContext.to_string` instead,
            and then write the output to a file as desired.
        sYInstead of ``context.policy.to_file(stream)``, use ``stream.write(context.to_string())``.R8is{Instead of ``CryptPolicy().to_file(stream)``, create a CryptContext instance and use ``stream.write(context.to_string())``.R?sutf-8N(	RWRR:R;RRt	to_stringRtencodetwrite(RZtstreamR?tout((s3/usr/lib/python2.7/site-packages/passlib/context.pytto_files	
cC�sk|jr#ttdtdd�nttdtdd�|jjd|�}|rg|j|�}n|S(s�export policy to file.

        .. deprecated:: 1.6
            applications should use :meth:`CryptContext.to_string` instead.
        sGInstead of ``context.policy.to_string()``, use ``context.to_string()``.R8isiInstead of ``CryptPolicy().to_string()``, create a CryptContext instance and use ``context.to_string()``.R?(RWRR:R;RRR}R~(RZR?R@R�((s3/usr/lib/python2.7/site-packages/passlib/context.pyR}-s	
N(t__name__t
__module__t__doc__tclassmethodR<RAR2RMRVR\R/RRRPRWR`RcReRbRjRkRoRqR{RSR�R}(((s3/usr/lib/python2.7/site-packages/passlib/context.pyRWs09'	 			$t_CryptConfigcB�s1eZdZdZdZdZdZdZdZ	dZ
dZdZd�Z
d�Zd�Zd�Zd�Zid�Zd�Zid�Zd	�Zed
��Zd�Zd�Zd
�Zd�Zd�Zeded��Zd�Zd�Z dd�Z!e"d�Z#e$d��Z%ed�Z&RS(sparses, validates, and stores CryptContext config

    this is a helper used internally by CryptContext to handle
    parsing, validation, and serialization of its config options.
    split out from the main class, but not made public since
    that just complicates interface too much (c.f. CryptPolicy)

    :arg source: config as dict mapping ``(cat,scheme,option) -> value``
    cC�s;|j|jd��|j|�|j�|j�dS(NRb(NNsschemes(t_init_scheme_listtgetR/t
_init_optionst_init_default_schemest
_init_records(RZRB((s3/usr/lib/python2.7/site-packages/passlib/context.pyR`ys

cC�sg}g}t|t�r*t|�}nx�|p6dD]�}t|d�rh|}|j}t|�n=t|t�r�t|�}|j}ntdt|���||kr�t	d|f��n|j
|�|j
|�q7Wt|�|_t|�|_
dS(s,initialize .handlers and .schemes attributesR.s+scheme must be name or CryptHandler, not %rs$multiple handlers with same name: %rN((RERR
RlR.RRRHRIRgRYRwRRb(RZtdataRRbtelemR0tscheme((s3/usr/lib/python2.7/site-packages/passlib/context.pyR�s*	

c	C�s|j}|j}i|_}i|_}t�}x�t|�D]�\\}}}	}
|j|�|}|r�|r�|	tkr�d}n|rm||	|
�\}	}
|dkr�|	tkr�td|	ft	�n|dkr�tdt
�ny||}Wn)tk
r,ii|
|	6|6||<q�Xy||}
Wn"tk
r_i|
|	6||<q�X|
|
|	<qB|r�|	dkr�td��n|||	|
�\}	}
|	dkr�qBny||	}Wn"tk
r�i|
|6||	<qBX|
||<qBW|jd�tt|��|_dS(sYload config dict into internal representation,
        and init .categories attr
        talls}The '%s' option should be configured per-algorithm, and not set globally in the context; This will be an error in Passlib 2.0s�The 'all' scheme is deprecated as of Passlib 1.7, and will be removed in Passlib 2.0; Please configure options on a per-algorithm basis.Rbs4'schemes' context option is not allowed per categorytmin_verify_timeN(t_norm_scheme_optiont_norm_context_optiont_scheme_optionst_context_optionstsetRtaddt_global_settingsRRR;RgtdiscardR/Rwtsortedt
categories(RZRBtnorm_scheme_optiontnorm_context_optiontscheme_optionstcontext_optionsR�tcatR�RuR&texplicit_schemetcategory_mapt
option_map((s3/usr/lib/python2.7/site-packages/passlib/context.pyR��sN		

	"
	





cC�sb|tkr"td|f��nt|t�rXtj|�}|rX||�}qXn||fS(Ns3%r option not allowed in CryptContext configuration(t_forbidden_scheme_optionsRgRERt_coerce_scheme_optionsR�(RZRuR&tfunc((s3/usr/lib/python2.7/site-packages/passlib/context.pyR��scC�s�|j}|dkrxt|d�r0|j}n$t|t�sTt|dd��n|r�||kr�td��q�nA|dkr_t|t�r�t|�}n*t|tt	f�s�t|dd��nd|kr�t
|�dkr\td	��q\q�|r�xW|D]L}t|t�s3t|dd
��n||kr	td|f��q	q	Wq�nZ|dkr{td
t
�n>|dkr�tdt
�n"|dkr�td|f��n||fS(NtdefaultR.tstrs"default scheme not found in policyRps
str or seqtautois<cannot list other schemes if ``deprecated=['auto']`` is usedsdeprecated elements)deprecated scheme not found in policy: %rR�s^'min_verify_time' was deprecated in Passlib 1.6, is ignored in 1.7, and will be removed in 1.8t
harden_verifysX'harden_verify' is deprecated & ignored as of Passlib 1.7.1,  and will be removed in 1.8Rbs unknown CryptContext keyword: %r(RbRlR.RERRRgR
RfRwROR%RR;(RZR�RuR&RbR�((s3/usr/lib/python2.7/site-packages/passlib/context.pyR��s@	


cC�s|jj||�S(sreturn dict mapping category->value for specific context option.

        .. warning:: treat return value as readonly!
        (R�R�(RZRut_default((s3/usr/lib/python2.7/site-packages/passlib/context.pytget_context_optionmap%scC�s�y|j|}Wntk
r+dtfSX|jd�}|r�y||}Wntk
rbq�X|dks{||kr�|tfSn|tfS(s�return value of specific option, handling category inheritance.
        also returns flag indicating whether value is category-specific.
        N(R�RgR/RPR�R2(RZRhRuR�R&talt((s3/usr/lib/python2.7/site-packages/passlib/context.pytget_context_option_with_flag,s


cC�s,y|j||SWntk
r'|SXdS(ssreturn all options for (scheme,category) combination

        .. warning:: treat return value as readonly!
        N(R�Rg(RZR�RhR�((s3/usr/lib/python2.7/site-packages/passlib/context.pyt_get_scheme_optionmapBs
cC�s|j|jj|�S(N(RRbtindex(RZR�((s3/usr/lib/python2.7/site-packages/passlib/context.pytget_base_handlerLscC�s/|j}d|jkr+|tjj7}n|S(Ntrounds(tsetting_kwdstuht	HasRoundstusing_rounds_kwds(R0R�((s3/usr/lib/python2.7/site-packages/passlib/context.pytexpand_settingsOs	c
C�s1|j}|dd�j�}t}|rO|j�}|j|d|��n|j|j|��}x*t|�j|�D]}|j	|�q}W|r�x-t|�j|�D]}|j	|�q�Wn||d�}	|j|	�|r'|j|	�|j|||��||kr't
}q'n||fS(s�return composite dict of all options set for scheme.
        includes options inherited from 'all' and from default category.
        result can be modified.
        returns (kwds, has_cat_specific_options)
        R�N(R�R/tcopyRPRQR�R�R�t
differenceR]R2(
RZR�Rht
get_optionmapRUthas_cat_optionstdefkwdstallowed_settingsRutother((s3/usr/lib/python2.7/site-packages/passlib/context.pytget_scheme_options_with_flagXs(	

cC�s_|j}|d�j�}|_|d�}|j}|sAdS|jd�pSd}|jd�}|s�xR|D] }||krr||d<PqrqrWtd��n||kr�td��nx�|jD]�}|j||�}	|j||�}
|
s8xZ|D] }||	kr|||<PqqWtd|��q�|
|	kr�td|��q�q�WdS(	s�initialize maps containing default scheme for each category.

        have to do this after _init_options(), since the default scheme
        is affected by the list of deprecated schemes.
        R�RpNs,must have at least one non-deprecated schemes#default scheme cannot be deprecateds<must have at least one non-deprecated scheme for %r categorys3default scheme for %r category cannot be deprecated((R�R�t_default_schemesRbR�R/R%R�(RZR�tdefault_maptdep_mapRbtdepsR�R�R�tcdepstcdefault((s3/usr/lib/python2.7/site-packages/passlib/context.pyR��s:		




cC�sI|j}y||SWntk
r(nX|jsAtd��n|dS(s+return default scheme for specific categorys9no hash schemes configured for this CryptContext instanceN(R�RgRbR/(RZRhtdefaults((s3/usr/lib/python2.7/site-packages/passlib/context.pytdefault_scheme�s	
	c�sw�jd�����fd�}|d�p3t}|rm||�}|dk	rm||krm|tfSn|tfS(s/is scheme deprecated under particular category?Rpc�sX�j|�jd��}|dkr+dSd|krJ��j|�kS�|kSdS(NR�(R�R/R�(R�RB(tdepmapR�RZ(s3/usr/lib/python2.7/site-packages/passlib/context.pyttest�sN(R�R/RPR2(RZR�RhR�R&R�((R�R�RZs3/usr/lib/python2.7/site-packages/passlib/context.pytis_deprecated_with_flag�s
c
C�s�i|_i}|_t�}|_|j}d|j}x�|jD]y}|j}|j	|j�xW|D]O}|||�\}}	|dks�|	rl|j
|||�|||f<qlqlWqFWdS(N(N(t
_record_listst_recordsR�tcontext_kwdsRnR/R�RR.RQt_create_record(
RZtrecordstall_context_kwdsRoR�R0R�R�RUR�((s3/usr/lib/python2.7/site-packages/passlib/context.pyR��s	
	
	
cK�s�y|jdt|�}Wnttk
r�}tjdt|��}|r�|jd�|kr�|jd�}td|j|f��n�nX||k	s�t	d��||_
||_|S(Ntrelaxeds&.* unexpected keyword argument '(.*)'$is'keyword not supported by %s handler: %rs"expected unique variant of handler(tusingR2RHtretmatchR�tgroupRgR.R^t_Context__orig_handlerRp(R0RhRptsettingstsubclsterrtmRu((s3/usr/lib/python2.7/site-packages/passlib/context.pyR��s		cC�s\|j||�\}}|j||�\}}|rCt|d<n|rRt}n||fS(s�return composite dict of options for given scheme + category.

        this is currently a private method, though some variant
        of its output may eventually be made public.

        given a scheme & category, it returns two things:
        a set of all the keyword options to pass to :meth:`_create_record`,
        and a bool flag indicating whether any of these options
        were specific to the named category. if this flag is false,
        the options are identical to the options for the default category.

        the options dict includes all the scheme-specific settings,
        as well as optional *deprecated* keyword.
        Rp(R�R�R2(RZR�RhRUR�R&t
not_inherited((s3/usr/lib/python2.7/site-packages/passlib/context.pyRn�s
	cC�sdy|j||fSWntk
r(nX|dk	r�t|t�r�trst|t�rs|j||jd��St	|dd��n|dk	r�t|t�r�t	|dd��n|s|j
|�}|s�t�|j||�}|jd|f<|S|rMy/|j}||df}|||f<|SWqMtk
rIqMXntd|f��dS(s5return record for specific scheme & category (cached)sutf-8sstr or NoneRhR�s'crypt algorithm not found in policy: %rN(R�RgR/RERRRt
get_recordR~RR�R^(RZR�RhR�trecordtcache((s3/usr/lib/python2.7/site-packages/passlib/context.pyR�s0
		
cC�sZy|j|SWntk
r"nXg|jD]}|j||�^q-}|j|<|S(sxreturn list of records for category (cached)

        this is an internal helper used only by identify_record()
        (R�RgRbR�(RZRhR�R&((s3/usr/lib/python2.7/site-packages/passlib/context.pyt_get_record_listCs
0cC�s�t|t�s!t|d��nx*|j|�D]}|j|�r1|Sq1W|sXdS|jsptd��ntd��dS(s?internal helper to identify appropriate custom handler for hashR3sno crypt algorithms supportedshash could not be identifiedN(	RERRR�tidentifyR/RbRgR%(RZR3RhRiR�((s3/usr/lib/python2.7/site-packages/passlib/context.pytidentify_recordUs	cC�s7x$|jd�D]}|jr|SqWtd��dS(NsLno disabled hasher present (perhaps add 'unix_disabled' to list of schemes?)(R�R/tis_disabledtRuntimeError(RZR�((s3/usr/lib/python2.7/site-packages/passlib/context.pytdisabled_recordms	cc�sc|j}|j}t|�}t|�}d|krF|jd�n|rU|jn|j}|rxdt|�fVnx�d|jD]�}xf|D]^}y|||}Wnt	k
r�q�Xt
|t�r�t|�}n|d|f|fVq�Wxc|D][}	y||	|}
Wnt	k
r'q�Xx,t|
�D]}||	|f|
|fVq5Wq�Wq�WdS(s�regenerate original config.

        this is an iterator which yields ``(cat,scheme,option),value`` items,
        in the order they generally appear inside an INI file.
        if interpreted as a dictionary, it should match the original
        keywords passed to the CryptContext (aside from any canonization).

        it's mainly used as the internal backend for most of the public
        serialization methods.
        RbN(NNsschemes(N(R�R�R�tremoveRRbR/RfR�RgRE(RZRNR�R�tscheme_keystcontext_keysR&R�RuR�RU((s3/usr/lib/python2.7/site-packages/passlib/context.pyR{xs2		



N('R�R�R�R/R�R�RRbR�R�R�R�R�R`R�R�R�R�R�R�R�R�tstaticmethodR�R�R�R�R�R�RPR�RnR�R�R2R�RR�R{(((s3/usr/lib/python2.7/site-packages/passlib/context.pyR�JsB			&	I		+	
			+	+					+cB�seZdZd>Zd>Zd>Zed��Zeddd��Z	eddd��Z
d�Zd�Zd�Z
d>eed	�Zd
�Zd�Zd�Zeeed
d�Zed��Zeddd�Zeddd�Zed��Zd�Zed>ed�Zd>eed�Zd>d>ed�Zd�Z ed��Z!ed��Z"ed��Z#ed�Z$d�Z%dd�Z&dZ'dZ(d Z)d!Z*d>Z+d"Z,d#�Z-d>d>d$�Z.d%�Z/d>d>d>d&�Z0e1d'd(d)d*d+d,�d>d>d-��Z2e1d'd.d)d*�d>d>d/��Z3e1d'd.d)d*�d>d>d0��Z4d>eeed1�Z5d>d>d2�Z6e1d'd.d)d*d+d3�d4��Z7d>d>d5�Z8d>d>d6�Z9d7Z:e;d8��Z<d9�Z=d"d:�Z>d;�Z?d>d<�Z@d=�ZARS(?s-Helper for hashing & verifying passwords using multiple algorithms.

    Instances of this class allow applications to choose a specific
    set of hash algorithms which they wish to support, set limits and defaults
    for the rounds and salt sizes those algorithms should use, flag
    which algorithms should be deprecated, and automatically handle
    migrating users to stronger hashes when they log in.

    Basic usage::

        >>> ctx = CryptContext(schemes=[...])

    See the Passlib online documentation for details and full documentation.
    cC�sJt|t�r||�St||�r,|S|�}|j|�|SdS(s2internal helper - accepts string, dict, or contextN(RERFtload(R=RBRZ((s3/usr/lib/python2.7/site-packages/passlib/context.pyt_norm_source�s
	
R7sutf-8cC�sPt|t�s$t|dd��n|dt�}|j|d|d|�|S(s�create new CryptContext instance from an INI-formatted string.

        :type source: unicode or bytes
        :arg source:
            string containing INI-formatted content.

        :type section: str
        :param section:
            option name of section to read from, defaults to ``"passlib"``.

        :type encoding: str
        :arg encoding:
            optional encoding used when source is bytes, defaults to ``"utf-8"``.

        :returns:
            new :class:`CryptContext` instance, configured based on the
            parameters in the *source* string.

        Usage example::

            >>> from passlib.context import CryptContext
            >>> context = CryptContext.from_string('''
            ... [passlib]
            ... schemes = sha256_crypt, des_crypt
            ... sha256_crypt__default_rounds = 30000
            ... ''')

        .. versionadded:: 1.6

        .. seealso:: :meth:`to_string`, the inverse of this constructor.
        sunicode or bytesRBt	_autoloadR?R@(RERRRPR�(R=RBR?R@RZ((s3/usr/lib/python2.7/site-packages/passlib/context.pyRA�s
!cC�s,|dt�}|j|d|d|�|S(screate new CryptContext instance from an INI-formatted file.

        this functions exactly the same as :meth:`from_string`,
        except that it loads from a local file.

        :type path: str
        :arg path:
            path to local file containing INI-formatted config.

        :type section: str
        :param section:
            option name of section to read from, defaults to ``"passlib"``.

        :type encoding: str
        :arg encoding:
            encoding used to load file, defaults to ``"utf-8"``.

        :returns:
            new CryptContext instance, configured based on the parameters
            stored in the file *path*.

        .. versionadded:: 1.6

        .. seealso:: :meth:`from_string` for an equivalent usage example.
        R�R?R@(RPt	load_path(R=R>R?R@RZ((s3/usr/lib/python2.7/site-packages/passlib/context.pyR<scK�s<tdt�}|j|�|r8|j|dt�n|S(s6Return copy of existing CryptContext instance.

        This function returns a new CryptContext instance whose configuration
        is exactly the same as the original, with the exception that any keywords
        passed in will take precedence over the original settings.
        As an example::

            >>> from passlib.context import CryptContext

            >>> # given an existing context...
            >>> ctx1 = CryptContext(["sha256_crypt", "md5_crypt"])

            >>> # copy can be used to make a clone, and update
            >>> # some of the settings at the same time...
            >>> ctx2 = custom_app_context.copy(default="md5_crypt")

            >>> # and the original will be unaffected by the change
            >>> ctx1.default_scheme()
            "sha256_crypt"
            >>> ctx2.default_scheme()
            "md5_crypt"

        .. versionadded:: 1.6
            This method was previously named :meth:`!replace`. That alias
            has been deprecated, and will be removed in Passlib 1.8.

        .. seealso:: :meth:`update`
        R�RQ(RRPR�R2(RZRUR�((s3/usr/lib/python2.7/site-packages/passlib/context.pyR�+s
 
cK�s
|j|�S(sG
        alias for :meth:`copy`, to match PasswordHash.using()
        (R�(RZRU((s3/usr/lib/python2.7/site-packages/passlib/context.pyR�QscK�s tdtdd�|j|�S(s deprecated alias of :meth:`copy`s�CryptContext().replace() has been deprecated in Passlib 1.6, and will be removed in Passlib 1.8, it has been renamed to CryptContext().copy()R8i(RR;R�(RZRU((s3/usr/lib/python2.7/site-packages/passlib/context.pyR\Ws
cK�s�|dk	r||d<n|tk	r�tdt�|dkrN|j|�q�t|t�r}|j|j�|j|�q�t	d��n)|r�|j|�n|s�t
d��dS(NRbs�The CryptContext ``policy`` keyword has been deprecated as of Passlib 1.6, and will be removed in Passlib 1.8; please use ``CryptContext.from_string()` or ``CryptContext.from_path()`` instead.s%policy must be a CryptPolicy instances/_autoload=False and kwds are mutually exclusive(R/t_UNSETRR;R�RERRRRQRHR^(RZRbtpolicyR�RU((s3/usr/lib/python2.7/site-packages/passlib/context.pyR`bs
cC�sdt|�S(Ns<CryptContext at 0x%0x>(tid(RZ((s3/usr/lib/python2.7/site-packages/passlib/context.pyt__repr__�scC�std|j�dt�S(NR9RW(RR�R2(RZ((s3/usr/lib/python2.7/site-packages/passlib/context.pyt_get_policy�scC�sEtdtdd�t|t�r5|j|j�ntd��dS(Ns�The CryptPolicy class and the ``context.policy`` attribute have been deprecated as of Passlib 1.6, and will be removed in Passlib 1.8; please use the ``context.load()`` and ``context.update()`` methods instead.R8isexpected CryptPolicy instance(RR;RERR�RRRH(RZR�((s3/usr/lib/python2.7/site-packages/passlib/context.pyt_set_policy�s

tdocsC[deprecated] returns CryptPolicy instance tied to this CryptContextcC�sEt�}tr"|j||�n|j||�t|j|��S(s<helper read INI from stream, extract passlib section as dict(RRt	read_filetreadfpRFtitems(R�R?tfilenametp((s3/usr/lib/python2.7/site-packages/passlib/context.pyt_parse_ini_stream�s
	c	�s�����fd�}trIt�dd|��}||�SWdQXnw|dkrzt�d��}||�SWdQXnFt�d��5}|j�j|�jd�}|t|��SWdQXdS(	s�Load new configuration into CryptContext from a local file.

        This function is a wrapper for :meth:`load` which
        loads a configuration string from the local file *path*,
        instead of an in-memory source. Its behavior and options
        are otherwise identical to :meth:`!load` when provided with
        an INI-formatted string.

        .. versionadded:: 1.6
        c�s(�j|���}�j|d��S(NRQ(R�R�(R�RU(R>R?RZRQ(s3/usr/lib/python2.7/site-packages/passlib/context.pythelper�strtR@Nsutf-8tasciitrb(sutf-8sascii(RtopentreadtdecodeR~R(	RZR>RQR?R@R�R�tfhttmp((R>R?RZRQs3/usr/lib/python2.7/site-packages/passlib/context.pyR��sc�s�t}t|t�rltr3t||dd�}nt|dd|dd�}|jt|�|d�}nWt|t�r�t	|j
jdt��}t}n$t
|d�s�t|dd��n|r�|j�t	�fd	�t|�D��}n|rG|j
d
k	rG|sd
S|}t	|j
jdt��}|j|�nt|�}||_
|j�|j|_|j|_|jr�|jjdd
�n	d
|_d
S(s�Load new configuration into CryptContext, replacing existing config.

        :arg source:
            source of new configuration to load.
            this value can be a number of different types:

            * a :class:`!dict` object, or compatible Mapping

                the key/value pairs will be interpreted the same
                keywords for the :class:`CryptContext` class constructor.

            * a :class:`!unicode` or :class:`!bytes` string

                this will be interpreted as an INI-formatted file,
                and appropriate key/value pairs will be loaded from
                the specified *section*.

            * another :class:`!CryptContext` object.

                this will export a snapshot of its configuration
                using :meth:`to_dict`.

        :type update: bool
        :param update:
            By default, :meth:`load` will replace the existing configuration
            entirely. If ``update=True``, it will preserve any existing
            configuration options that are not overridden by the new source,
            much like the :meth:`update` method.

        :type section: str
        :param section:
            When parsing an INI-formatted string, :meth:`load` will look for
            a section named ``"passlib"``. This option allows an alternate
            section name to be used. Ignored when loading from a dictionary.

        :type encoding: str
        :param encoding:
            Encoding to use when decode bytes from string.
            Defaults to ``"utf-8"``. Ignoring when loading from a dictionary.

        :raises TypeError:
            * If the source cannot be identified.
            * If an unknown / malformed keyword is encountered.

        :raises ValueError:
            If an invalid keyword value is encountered.

        .. note::

            If an error occurs during a :meth:`!load` call, the :class:`!CryptContext`
            instance will be restored to the configuration it was in before
            the :meth:`!load` call was made; this is to ensure it is
            *never* left in an inconsistent state due to a load error.

        .. versionadded:: 1.6
        tparamRBsutf-8tsource_encodings&<string passed to CryptContext.load()>RNR�sstring or dictc3�s'|]\}}�|�|fVqdS(N((RCRuR&(tparse(s3/usr/lib/python2.7/site-packages/passlib/context.pys	<genexpr>*sNt_strip_unused_context_kwds(R2RERRR	RR�RRRFRmR{RPRlRt_parse_config_keyRR/RQR�t_reset_dummy_verifyR�t_get_recordR�t_identify_recordR�t__dict__R]R(RZRBRQR?R@t
parse_keysRtconfig((Rs3/usr/lib/python2.7/site-packages/passlib/context.pyR��s><				
	cC�sQt|t�st�|jdd�jd�}t|�}|dkrcd
d
|d}}}nR|dkr�d
}|\}}n1|dkr�|\}}}ntd|f��|dkr�d
}n&|r�|d
k	r�td	|��n|d
krd
}n&|r+|d
k	r+td|��n|sDtd|��n|||fS(s>helper used to parse ``cat__scheme__option`` keys into a tupleRsRriiiis)keys must have less than 3 separators: %rR�sempty category: %rR_sempty scheme: %rsempty option: %rN(RERR^R\tsplitROR/RH(tckeytpartstcountR�R�Ru((s3/usr/lib/python2.7/site-packages/passlib/context.pyRDs.
		cO�sv|rVt|�dkr'td��n|r<td��n|j|ddt�n|rr|j|dt�ndS(s�Helper for quickly changing configuration.

        This acts much like the :meth:`!dict.update` method:
        it updates the context's configuration,
        replacing the original value(s) for the specified keys,
        and preserving the rest.
        It accepts any :ref:`keyword <context-options>`
        accepted by the :class:`!CryptContext` constructor.

        .. versionadded:: 1.6

        .. seealso:: :meth:`copy`
        is(expected at most one positional arguments.positional arg and keywords mutually exclusiveiRQN(RORHR�R2(RZR[RU((s3/usr/lib/python2.7/site-packages/passlib/context.pyRQbsc�s:�jj}|r2t���fd�|D��S|SdS(s;return schemes loaded into this CryptContext instance.

        :type resolve: bool
        :arg resolve:
            if ``True``, will return a tuple of :class:`~passlib.ifc.PasswordHash`
            objects instead of their names.

        :returns:
            returns tuple of the schemes configured for this context
            via the *schemes* option.

        .. versionadded:: 1.6
            This was previously available as ``CryptContext().policy.schemes()``

        .. seealso:: the :ref:`schemes <context-schemes-option>` option for usage example.
        c3�s'|]}�j|�d��VqdS(RdN(R0(RCR�(RhRZRd(s3/usr/lib/python2.7/site-packages/passlib/context.pys	<genexpr>�sN(RmRbRw(RZRNRhRdRb((RhRZRds3/usr/lib/python2.7/site-packages/passlib/context.pyRb�s
cC�s)|jd|d|�}|r"|S|jS(shreturn name of scheme that :meth:`hash` will use by default.

        :type resolve: bool
        :arg resolve:
            if ``True``, will return a :class:`~passlib.ifc.PasswordHash`
            object instead of the name.

        :type category: str or None
        :param category:
            Optional :ref:`user category <user-categories>`.
            If specified, this will return the catgory-specific default scheme instead.

        :returns:
            name of the default scheme.

        .. seealso:: the :ref:`default <context-default-option>` option for usage example.

        .. versionadded:: 1.6

        .. versionchanged:: 1.7

            This now returns a hasher configured with any CryptContext-specific
            options (custom rounds settings, etc).  Previously this returned
            the base hasher from :mod:`passlib.hash`.
        RdN(R0R/R.(RZRhRNRdthasher((s3/usr/lib/python2.7/site-packages/passlib/context.pyR��scC�smy'|j||�}|r"|jS|SWntk
r:nX|jjr]td|f��ntd��dS(s�helper to resolve name of scheme -> :class:`~passlib.ifc.PasswordHash` object used by scheme.

        :arg scheme:
            This should identify the scheme to lookup.
            If omitted or set to ``None``, this will return the handler
            for the default scheme.

        :arg category:
            If a user category is specified, and no scheme is provided,
            it will use the default for that category.
            Otherwise this parameter is ignored.

        :param unconfigured:

            By default, this returns a handler object whose .hash()
            and .needs_update() methods will honor the configured
            provided by CryptContext.   See ``unconfigured=True``
            to get the underlying handler from before any context-specific
            configuration was applied.

        :raises KeyError:
            If the scheme does not exist OR is not being used within this context.

        :returns:
            :class:`~passlib.ifc.PasswordHash` object used to implement
            the named scheme within this context (this will usually
            be one of the objects from :mod:`passlib.hash`)

        .. versionadded:: 1.6
            This was previously available as ``CryptContext().policy.get_handler()``

        .. versionchanged:: 1.7

            This now returns a hasher configured with any CryptContext-specific
            options (custom rounds settings, etc).  Previously this returned
            the base hasher from :mod:`passlib.hash`.
        s;crypt algorithm not found in this CryptContext instance: %rs8no crypt algorithms loaded in this CryptContext instanceN(R	R�RgRmR(RZR�RhRdR((s3/usr/lib/python2.7/site-packages/passlib/context.pyR0�s&
cC�std�|jjD��S(sCcheck if any handlers in this context aren't in the global registrycs�s!|]}t|�s|VqdS(N(R1(RCR0((s3/usr/lib/python2.7/site-packages/passlib/context.pys	<genexpr>-s(RwRmR(RZ((s3/usr/lib/python2.7/site-packages/passlib/context.pyt_get_unregistered_handlers+scC�s
|jjS(s�
        return :class:`!set` containing union of all :ref:`contextual keywords <context-keywords>`
        supported by the handlers in this context.

        .. versionadded:: 1.6.6
        (RmR�(RZ((s3/usr/lib/python2.7/site-packages/passlib/context.pyR�0scC�sH|\}}}|r,d||p$d|fS|r@d||fS|SdS(s*convert 3-part config key to single strings
%s__%s__%sR_s%s__%sN((RuR�R�toption((s3/usr/lib/python2.7/site-packages/passlib/context.pyRt=scC�s�t|ttf�r'dj|�}n_t|t�r�t|t�rw|ddkrw|rnd|jd�nd}q�t|�}nt|t�s�t	d||f��|j
dd�S(	s,render value to string suitable for INI files, iR,s%.2ft0sexpected string for key: %r %rR s%%(RERfRwRxRR"R#R�RR^R\(RuR&((s3/usr/lib/python2.7/site-packages/passlib/context.pyt_render_ini_valueHs"c�s/|j�t�fd�|jj|�D��S(sgReturn current configuration as a dictionary.

        :type resolve: bool
        :arg resolve:
            if ``True``, the ``schemes`` key will contain a list of
            a :class:`~passlib.ifc.PasswordHash` objects instead of just
            their names.

        This method dumps the current configuration of the CryptContext
        instance. The key/value pairs should be in the format accepted
        by the :class:`!CryptContext` class constructor, in fact
        ``CryptContext(**myctx.to_dict())`` will create an exact copy of ``myctx``.
        As an example::

            >>> # you can dump the configuration of any crypt context...
            >>> from passlib.apps import ldap_nocrypt_context
            >>> ldap_nocrypt_context.to_dict()
            {'schemes': ['ldap_salted_sha1',
            'ldap_salted_md5',
            'ldap_sha1',
            'ldap_md5',
            'ldap_plaintext']}

        .. versionadded:: 1.6
            This was previously available as ``CryptContext().policy.to_dict()``

        .. seealso:: the :ref:`context-serialization-example` example in the tutorial.
        c3�s'|]\}}�|�|fVqdS(N((RCRuR&(Rv(s3/usr/lib/python2.7/site-packages/passlib/context.pys	<genexpr>}s(RtRFRmR{(RZRN((Rvs3/usr/lib/python2.7/site-packages/passlib/context.pyRS]s	cC�sq|j}|j}|j|�xK|jj�D]:\}}|||�}||�}|j|||�q/WdS(s(helper to write to ConfigParser instanceN(RtRtadd_sectionRmR{R�(RZtparserR?RvRytktv((s3/usr/lib/python2.7/site-packages/passlib/context.pyt_write_to_parser�s		
cC�s�t�}|j||�t�}|j|�|j�}|rh|jddjd�|D���n|j�}ts�|jd�}n|S(sHserialize to INI format and return as unicode string.

        :param section:
            name of INI section to output, defaults to ``"passlib"``.

        :returns:
            CryptContext configuration, serialized to a INI unicode string.

        This function acts exactly like :meth:`to_dict`, except that it
        serializes all the contents into a single human-readable string,
        which can be hand edited, and/or stored in a file. The
        output of this method is accepted by :meth:`from_string`,
        :meth:`from_path`, and :meth:`load`. As an example::

            >>> # you can dump the configuration of any crypt context...
            >>> from passlib.apps import ldap_nocrypt_context
            >>> print ldap_nocrypt_context.to_string()
            [passlib]
            schemes = ldap_salted_sha1, ldap_salted_md5, ldap_sha1, ldap_md5, ldap_plaintext

        .. versionadded:: 1.6
            This was previously available as ``CryptContext().policy.to_string()``

        .. seealso:: the :ref:`context-serialization-example` example in the tutorial.
        s�# NOTE: the %s handler(s) are not registered with Passlib,
# this string may not correctly reproduce the current configuration.

s, cs�s|]}t|j�VqdS(N(treprR.(RCR0((s3/usr/lib/python2.7/site-packages/passlib/context.pys	<genexpr>�ssutf-8(	RRRRRRxtgetvalueRR(RZR?RtbuftunregisteredR�((s3/usr/lib/python2.7/site-packages/passlib/context.pyR}�s		
ii
ig{�G�z�?icC�s|j�dS(N(R(RZ((s3/usr/lib/python2.7/site-packages/passlib/context.pytreset_min_verify_time�scC�sK|r7t|t�s't|d��n|j||�S|j||�SdS(sCreturn record based on scheme, or failing that, by identifying hashR3N(RERRR	R
(RZR3R�Rh((s3/usr/lib/python2.7/site-packages/passlib/context.pyt_get_or_identify_record�s
cC�sG|s
dS|jjj|j�}x|D]}|j|d�q)WdS(sf
        helper which removes any context keywords from **kwds**
        that are known to be used by another scheme in this context,
        but are NOT supported by handler specified by **record**.

        .. note::
            as optimization, load() will set this method to None on a per-instance basis
            if there are no context kwds.
        N(RmR�R�R]R/(RZRUR�tunused_kwdsRu((s3/usr/lib/python2.7/site-packages/passlib/context.pyR�s


cC�sM|dk	rtdt�n|j|||�}|jpL|j|d|�S(s�	Check if hash needs to be replaced for some reason,
        in which case the secret should be re-hashed.

        This function is the core of CryptContext's support for hash migration:
        This function takes in a hash string, and checks the scheme,
        number of rounds, and other properties against the current policy.
        It returns ``True`` if the hash is using a deprecated scheme,
        or is otherwise outside of the bounds specified by the policy
        (e.g. the number of rounds is lower than :ref:`min_rounds <context-min-rounds-option>`
        configuration for that algorithm).
        If so, the password should be re-hashed using :meth:`hash`
        Otherwise, it will return ``False``.

        :type hash: unicode or bytes
        :arg hash:
            The hash string to examine.

        :type scheme: str or None
        :param scheme:

            Optional scheme to use. Scheme must be one of the ones
            configured for this context (see the
            :ref:`schemes <context-schemes-option>` option).
            If no scheme is specified, it will be identified
            based on the value of *hash*.

            .. deprecated:: 1.7

                Support for this keyword is deprecated, and will be removed in Passlib 2.0.

        :type category: str or None
        :param category:
            Optional :ref:`user category <user-categories>`.
            If specified, this will cause any category-specific defaults to
            be used when determining if the hash needs to be updated
            (e.g. is below the minimum rounds).

        :type secret: unicode, bytes, or None
        :param secret:
            Optional secret associated with the provided ``hash``.
            This is not required, or even currently used for anything...
            it's for forward-compatibility with any future
            update checks that might need this information.
            If provided, Passlib assumes the secret has already been
            verified successfully against the hash.

            .. versionadded:: 1.6

        :returns: ``True`` if hash should be replaced, otherwise ``False``.

        :raises ValueError:
            If the hash did not match any of the configured :meth:`schemes`.

        .. versionadded:: 1.6
            This method was previously named :meth:`hash_needs_update`.

        .. seealso:: the :ref:`context-migration-example` example in the tutorial.
        sqCryptContext.needs_update(): 'scheme' keyword is deprecated as of Passlib 1.7, and will be removed in Passlib 2.0R4N(R/RR;R!Rptneeds_update(RZR3R�RhR4R�((s3/usr/lib/python2.7/site-packages/passlib/context.pyR#�s
;
Rps1.6tremoveds2.0treplacementsCryptContext.needs_update()cC�s|j|||�S(sLegacy alias for :meth:`needs_update`.

        .. deprecated:: 1.6
            This method was renamed to :meth:`!needs_update` in version 1.6.
            This alias will be removed in version 2.0, and should only
            be used for compatibility with Passlib 1.3 - 1.5.
        (R#(RZR3R�Rh((s3/usr/lib/python2.7/site-packages/passlib/context.pythash_needs_updateAs	s1.7cK�s>|j||�}|j}|r1|||�n|j|�S(s�Generate a config string for specified scheme.

        .. deprecated:: 1.7

            This method will be removed in version 2.0, and should only
            be used for compatibility with Passlib 1.3 - 1.6.
        (R	Rt	genconfig(RZR�RhR�R�tstrip_unused((s3/usr/lib/python2.7/site-packages/passlib/context.pyR'Ls
		cK�sG|j|||�}|j}|r4|||�n|j|||�S(s�Generate hash for the specified secret using another hash.

        .. deprecated:: 1.7

            This method will be removed in version 2.0, and should only
            be used for compatibility with Passlib 1.3 - 1.6.
        (R!Rtgenhash(RZR4R
R�RhRUR�R(((s3/usr/lib/python2.7/site-packages/passlib/context.pyR)[s
		cC�sJ|j|||�}|dkr%dS|r?|r8|jS|Sn|jSdS(s�Attempt to identify which algorithm the hash belongs to.

        Note that this will only consider the algorithms
        currently configured for this context
        (see the :ref:`schemes <context-schemes-option>` option).
        All registered algorithms will be checked, from first to last,
        and whichever one positively identifies the hash first will be returned.

        :type hash: unicode or bytes
        :arg hash:
            The hash string to test.

        :type category: str or None
        :param category:
            Optional :ref:`user category <user-categories>`.
            Ignored by this function, this parameter
            is provided for symmetry with the other methods.

        :type resolve: bool
        :param resolve:
            If ``True``, returns the hash handler itself,
            instead of the name of the hash.

        :type required: bool
        :param required:
            If ``True``, this will raise a ValueError if the hash
            cannot be identified, instead of returning ``None``.

        :returns:
            The handler which first identifies the hash,
            or ``None`` if none of the algorithms identify the hash.
        N(R
R/R�R.(RZR3RhRNRiRdR�((s3/usr/lib/python2.7/site-packages/passlib/context.pyR�js"cK�s]|dk	rtdt�n|j||�}|j}|rM|||�n|j||�S(sZrun secret through selected algorithm, returning resulting hash.

        :type secret: unicode or bytes
        :arg secret:
            the password to hash.

        :type scheme: str or None
        :param scheme:

            Optional scheme to use. Scheme must be one of the ones
            configured for this context (see the
            :ref:`schemes <context-schemes-option>` option).
            If no scheme is specified, the configured default
            will be used.

            .. deprecated:: 1.7

                Support for this keyword is deprecated, and will be removed in Passlib 2.0.

        :type category: str or None
        :param category:
            Optional :ref:`user category <user-categories>`.
            If specified, this will cause any category-specific defaults to
            be used when hashing the password (e.g. different default scheme,
            different default rounds values, etc).

        :param \*\*kwds:
            All other keyword options are passed to the selected algorithm's
            :meth:`PasswordHash.hash() <passlib.ifc.PasswordHash.hash>` method.

        :returns:
            The secret as encoded by the specified algorithm and options.
            The return value will always be a :class:`!str`.

        :raises TypeError, ValueError:
            * If any of the arguments have an invalid type or value.
              This includes any keywords passed to the underlying hash's
              :meth:`PasswordHash.hash() <passlib.ifc.PasswordHash.hash>` method.

        .. seealso:: the :ref:`context-basic-example` example in the tutorial
        siCryptContext.hash(): 'scheme' keyword is deprecated as of Passlib 1.7, and will be removed in Passlib 2.0N(R/RR;R	RR3(RZR4R�RhRUR�R(((s3/usr/lib/python2.7/site-packages/passlib/context.pyR3�s+
	sCryptContext.hash()cO�s|j||�S(s
        Legacy alias for :meth:`hash`.

        .. deprecated:: 1.7
            This method was renamed to :meth:`!hash` in version 1.7.
            This alias will be removed in version 2.0, and should only
            be used for compatibility with Passlib 1.3 - 1.6.
        (R3(RZR[RU((s3/usr/lib/python2.7/site-packages/passlib/context.pytencrypt�s
cK�s}|dk	rtdt�n|dkr6|j�tS|j|||�}|j}|rj|||�n|j|||�S(s�verify secret against an existing hash.

        If no scheme is specified, this will attempt to identify
        the scheme based on the contents of the provided hash
        (limited to the schemes configured for this context).
        It will then check whether the password verifies against the hash.

        :type secret: unicode or bytes
        :arg secret:
            the secret to verify

        :type hash: unicode or bytes
        :arg hash:
            hash string to compare to

            if ``None`` is passed in, this will be treated as "never verifying"

        :type scheme: str
        :param scheme:
            Optionally force context to use specific scheme.
            This is usually not needed, as most hashes can be unambiguously
            identified. Scheme must be one of the ones configured
            for this context
            (see the :ref:`schemes <context-schemes-option>` option).

            .. deprecated:: 1.7

                Support for this keyword is deprecated, and will be removed in Passlib 2.0.

        :type category: str or None
        :param category:
            Optional :ref:`user category <user-categories>` string.
            This is mainly used when generating new hashes, it has little
            effect when verifying; this keyword is mainly provided for symmetry.

        :param \*\*kwds:
            All additional keywords are passed to the appropriate handler,
            and should match its :attr:`~passlib.ifc.PasswordHash.context_kwds`.

        :returns:
            ``True`` if the password matched the hash, else ``False``.

        :raises ValueError:
            * if the hash did not match any of the configured :meth:`schemes`.

            * if any of the arguments have an invalid value (this includes
              any keywords passed to the underlying hash's
              :meth:`PasswordHash.verify() <passlib.ifc.PasswordHash.verify>` method).

        :raises TypeError:
            * if any of the arguments have an invalid type (this includes
              any keywords passed to the underlying hash's
              :meth:`PasswordHash.verify() <passlib.ifc.PasswordHash.verify>` method).

        .. seealso:: the :ref:`context-basic-example` example in the tutorial
        skCryptContext.verify(): 'scheme' keyword is deprecated as of Passlib 1.7, and will be removed in Passlib 2.0N(R/RR;tdummy_verifyRPR!Rtverify(RZR4R3R�RhRUR�R(((s3/usr/lib/python2.7/site-packages/passlib/context.pyR,�s;

	c	K�s�|dk	rtdt�n|dkr<|j�tdfS|j|||�}|j}|r�|r�|j�}|||�n|}|j|||�s�tdfS|j	s�|j
|d|�r�t|j|d||�fStdfSdS(s�
verify password and re-hash the password if needed, all in a single call.

        This is a convenience method which takes care of all the following:
        first it verifies the password (:meth:`~CryptContext.verify`), if this is successfull
        it checks if the hash needs updating (:meth:`~CryptContext.needs_update`), and if so,
        re-hashes the password (:meth:`~CryptContext.hash`), returning the replacement hash.
        This series of steps is a very common task for applications
        which wish to update deprecated hashes, and this call takes
        care of all 3 steps efficiently.

        :type secret: unicode or bytes
        :arg secret:
            the secret to verify

        :type secret: unicode or bytes
        :arg hash:
            hash string to compare to.

            if ``None`` is passed in, this will be treated as "never verifying"

        :type scheme: str
        :param scheme:
            Optionally force context to use specific scheme.
            This is usually not needed, as most hashes can be unambiguously
            identified. Scheme must be one of the ones configured
            for this context
            (see the :ref:`schemes <context-schemes-option>` option).

            .. deprecated:: 1.7

                Support for this keyword is deprecated, and will be removed in Passlib 2.0.

        :type category: str or None
        :param category:
            Optional :ref:`user category <user-categories>`.
            If specified, this will cause any category-specific defaults to
            be used if the password has to be re-hashed.

        :param \*\*kwds:
            all additional keywords are passed to the appropriate handler,
            and should match that hash's
            :attr:`PasswordHash.context_kwds <passlib.ifc.PasswordHash.context_kwds>`.

        :returns:
            This function returns a tuple containing two elements:
            ``(verified, replacement_hash)``. The first is a boolean
            flag indicating whether the password verified,
            and the second an optional replacement hash.
            The tuple will always match one of the following 3 cases:

            * ``(False, None)`` indicates the secret failed to verify.
            * ``(True, None)`` indicates the secret verified correctly,
              and the hash does not need updating.
            * ``(True, str)`` indicates the secret verified correctly,
              but the current hash needs to be updated. The :class:`!str`
              will be the freshly generated hash, to replace the old one.

        :raises TypeError, ValueError:
            For the same reasons as :meth:`verify`.

        .. seealso:: the :ref:`context-migration-example` example in the tutorial.
        skCryptContext.verify(): 'scheme' keyword is deprecated as of Passlib 1.7, and will be removed in Passlib 2.0R4RhN(
R/RR;R+RPR!RR�R,RpR#R2R3(	RZR4R3R�RhRUR�R(t
clean_kwds((s3/usr/lib/python2.7/site-packages/passlib/context.pytverify_and_update(	s"@


	
stoo many secretscC�s|j|j�S(s>
        precalculated hash for dummy_verify() to use
        (R3t
_dummy_secret(RZ((s3/usr/lib/python2.7/site-packages/passlib/context.pyt_dummy_hash�	scC�st|�jj|�dS(s>
        flush memoized values used by dummy_verify()
        N(RIR0tclear_cache(RZ((s3/usr/lib/python2.7/site-packages/passlib/context.pyR�	scC�s|j|j|j�tS(s�
        Helper that applications can call when user wasn't found,
        in order to simulate time it would take to hash a password.

        Runs verify() against a dummy hash, to simulate verification
        of a real account password.

        :param elapsed:

            .. deprecated:: 1.7.1

                this option is ignored, and will be removed in passlib 1.8.

        .. versionadded:: 1.7
        (R,R/R0RP(RZtelapsed((s3/usr/lib/python2.7/site-packages/passlib/context.pyR+�	scC�s|j|d�jS(sn
        test if hash represents a usuable password --
        i.e. does not represent an unusuable password such as ``"!"``,
        which is recognized by the :class:`~passlib.hash.unix_disabled` hash.

        :raises ValueError:
            if the hash is not recognized
            (typically solved by adding ``unix_disabled`` to the list of schemes).
        N(R
R/R�(RZR3((s3/usr/lib/python2.7/site-packages/passlib/context.pyt
is_enabled�	s
cC�s(|jj}|jst�|j|�S(s�
        return a string to disable logins for user,
        usually by returning a non-verifying string such as ``"!"``.

        :param hash:
            Callers can optionally provide the account's existing hash.
            Some disabled handlers (such as :class:`!unix_disabled`)
            will encode this into the returned value,
            so that it can be recovered via :meth:`enable`.

        :raises RuntimeError:
            if this function is called w/o a disabled hasher
            (such as :class:`~passlib.hash.unix_disabled`) included
            in the list of schemes.

        :returns:
            hash string which will be recognized as valid by the context,
            but is guaranteed to not validate against *any* password.
        (RmR�R�R^tdisable(RZR3R�((s3/usr/lib/python2.7/site-packages/passlib/context.pyR4�	scC�s0|j|d�}|jr(|j|�S|SdS(s�
        inverse of :meth:`disable` --
        attempts to recover original hash which was converted
        by a :meth:`!disable` call into a disabled hash --
        thus restoring the user's original password.

        :raises ValueError:
            if original hash not present, or if the disabled handler doesn't
            support encoding the original hash (e.g. ``django_disabled``)

        :returns:
            the original hash.
        N(R
R/R�tenable(RZR3R�((s3/usr/lib/python2.7/site-packages/passlib/context.pyR5�	s	
N(BR�R�R�R/RmR	R
R�R�RAR<R�R�R\R�R2R`R�R�R�tpropertyR�R�R�RPR�R�RRQRbR�R0RR�RtRRSRR}tmvt_estimate_max_samplestmvt_estimate_min_samplestmvt_estimate_max_timetmvt_estimate_resolutionR�R�R R!RR#RR&R'R)R�R3R*R,R.R/RR0RR+R3R4R5(((s3/usr/lib/python2.7/site-packages/passlib/context.pyR�s�&	&				
		o	E15	
#	
=	
	E
	,8$Ma		cB�s2eZdZdZdd�Zd�Zd�ZRS(s�CryptContext subclass which doesn't load handlers until needed.

    This is a subclass of CryptContext which takes in a set of arguments
    exactly like CryptContext, but won't import any handlers
    (or even parse its arguments) until
    the first time one of its methods is accessed.

    :arg schemes:
        The first positional argument can be a list of schemes, or omitted,
        just like CryptContext.

    :param onload:

        If a callable is passed in via this keyword,
        it will be invoked at lazy-load time
        with the following signature:
        ``onload(**kwds) -> kwds``;
        where ``kwds`` is all the additional kwds passed to LazyCryptContext.
        It should perform any additional deferred initialization,
        and return the final dict of options to be passed to CryptContext.

        .. versionadded:: 1.6

    :param create_policy:

        .. deprecated:: 1.6
            This option will be removed in Passlib 1.8,
            applications should use ``onload`` instead.

    :param kwds:

        All additional keywords are passed to CryptContext;
        or to the *onload* function (if provided).

    This is mainly used internally by modules such as :mod:`passlib.apps`,
    which define a large number of contexts, but only a few of them will be needed
    at any one time. Use of this class saves the memory needed to import
    the specified handlers until the context instance is actually accessed.
    As well, it allows constructing a context at *module-init* time,
    but using :func:`!onload()` to provide dynamic configuration
    at *application-run* time.

    .. note:: 
        This class is only useful if you're referencing handler objects by name,
        and don't want them imported until runtime. If you want to have the config
        validated before your application runs, or are passing in already-imported
        handler instances, you should use :class:`CryptContext` instead.

    .. versionadded:: 1.4
    cK�s&|dk	r||d<n||_dS(NRb(R/t
_lazy_kwds(RZRbRU((s3/usr/lib/python2.7/site-packages/passlib/context.pyR`(
s
cC�s�|j}d|krdtdt�|jd�}||�}tj|dt�}|jj�}n*d|kr�|jd�}||�}n|`t	t
|�j|�t|_
dS(Nt
create_policys�The CryptPolicy class, and LazyCryptContext's ``create_policy`` keyword have been deprecated as of Passlib 1.6, and will be removed in Passlib 1.8; please use the ``onload`` keyword instead.RLtonload(R;RR;R]RRMRPRRRStsuperRR`Rt	__class__(RZRUR<tresultR�R=((s3/usr/lib/python2.7/site-packages/passlib/context.pyt
_lazy_init-
s	cC�sK|jd�s|jd�r;|jdk	r;|j�ntj||�S(Nt_Rr(t
startswithR;R/RAtobjectt__getattribute__(RZtattr((s3/usr/lib/python2.7/site-packages/passlib/context.pyRE@
s
N(R�R�R�R/R;R`RARE(((s3/usr/lib/python2.7/site-packages/passlib/context.pyR�	s
2	(AR�t
__future__RR�tloggingt	getLoggerR�tlogt	threadingttimetwarningsRtpasslib.excRRRtpasslib.registryRRt
passlib.utilsRR�RR	R
RRR
Rtpasslib.utils.binaryRtpasslib.utils.compatRRRRRRRRRRRtpasslib.utils.decorRRt__all__RDR�R'R�R�RFR$R�R1R�R/R5R�R:RR�RR(((s3/usr/lib/python2.7/site-packages/passlib/context.pyt<module>sT:L					����g�����C

Anon7 - 2022
AnonSec Team