Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/python/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyc


VNc@sdZddlZejdeddddlZddlZddlZddlZddl	m
Z
mZmZddl
mZdejfd	YZd
fdYZdefd
YZdefdYZdefdYZdfdYZdZdZdZdZdddfdddfddd fd!d"dfd#d$d%fd&d'd(fd)d*d+fd,d-d fd.d/d fd0d1dfd2d3d+fd4d5dfd6d7dfg
Zied6ed&6Zeed8Zd9Zd:Zed;krendS(<s-
Rebuild the completion functions for the currently active version of Twisted::
    $ python zshcomp.py -i

This module implements a zsh code generator which generates completion code for
commands that use twisted.python.usage. This is the stuff that makes pressing
Tab at the command line work.

Maintainer: Eric Mangold

To build completion functions for your own commands, and not Twisted commands,
then just do something like this::

    o = mymodule.MyOptions()
    f = file('_mycommand', 'w')
    Builder("mycommand", o, f).write()

Then all you have to do is place the generated file somewhere in your
C{$fpath}, and restart zsh. Note the "site-functions" directory in your
C{$fpath} where you may install 3rd-party completion functions (like the one
you're building). Call C{siteFunctionsPath} to locate this directory
programmatically.

SPECIAL CLASS VARIABLES. You may set these on your usage.Options subclass::

    zsh_altArgDescr
    zsh_multiUse
    zsh_mutuallyExclusive
    zsh_actions
    zsh_actionDescr
    zsh_extras

Here is what they mean (with examples)::

    zsh_altArgDescr = {"foo":"use this description for foo instead"}
        A dict mapping long option names to alternate descriptions.  When this
        variable is present, the descriptions contained here will override
        those descriptions provided in the optFlags and optParameters
        variables.

    zsh_multiUse = ["foo", "bar"]
        A sequence containing those long option names which may appear on the
        command line more than once. By default, options will only be completed
        one time.

    zsh_mutuallyExclusive = [("foo", "bar"), ("bar", "baz")]
        A sequence of sequences, with each sub-sequence containing those long
        option names that are mutually exclusive. That is, those options that
        cannot appear on the command line together.

    zsh_actions = {"foo":'_files -g "*.foo"', "bar":"(one two three)",
            "colors":"_values -s , 'colors to use' red green blue"}
        A dict mapping long option names to Zsh "actions". These actions
        define what will be completed as the argument to the given option.  By
        default, all files/dirs will be completed if no action is given.

        Callables may instead be given for the values in this dict. The
        callable should accept no arguments, and return a string that will be
        used as the zsh "action" in the same way as the literal strings in the
        examples above.

        As you can see in the example above. The "foo" option will have files
        that end in .foo completed when the user presses Tab. The "bar"
        option will have either of the strings "one", "two", or "three"
        completed when the user presses Tab.

        "colors" will allow multiple arguments to be completed, seperated by
        commas. The possible arguments are red, green, and blue. Examples::

            my_command --foo some-file.foo --colors=red,green
            my_command --colors=green
            my_command --colors=green,blue

        Actions may take many forms, and it is beyond the scope of this
        document to illustrate them all. Please refer to the documention for
        the Zsh _arguments function. zshcomp is basically a front-end to Zsh's
        _arguments completion function.

        That documentation is available on the zsh web site at this URL:
        U{http://zsh.sunsite.dk/Doc/Release/zsh_19.html#SEC124}

    zsh_actionDescr = {"logfile":"log file name", "random":"random seed"}
        A dict mapping long option names to a description for the corresponding
        zsh "action". These descriptions are show above the generated matches
        when the user is doing completions for this option.

        Normally Zsh does not show these descriptions unless you have
        "verbose" completion turned on. Turn on verbosity with this in your
        ~/.zshrc::

            zstyle ':completion:*' verbose yes
            zstyle ':completion:*:descriptions' format '%B%d%b'

    zsh_extras = [":file to read from:action", ":file to write to:action"]
        A sequence of extra arguments that will be passed verbatim to Zsh's
        _arguments completion function. The _arguments function does all the
        hard work of doing command line completions. You can see how zshcomp
        invokes the _arguments call by looking at the generated completion
        files that this module creates.

   *** NOTE ***

        You will need to use this variable to describe completions for normal
        command line arguments. That is, those arguments that are not
        associated with an option. That is, the arguments that are given to the
        parseArgs method of your usage.Options subclass.

        In the example above, the 1st non-option argument will be described as
        "file to read from" and completion options will be generated in
        accordance with the "action". (See above about zsh "actions") The
        2nd non-option argument will be described as "file to write to" and
        the action will be interpreted likewise.

        Things you can put here are all documented under the _arguments
        function here: U{http://zsh.sunsite.dk/Doc/Release/zsh_19.html#SEC124}

Zsh Notes:

To enable advanced completion add something like this to your ~/.zshrc::

    autoload -U compinit
    compinit

For some extra verbosity, and general niceness add these lines too::

    zstyle ':completion:*' verbose yes
    zstyle ':completion:*:descriptions' format '%B%d%b'
    zstyle ':completion:*:messages' format '%d'
    zstyle ':completion:*:warnings' format 'No matches for: %d'

Have fun!
iNsfzshcomp is deprecated as of Twisted 11.1. Shell tab-completion is now handled by twisted.python.usage.t
stackleveli(treflecttutiltusage(t
IServiceMakert	MyOptionscBsJeZdZdZdZdddggZddd
dggZd	ZRS(s
    Options for this file
    ts>Usage: python zshcomp.py [--install | -i] | <output directory>tinstalltisiOutput files to the "installation" directory (twisted/python/zsh in the currently active Twisted package)t	directorytdsOutput files to this directorycCs|dr#|dr#tjdn|drH|drHtjdn|drtjj|drtjd|dndS(NRR	s5Can't have --install and --directory at the same timesNot enough argumentss%s is not a directory(Rt
UsageErrortostpathtisdir(tself((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pytpostOptionss!N(	t__name__t
__module__t__doc__tlongdesctsynopsistoptFlagstNonet
optParametersR(((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyRs	tBuildercBseZdZdZRS(cCs||_||_||_dS(s[
        @type cmd_name: C{str}
        @param cmd_name: The name of the command

        @type options: C{twisted.usage.Options}
        @param options: The C{twisted.usage.Options} instance defined for
                        this command

        @type file: C{file}
        @param file: The C{file} to write the completion function to
        N(tcmd_nametoptionstfile(RRRR((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyt__init__s
		cCsC|jjd|jft|j|j|j}|jdS(sf
        Write the completion function to the file given to __init__
        @return: C{None}
        s#compdef %s
N(RtwriteRtArgumentsGeneratorR(Rtgen((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyRs(RRRR(((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyRs	tSubcommandBuildercBs#eZdZdZdZdZRS(s
    Use this builder for commands that have sub-commands. twisted.python.usage
    has the notion of sub-commands that are defined using an entirely seperate
    Options class.
    cCsd|jjd|jf|jjdddlm}|j|j}x.|D]&}|jjd|j|jfqSW|jjddg|j	j
_t|j|j	|j}|j|jjd|j
f|j|j}x]|D]U}|jj|jd	t|j|j	|j}|j|jjd
qW|jjddS(
sf
        Write the completion function to the file given to __init__
        @return: C{None}
        s#compdef %s
s.local _zsh_subcmds_array
_zsh_subcmds_array=(
i(tplugins"%s:%s"
s)

s*::subcmd:->subcmdsif (( CURRENT == 1 )); then
  _describe "%s" _zsh_subcmds_array && ret=0
fi
(( ret )) || return 0

service="$words[1]"

case $service in
s)
s;;
s8*) _message "don't know how to complete $service";;
esacN(RRRttwistedR"t
getPluginst	interfacettapnametdescriptionRt	__class__t
zsh_extrasRtsubcmdLabel(Rt	newplugintpluginstpR ((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyRs&
$
	

N(RRRRR%R*R(((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyR!stMktapBuildercBseZdZeZdZRS(s'
    Builder for the mktap command
    stap to build(RRRRR%R*(((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyR.st
TwistdBuildercBseZdZeZdZRS(s(
    Builder for the twistd command
    sservice to run(RRRRR%R*(((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyR/sRcBseZdZdZdZdZdZdZdZdZ	e
dZd	Zd
Z
dZdZd
ZdZdZRS(sq
    Generate a call to the zsh _arguments completion function
    based on data in a usage.Options subclass
    c
Cso||_||_||_i|_i|_g|_g|_i|_g|_t	j
}t	j}||jd|j||jd|j||jd|j||jd|j||jd|j||jd|jg}g}||jd|||jd|xEt
|D]7\}}	t|	d	kr&tjd	|	||<q&q&WxEt
|D]7\}}	t|	d
krntjd
|	||<qnqnW||_||_i}
x |D]}	|	d|
|	d<qW|
|_i}x |D]}	|	d||	d<qW||_i}|j|
|j|||_|j|j|j|_d
S(s[
        @type cmd_name: C{str}
        @param cmd_name: The name of the command

        @type options: C{twisted.usage.Options}
        @param options: The C{twisted.usage.Options} instance defined
                        for this command

        @type file: C{file}
        @param file: The C{file} to write the completion function to
        tzsh_altArgDescrtzsh_actionDescrtzsh_multiUsetzsh_mutuallyExclusivetzsh_actionsR)RRiiiiN(RRRtaltArgDescrtactionDescrtmultiUsetmutuallyExclusivetactionstextrasRtaccumulateClassListtaccumulateClassDictR(t	enumeratetlenRtpadToRt	optParamstoptParams_dt
optFlags_dtupdatetoptAll_dtaddAdditionalOptionstverifyZshNamestmakeExcludesDicttexcludes(
RRRRtaCLtaCDRR@RtoptListRARBRD((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyRsZ											
		
	
	

	

cCs,|j|j|j|jdS(sf
        Write the zsh completion code to the file given to __init__
        @return: C{None}
        N(twriteHeadertwriteExtrastwriteOptionstwriteFooter(R((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyR_s


cCs|jjddS(s^
        This is the start of the code that calls _arguments
        @return: C{None}
        s_arguments -s -A "-*" \
N(RR(R((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyRLjscCs;|jj}|jx|D]}|j|q WdS(s]
        Write out zsh code for each option in this command
        @return: C{None}
        N(RDtkeystsorttwriteOpt(RtoptNamestlongname((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyRNrs

cCs>x7|jD],}|jjt||jjdq
WdS(s
        Write out the "extras" list. These are just passed verbatim to the
        _arguments call
        @return: C{None}
        s \
N(R:RRtescape(Rts((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyRM}scCs|jjddS(sj
        Write the last bit of code that finishes the call to _arguments
        @return: C{None}
        s&& return 0
N(RR(R((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyROscsfd}xHtjjjjjD]"}|jkr4||q4q4Wx>jD]3}x*|D]"}|jkrq||qqqqWqdWdS(s
        Ensure that none of the names given in zsh_* variables are typoed
        @return: C{None}
        @raise ValueError: Raised if unknown option names have been given in
                           zsh_* variables
        cstd|jfdS(NsQUnknown option name "%s" found while
examining zsh_ attributes for the %s command(t
ValueErrorR(tname(R(s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyterrsN(t	itertoolstchainR5R6R9R7RDR8(RRYRXtseq((Rs:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyRFs
cCs||jkr |j|}ng}||jkr|tkro|j|}|dk	r||j|q|q|j|n|sdSg}xE|D]=}t|dkr|jd|q|jd|qWddj|S(s
        Generate an "exclusion string" for the given option

        @type longname: C{str}
        @param longname: The long name of the option
                         (i.e. "verbose" instead of "v")

        @type buildShort: C{bool}
        @param buildShort: May be True to indicate we're building an excludes
                           string for the short option that correspondes to
                           the given long opt

        @return: The generated C{str}
        Rit-s--s(%s)t N(RHR7tFalsetgetShortOptionRtappendR>tjoin(RRTt
buildShortt
exclusionstshorttstringstoptName((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyt
excludeStrs"
c	Cs)i}x]tj|j|jD]C}y)|ddkrM|d||d<nWqtk
raqXqWi}x|jD]}xt|D]\}}g}|j|| |j||dx/|D]&}||kr|j	||qqW||kr||j|q|||<qWqvW|S(s
        @return: A C{dict} that maps each option name appearing in
        self.mutuallyExclusive to a list of those option names that
        is it mutually exclusive with (can't appear on the cmd line with)
        iiN(
RZR[R@RRt
IndexErrorR8R=textendRa(	RtlongToShortRKRHtlstRRTttmpRX((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyRGs(
cCs||jkrd|}n
d|}|j|}|dkrNd|}nd}|j|}|jdd}|jdd}d	|}||jkr|j|}n|}|j|}||jkrd
}	nd}	|j|}
|rI|j|dt	}|j
jtd||	|||f|j
jd
n|j
jtd|
|	|||f|j
jd
dS(s
        Write out the zsh code for the given argument. This is just part of the
        one big call to _arguments

        @type longname: C{str}
        @param longname: The long name of the option
            (i.e. "verbose" instead of "v")

        @return: C{None}
        s--%ss--%s=R]Rt[s\[t]s\]s[%s]t*Rcs
%s%s%s%s%ss \
N(
RBR`RtgetDescriptiontreplaceR6t	getActionR7RhtTrueRRRU(RRTt
long_fieldRetshort_fieldtdescrtdescr_fieldtactionDescr_fieldtaction_fieldtmulti_fieldtlongExclusions_fieldtshortExclusions_field((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyRRs6



	cCs}||jkrYt|j|r5|j|}n
|j|}d|j||fS||jkryd|j|SdS(s]
        Return a zsh "action" string for the given argument
        @return: C{str}
        s:%s:%ss
:%s:_filesR(R9tcallabletgetActionDescrRA(RRTtaction((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyRs)s
cCs"||jkr|j|S|SdS(sk
        Return the description to be used when this argument is completed
        @return: C{str}
        N(R6(RRT((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyR9scCs||jkr|j|Sy|j|d}Wn@tk
rqy|j|d}Wqrtk
rmd}qrXnX|dk	r|S|jdd}t|jd|d}|rt|}|dk	r|Sn|S(s]
        Return the description to be used for this argument
        @return: C{str}
        iiR]t_sopt_%sN(	R5RBtKeyErrorRARRrtgetattrRtdescrFromDoc(RRTRwtlongMangledtobj((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyRqDs$

cCs7|j|}y|dpdSWntk
r2nXdS(s[
        Return the short option letter or None
        @return: C{str} or C{None}
        iN(RDRRi(RRTRK((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyR`ds


c
Csi}tj|j|di}x>|jD]0}t|dkr/||||<||=q/q/Wx6|jD](\}}|jdd}||jkrqpn|j|}d}||kr||}n|j
jj}	|	dkr7|j
j||d|g|d|g|j|<|d|g|j|<qp|	dkr|jj|||g||g|j|<|d|g|j|<qptd|fqpWdS(s
        Add additional options to the optFlags and optParams lists.
        These will be defined by 'opt_foo' methods of the Options subclass
        @return: C{None}
        topt_iRR]is %r has wrong number of argumentsN(RtaccumulateMethodsRtcopyR>titemsRrRDRqRtim_funct	func_codetco_argcountR@RaRARRBt	TypeError(
RtmethodsDictt
methodToShortRXt
methodNamet	methodObjRTRwRetreqArgs((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyREps4
(RRRRRRLRNRMRORFR_RhRGRRRsRRqR`RE(((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyRs 	L						,	!	5			 	cCs|jdkrdS|jjd}d}yl|ddkrb|djrb|dj}n4|ddkr|djr|dj}nWntk
rnX|S(sP
    Generate an appropriate description from docstring of the given object
    s
iRiN(RRtsplittisspacetlstripRi(RtlinesRw((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyRs!!
cCs4y|jd}|| SWntk
r/|SXdS(s3
    Return the first line of the given string
    s
N(tindexRW(RVR((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyt	firstLines

cCstj|dS(s'
    Shell escape the given string
    i(tcommandstmkarg(tstr((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyRUscCs=y/d}tj|}tjj|r.|SWnnXdS(so
    Return the path to the system-wide site-functions directory or
    C{None} if it cannot be determined
    s/zsh -f -c 'echo ${(M)fpath:#/*/site-functions}'N(Rt	getoutputRR
R(tcmdtoutput((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pytsiteFunctionsPathstconchstwisted.conch.scripts.concht
ClientOptionstmktapstwisted.scripts.mktaptFirstPassOptionsttrialstwisted.scripts.trialtOptionstcftpstwisted.conch.scripts.cftpt
tapconvertstwisted.scripts.tapconverttConvertOptionsttwistdstwisted.scripts.twistdt
ServerOptionstckeygenstwisted.conch.scripts.ckeygentGeneralOptionstlorestwisted.lore.scripts.loret
pyhtmlizerstwisted.scripts.htmlizerttap2debstwisted.scripts.tap2debttkconchstwisted.conch.scripts.tkconchtmanholestwisted.scripts.manholettap2rpmstwisted.scripts.tap2rpmcCsg}x|D]\}}}|dkrGt||}|jq
nytd|fdd|}t||}t||}	||kr||||	|}
|
jnt||	|}
|
jWq
tk
r}|j||fq
q
Xq
W|S(sN
    Generate completion function files in the given directory for all
    twisted commands

    @type out_path: C{str}
    @param out_path: The path to the directory to generate completion function
                     fils in

    @param generateFor: Sequence in the form of the 'generateFor' top-level
                        variable as defined in this module. Indicates what
                        commands to build completion files for.

    @param specialBuilders: Sequence in the form of the 'specialBuilders'
                            top-level variable as defined in this module.
                            Indicates what commands require a special
                            Builder class.

    @return: C{list} of 2-tuples of the form (cmd_name, error) indicating
             commands that we skipped building completions for. cmd_name
             is the name of the skipped command, and error is the Exception
             that was raised when trying to import the script module.
             Commands are usually skipped due to a missing dependency,
             e.g. Tkinter.
    s%sN(	Rt_openCmdFiletcloset
__import__RRRt	ExceptionRa(tout_pathtgenerateFortspecialBuilderstskipsRtmodule_namet
class_nametftmtotbte((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pytmakeCompFunctionFiless&

cCs ttjj|d|dS(NRtw(RRR
Rb(RR((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyRscCst}y|jtjdWn3tjk
rV}|GH|jGHtjdnX|drddl}t	j
jt	j
j|j
dd}t|}nt|d}xE|D]=\}}tjjd|ftjjt|d	qW|rtjd
ndS(NiiRitpythontzshR	sGzshcomp: Skipped building for %s. Script module could not be imported:
s
i(RtparseOptionstsystargvRRtgetUsagetexitR#RR
Rbtdirnamet__file__RtstderrRR(RRR#tdirRRterror((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pytruns$	
't__main__( RtwarningstwarntDeprecationWarningRZRRtos.pathRttwisted.pythonRRRttwisted.application.serviceRRRRR!R.R/RRRRURRRRRRR(((s:/usr/lib/python2.7/dist-packages/twisted/python/zshcomp.pyt<module>sN
00						

2