Viewing File: /opt/alt/python35/lib/python3.5/site-packages/click/__pycache__/decorators.cpython-35.pyc



e([V*@s9ddlZddlZddlmZddlmZddlmZddlm	Z	ddl
mZdd	Zd
dZ
dd
dZddZddddZdddZddZddZddZddZddZddd Zd!d"Zdd#lmZmZmZmZdS)$N)update_wrapper)	iteritems)_check_for_unicode_literals)echo)get_current_contextcsfdd}t|S)z]Marks a callback as wanting to receive the current context
    object as first argument.
    cst||S)N)r)argskwargs)f/decorators.pynew_funcszpass_context.<locals>.new_func)r)r
r
r)r
rpass_contextsrcsfdd}t|S)zSimilar to :func:`pass_context`, but only pass the object on the
    context onwards (:attr:`Context.obj`).  This is useful if that object
    represents the state of a nested system.
    cstj||S)N)robj)rr	)r
rrr
szpass_obj.<locals>.new_func)r)r
r
r)r
rpass_objsrFcsfdd}|S)a.Given an object type this creates a decorator that will work
    similar to :func:`pass_obj` but instead of passing the object of the
    current context, it will find the innermost context of type
    :func:`object_type`.

    This generates a decorator that works roughly like this::

        from functools import update_wrapper

        def decorator(f):
            @pass_context
            def new_func(ctx, *args, **kwargs):
                obj = ctx.find_object(object_type)
                return ctx.invoke(f, obj, *args, **kwargs)
            return update_wrapper(new_func, f)
        return decorator

    :param object_type: the type of the object to pass.
    :param ensure: if set to `True`, a new object will be created and
                   remembered on the context if it's not there yet.
    cs%fdd}t|S)Ncsot}r!|j}n|j}|dkrOtdj|j||dd|S)NzGManaged to invoke callback without a context object of type %r existingr)rZ
ensure_objectZfind_objectRuntimeError__name__Zinvoke)rr	ctxr)ensurer
object_typerrr
6s	
z8make_pass_decorator.<locals>.decorator.<locals>.new_func)r)r
r
)rr)r
r	decorator5sz&make_pass_decorator.<locals>.decoratorr)rrrr)rrrmake_pass_decorators
rcCst|trtdy|j}|j|`Wntk
rRg}YnX|jd}|dkrtj|}t|t	r|j
d}ntj|}||d<t|d|p|j
jd|d||S)Nz5Attempted to convert a callback into a command twice.helpzutf-8namecallbackparams)
isinstanceCommand	TypeError__click_params__reverseAttributeErrorgetinspectZgetdocbytesdecodecleandocrrlower)r
rattrsclsrrrrr
_make_commandEs$	



r*cs.dkrtfdd}|S)a*Creates a new :class:`Command` and uses the decorated function as
    callback.  This will also automatically attach all decorated
    :func:`option`\s and :func:`argument`\s as parameters to the command.

    The name of the command defaults to the name of the function.  If you
    want to change that, you can pass the intended name as the first
    argument.

    All keyword arguments are forwarded to the underlying command class.

    Once decorated the function turns into a :class:`Command` instance
    that can be invoked as a command line utility or be attached to a
    command :class:`Group`.

    :param name: the name of the command.  This defaults to the function
                 name.
    :param cls: the command class to instantiate.  This defaults to
                :class:`Command`.
    Ncs%t|}|j|_|S)N)r*__doc__)r
cmd)r(r)rrrrrszcommand.<locals>.decorator)r)rr)r(rr)r(r)rrcommand\sr-cKs|jdtt||S)zCreates a new :class:`Group` with a function as callback.  This
    works otherwise the same as :func:`command` just that the `cls`
    parameter is set to :class:`Group`.
    r))
setdefaultGroupr-)rr(rrrgroupysr0cCsNt|tr"|jj|n(t|ds:g|_|jj|dS)Nr)rrrappendhasattrr)r
paramrrr_param_memos
	r4csfdd}|S)aAttaches an argument to the command.  All positional arguments are
    passed as parameter declarations to :class:`Argument`; all keyword
    arguments are forwarded unchanged (except ``cls``).
    This is equivalent to creating an :class:`Argument` instance manually
    and attaching it to the :attr:`Command.params` list.

    :param cls: the argument class to instantiate.  This defaults to
                :class:`Argument`.
    cs,jdt}t|||S)Nr))popArgumentr4)r
Z
ArgumentClass)r(param_declsrrrszargument.<locals>.decoratorr)r7r(rr)r(r7rarguments
r8csfdd}|S)aAttaches an option to the command.  All positional arguments are
    passed as parameter declarations to :class:`Option`; all keyword
    arguments are forwarded unchanged (except ``cls``).
    This is equivalent to creating an :class:`Option` instance manually
    and attaching it to the :attr:`Command.params` list.

    :param cls: the option class to instantiate.  This defaults to
                :class:`Option`.
    csOdkr#tjdd<jdt}t|||S)Nrr))r#r&r5Optionr4)r
ZOptionClass)r(r7rrrs
zoption.<locals>.decoratorr)r7r(rr)r(r7roptions
r:csfdd}|S)aShortcut for confirmation prompts that can be ignored by passing
    ``--yes`` as parameter.

    This is equivalent to decorating a function with :func:`option` with
    the following parameters::

        def callback(ctx, param, value):
            if not value:
                ctx.abort()

        @click.command()
        @click.option('--yes', is_flag=True, callback=callback,
                      expose_value=False, prompt='Do you want to continue?')
        def dropdb():
            pass
    csudd}jddjd|jddjdd	jd
dtphd
|S)NcSs|s|jdS)N)abort)rr3valuerrrrsz8confirmation_option.<locals>.decorator.<locals>.callbackis_flagTrexpose_valueFpromptzDo you want to continue?rz%Confirm the action without prompting.--yes)r@)r.r:)r
r)r(r7rrrsz&confirmation_option.<locals>.decoratorr)r7r(rr)r(r7rconfirmation_options
rAcsfdd}|S)aLShortcut for password prompts.

    This is equivalent to decorating a function with :func:`option` with
    the following parameters::

        @click.command()
        @click.option('--password', prompt=True, confirmation_prompt=True,
                      hide_input=True)
        def changeadmin(password):
            pass
    csIjddjddjddtp<d|S)Nr?TZconfirmation_promptZ
hide_input
--password)rB)r.r:)r
)r(r7rrrsz"password_option.<locals>.decoratorr)r7r(rr)r(r7rpassword_optionsrCcsFdkr'tjdjjdfdd}|S)acAdds a ``--version`` option which immediately ends the program
    printing out the version number.  This is implemented as an eager
    option that prints the version and exits the program in the callback.

    :param version: the version number to show.  If not provided Click
                    attempts an auto discovery via setuptools.
    :param prog_name: the name of the program (defaults to autodetection)
    :param message: custom message to show instead of the default
                    (``'%(prog)s, version %(version)s'``)
    :param others: everything else is forwarded to :func:`option`.
    Nrrcsjddjddfdd}jddjdd	jd
djdd|d
<tpd|S)N	prog_namemessagez%(prog)s, version %(version)sc
s|s|jrdS}|dkr5|jj}}|dkryddl}Wntk
rkYnfXxb|jD]W}|jjdpi}x3t|D]%\}}	|	j	kr|j
}PqWqvW|dkrtdtd|d|id|j
|jdS)NrZconsole_scriptszCould not determine versionprogversioncolor)resilient_parsingZ	find_rootZ	info_name
pkg_resourcesImportErrorZworking_setZ
get_entry_mapr"rmodule_namerGrrrHexit)
rr3r<rFZverrJZdistscriptsZscript_nameZentry_point)rEmodulerDrGrrrs0
		

z3version_option.<locals>.decorator.<locals>.callbackr=Tr>Fis_eagerrzShow the version and exit.r	--version)rQ)r5r.r:)r
r)r(rOr7rG)rErDrrs
z!version_option.<locals>.decorator)sys	_getframe	f_globalsr")rGr7r(rr)r(rOr7rGrversion_options%rUcsfdd}|S)alAdds a ``--help`` option which immediately ends the program
    printing out the help page.  This is usually unnecessary to add as
    this is added by default to all commands unless suppressed.

    Like :func:`version_option`, this is implemented as eager option that
    prints in the callback and exits.

    All arguments are forwarded to :func:`option`.
    csodd}jddjddjddjd	d|d
<tpbd|S)
NcSs7|r3|jr3t|jd|j|jdS)NrH)rIrZget_helprHrM)rr3r<rrrr"sz0help_option.<locals>.decorator.<locals>.callbackr=Tr>FrzShow this message and exit.rPr--help)rV)r.r:)r
r)r(r7rrr!s
zhelp_option.<locals>.decoratorr)r7r(rr)r(r7rhelp_options
rW)rr/r6r9)rRr#	functoolsrZ_compatrZ_unicodefunrZutilsrglobalsrrrrr*r-r0r4r8r:rArCrUrWZcorerr/r6r9rrrr<module>s(	
&		6
Back to Directory File Manager