%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib64/python2.7/site-packages/tornado/
Upload File :
Create Path :
Current File : //lib64/python2.7/site-packages/tornado/options.pyc

�
��L]c@�sydZddlmZmZmZmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
mZddlmZddlmZddlmZmZdefd	��YZd
efd��YZdefd
��YZdefd��YZe�Zeeeeeeed�Zee d�Z!e d�Z"ed�Z#d�Z$ee�dS(s�A command line parsing module that lets modules define their own options.

Each module defines its own options which are added to the global
option namespace, e.g.::

    from tornado.options import define, options

    define("mysql_host", default="127.0.0.1:3306", help="Main user DB")
    define("memcache_hosts", default="127.0.0.1:11011", multiple=True,
           help="Main user memcache servers")

    def connect():
        db = database.Connection(options.mysql_host)
        ...

The ``main()`` method of your application does not need to be aware of all of
the options used throughout your program; they are all automatically loaded
when the modules are loaded.  However, all modules that define options
must have been imported before the command line is parsed.

Your ``main()`` method can parse the command line or parse a config file with
either::

    tornado.options.parse_command_line()
    # or
    tornado.options.parse_config_file("/etc/server.conf")

Command line formats are what you would expect (``--myoption=myvalue``).
Config files are just Python files. Global names become options, e.g.::

    myoption = "myvalue"
    myotheroption = "myothervalue"

We support `datetimes <datetime.datetime>`, `timedeltas
<datetime.timedelta>`, ints, and floats (just pass a ``type`` kwarg to
`define`). We also accept multi-value options. See the documentation for
`define()` below.

`tornado.options.options` is a singleton instance of `OptionParser`, and
the top-level functions in this module (`define`, `parse_command_line`, etc)
simply call methods on it.  You may create additional `OptionParser`
instances to define isolated sets of options, such as for subcommands.

.. note::

   By default, several options are defined that will configure the
   standard `logging` module when `parse_command_line` or `parse_config_file`
   are called.  If you want Tornado to leave the logging configuration
   alone so you can manage it yourself, either pass ``--logging=none``
   on the command line or do the following to disable it in code::

       from tornado.options import options, parse_command_line
       options.logging = None
       parse_command_line()
i(tabsolute_importtdivisiontprint_functiontwith_statementN(t_unicodet
native_str(tdefine_logging_options(t
stack_context(tbasestring_typetexec_intErrorcB�seZdZRS(s1Exception raised by errors in the options module.(t__name__t
__module__t__doc__(((s5/usr/lib64/python2.7/site-packages/tornado/options.pyR
WstOptionParsercB�s�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zdddde
ddd
�Zded�Zed�Zdd
�Zd�Zd�Zd�Zd�ZRS(s�A collection of options, a dictionary with object-like access.

    Normally accessed via static functions in the `tornado.options` module,
    which reference a global instance.
    cC�s@i|jd<g|jd<|jddtddd|j�dS(Nt_optionst_parse_callbacksthelpttypesshow this help informationtcallback(t__dict__tdefinetboolt_help_callback(tself((s5/usr/lib64/python2.7/site-packages/tornado/options.pyt__init__bs

cC�s@t|jj|�t�r,|j|j�Std|��dS(NsUnrecognized option %r(t
isinstanceRtgett_OptiontvaluetAttributeError(Rtname((s5/usr/lib64/python2.7/site-packages/tornado/options.pyt__getattr__iscC�sCt|jj|�t�r/|j|j|�Std|��dS(NsUnrecognized option %r(RRRRtsetR(RRR((s5/usr/lib64/python2.7/site-packages/tornado/options.pyt__setattr__nscC�s
t|j�S(N(titerR(R((s5/usr/lib64/python2.7/site-packages/tornado/options.pyt__iter__sscC�s|j|j�S(N(RR(Rtitem((s5/usr/lib64/python2.7/site-packages/tornado/options.pyt__getitem__vscC�s2g|jj�D]\}}||j�f^qS(sJA sequence of (name, value) pairs.

        .. versionadded:: 3.1
        (RtitemsR(RRtopt((s5/usr/lib64/python2.7/site-packages/tornado/options.pyR'yscC�std�|jj�D��S(sWThe set of option-groups created by ``define``.

        .. versionadded:: 3.1
        cs�s|]}|jVqdS(N(t
group_name(t.0R(((s5/usr/lib64/python2.7/site-packages/tornado/options.pys	<genexpr>�s(R!Rtvalues(R((s5/usr/lib64/python2.7/site-packages/tornado/options.pytgroups�sc�s#t�fd�|jj�D��S(s�The names and values of options in a group.

        Useful for copying options into Application settings::

            from tornado.options import define, parse_command_line, options

            define('template_path', group='application')
            define('static_path', group='application')

            parse_command_line()

            application = Application(
                handlers, **options.group_dict('application'))

        .. versionadded:: 3.1
        c3�s=|]3\}}�s%�|jkr||j�fVqdS(N(R)R(R*RR((tgroup(s5/usr/lib64/python2.7/site-packages/tornado/options.pys	<genexpr>�s	(tdictRR'(RR-((R-s5/usr/lib64/python2.7/site-packages/tornado/options.pyt
group_dict�scC�std�|jj�D��S(sLThe names and values of all options.

        .. versionadded:: 3.1
        cs�s'|]\}}||j�fVqdS(N(R(R*RR(((s5/usr/lib64/python2.7/site-packages/tornado/options.pys	<genexpr>�s(R.RR'(R((s5/usr/lib64/python2.7/site-packages/tornado/options.pytas_dict�sc	
C�s7||jkr2td||j|jf��ntjd�}	|	jj}
|	jjj|
kr�|	jjjdkr�|	j}	n|	jjj}||
kr�d}n|d
kr�|r�|d
k	r�|j
}q�t}n|r�|}n|}t|d|d|d|d|d	|d
|d|d|�|j|<d
S(s;Defines a new command line option.

        If ``type`` is given (one of str, float, int, datetime, or timedelta)
        or can be inferred from the ``default``, we parse the command line
        arguments based on the given type. If ``multiple`` is True, we accept
        comma-separated values, and the option value is always a list.

        For multi-value integers, we also accept the syntax ``x:y``, which
        turns into ``range(x, y)`` - very useful for long integer ranges.

        ``help`` and ``metavar`` are used to construct the
        automatically generated command line help string. The help
        message is formatted like::

           --name=METAVAR      help string

        ``group`` is used to group the defined options in logical
        groups. By default, command line options are grouped by the
        file in which they are defined.

        Command line option names must be unique globally. They can be parsed
        from the command line with `parse_command_line` or parsed from a
        config file with `parse_config_file`.

        If a ``callback`` is given, it will be run with the new value whenever
        the option is changed.  This can be used to combine command-line
        and file-based options::

            define("config", type=str, help="path to config file",
                   callback=lambda path: parse_config_file(path, final=False))

        With this definition, options in the file specified by ``--config`` will
        override options set earlier on the command line, but can be overridden
        by later flags.
        sOption %r already defined in %siRtt	file_nametdefaultRRtmetavartmultipleR)RN(
RR
R2tsyst	_getframetf_codetco_filenametf_backtco_nametNonet	__class__tstrR(
RRR3RRR4R5R-Rtframetoptions_fileR2R)((s5/usr/lib64/python2.7/site-packages/tornado/options.pyR�s.%			c
C�sL|d	krtj}ng}xtdt|��D]�}||jd�s[||}Pn||dkr}||d}Pn||jd�}|jd�\}}}|jdd�}||j	kr�|j
�td|��n|j	|}	|s$|	jt
krd}q$td|��n|	j|�q4W|rH|j�n|S(
s�Parses all options given on the command line (defaults to
        `sys.argv`).

        Note that ``args[0]`` is ignored since it is the program name
        in `sys.argv`.

        We return a list of all arguments that are not parsed as options.

        If ``final`` is ``False``, parse callbacks will not be run.
        This is useful for applications that wish to combine configurations
        from multiple sources.
        it-s--t=t_s$Unrecognized command line option: %rttruesOption %r requires a valueN(R<R6targvtrangetlent
startswithtlstript	partitiontreplaceRt
print_helpR
RRtparsetrun_parse_callbacks(
Rtargstfinalt	remainingtitargRtequalsRtoption((s5/usr/lib64/python2.7/site-packages/tornado/options.pytparse_command_line�s2



	
cC�s�i}t|d��#}tt|j��||�WdQXx8|D]0}||jkrA|j|j||�qAqAW|r�|j�ndS(s�Parses and loads the Python config file at the given path.

        If ``final`` is ``False``, parse callbacks will not be run.
        This is useful for applications that wish to combine configurations
        from multiple sources.

        .. versionchanged:: 4.1
           Config files are now always interpreted as utf-8 instead of
           the system default encoding.
        trbN(topenR	RtreadRR!RN(RtpathRPtconfigtfR((s5/usr/lib64/python2.7/site-packages/tornado/options.pytparse_config_files"
c

C�s�|dkrtj}ntdtjdd|�tdd|�i}x3|jj�D]"}|j|jg�j	|�qYWxjt
|j��D]V\}}|r�tdtj
j|�d|�n|jdd��x|D]}|j}|jr
|d|j7}n|jpd	}|jdk	rN|jd	krN|d
|j7}ntj|d�}t|�d
ks�t|�dkr�|jdd	�ntd||dfd|�x,|dD] }	tdd|	fd|�q�Wq�Wq�Wtd|�dS(s@Prints all the command line options to stderr (or another file).sUsage: %s [OPTIONS]itfiles

Options:
s

%s options:
tkeycS�s|jS(N(R(RU((s5/usr/lib64/python2.7/site-packages/tornado/options.pyt<lambda>4sRBR1s
 (default %s)iOi#is  --%-30s %sis%-34s %st Ni,(R<R6tstderrtprintRERR+t
setdefaultR)tappendtsortedR'tosRZtnormpathtsortRR4RR3ttextwraptwrapRGtinsert(
RR^tby_groupRUtfilenametotprefixtdescriptiontlinestline((s5/usr/lib64/python2.7/site-packages/tornado/options.pyRL's2 #
		$&cC�s$|r |j�tjd�ndS(Ni(RLR6texit(RR((s5/usr/lib64/python2.7/site-packages/tornado/options.pyRDs
cC�s|jjtj|��dS(sAAdds a parse callback, to be invoked when option parsing is done.N(RReRRk(RR((s5/usr/lib64/python2.7/site-packages/tornado/options.pytadd_parse_callbackIscC�sx|jD]
}|�q
WdS(N(R(RR((s5/usr/lib64/python2.7/site-packages/tornado/options.pyRNMscC�s
t|�S(s�Returns a wrapper around self that is compatible with
        `mock.patch <unittest.mock.patch>`.

        The `mock.patch <unittest.mock.patch>` function (included in
        the standard library `unittest.mock` package since Python 3.3,
        or in the third-party ``mock`` package for older versions of
        Python) is incompatible with objects like ``options`` that
        override ``__getattr__`` and ``__setattr__``.  This function
        returns an object that can be used with `mock.patch.object
        <unittest.mock.patch.object>` to modify option values::

            with mock.patch.object(options.mockable(), 'name', value):
                assert options.name == value
        (t	_Mockable(R((s5/usr/lib64/python2.7/site-packages/tornado/options.pytmockableQsN(RRR
RR R"R$R&R'R,R/R0R<tFalseRtTrueRVR]RLRRuRNRw(((s5/usr/lib64/python2.7/site-packages/tornado/options.pyR\s&									B+			RvcB�s2eZdZd�Zd�Zd�Zd�ZRS(s`mock.patch` compatible wrapper for `OptionParser`.

    As of ``mock`` version 1.0.1, when an object uses ``__getattr__``
    hooks instead of ``__dict__``, ``patch.__exit__`` tries to delete
    the attribute it set instead of setting a new one (assuming that
    the object does not catpure ``__setattr__``, so the patch
    created a new attribute in ``__dict__``).

    _Mockable's getattr and setattr pass through to the underlying
    OptionParser, and delattr undoes the effect of a previous setattr.
    cC�s||jd<i|jd<dS(NRt
_originals(R(Rtoptions((s5/usr/lib64/python2.7/site-packages/tornado/options.pyRos
cC�st|j|�S(N(tgetattrR(RR((s5/usr/lib64/python2.7/site-packages/tornado/options.pyR tscC�sK||jkstd��t|j|�|j|<t|j||�dS(Nsdon't reuse mockable objects(RztAssertionErrorR|Rtsetattr(RRR((s5/usr/lib64/python2.7/site-packages/tornado/options.pyR"wscC�s#t|j||jj|��dS(N(R~RRztpop(RR((s5/usr/lib64/python2.7/site-packages/tornado/options.pyt__delattr__|s(RRR
RR R"R�(((s5/usr/lib64/python2.7/site-packages/tornado/options.pyRvcs
			Rc
B�s*eZe�Zd%ed%d%ed%d%d%d�Zd�Zd�Z	d�Z
dddddd	d
ddd
g
Zd�ZddgfdddgfdddgfddgfddgfddgfddgfgZ
ed�e
D��Zd Zejd!eej�Zd"�Zd#�Zd$�ZRS(&c

C�s||dkr|rg}n||_||_||_||_||_||_||_|	|_||_	t
j|_dS(N(
R<RRRR4R5R2R)RR3RtUNSETt_value(
RRR3RRR4R5R2R)R((s5/usr/lib64/python2.7/site-packages/tornado/options.pyR�s										cC�s |jtjkr|jS|jS(N(R�RR�R3(R((s5/usr/lib64/python2.7/site-packages/tornado/options.pyR�scC�s7i|jtj6|jtj6|jt6|jt6j|j	|j	�}|j
r�g|_x�|jd�D]�}t
|j	tj�r�|jd�\}}}||�}|r�||�n|}|jjt||d��qh|jj||��qhWn||�|_|jdk	r-|j|j�n|j�S(Nt,t:i(t_parse_datetimetdatetimet_parse_timedeltat	timedeltat_parse_boolRt
_parse_stringRRRR5R�tsplitt
issubclasstnumberstIntegralRJtextendRFReRR<R(RRt_parsetparttloRCthi((s5/usr/lib64/python2.7/site-packages/tornado/options.pyRM�s&



		 cC�s|jr�t|t�s:td|j|jjf��nx�|D]G}|dk	rAt||j�rAtd|j|jjf��qAqAWnJ|dk	r�t||j�r�td|j|jjt|�f��n||_|j	dk	r|j	|j�ndS(Ns(Option %r is required to be a list of %ss+Option %r is required to be a %s (%s given)(
R5RtlistR
RRRR<R�R(RRR%((s5/usr/lib64/python2.7/site-packages/tornado/options.pyR!�s	
#%	s%a %b %d %H:%M:%S %Ys%Y-%m-%d %H:%M:%Ss%Y-%m-%d %H:%Ms%Y-%m-%dT%H:%Ms%Y%m%d %H:%M:%Ss%Y%m%d %H:%Ms%Y-%m-%ds%Y%m%ds%H:%M:%Ss%H:%McC�sSx<|jD]1}ytjj||�SWq
tk
r:q
Xq
Wtd|��dS(Ns!Unrecognized date/time format: %r(t_DATETIME_FORMATSR�tstrptimet
ValueErrorR
(RRtformat((s5/usr/lib64/python2.7/site-packages/tornado/options.pyR��s
thoursthtminutestmtmintsecondststsectmillisecondstmstmicrosecondstustdaystdtweekstwcc�s.|]$\}}|D]}||fVqqdS(N((R*tfulltabbrevstabbrev((s5/usr/lib64/python2.7/site-packages/tornado/options.pys	<genexpr>�s	s-[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?s\s*(%s)\s*(\w*)\s*cC�s�y�tj�}d}x�|t|�kr�|jj||�}|sQt��nt|jd��}|jd�pxd}|jj	||�}|tji||6�7}|j
�}qW|SWntk
r��nXdS(NiiiR�(R�R�RGt_TIMEDELTA_PATTERNtmatcht	ExceptiontfloatR-t_TIMEDELTA_ABBREV_DICTRtend(RRtsumtstartR�tnumtunits((s5/usr/lib64/python2.7/site-packages/tornado/options.pyR��s
cC�s|j�dkS(Ntfalset0R\(R�R�R\(tlower(RR((s5/usr/lib64/python2.7/site-packages/tornado/options.pyR��scC�s
t|�S(N(R(RR((s5/usr/lib64/python2.7/site-packages/tornado/options.pyR��sN(RRtobjectR�R<RRxRRRMR!R�R�t_TIMEDELTA_ABBREVSR.R�t_FLOAT_PATTERNtretcompilet
IGNORECASER�R�R�R�(((s5/usr/lib64/python2.7/site-packages/tornado/options.pyR�sB										cC�s7tj|d|d|d|d|d|d|d|�S(sODefines an option in the global namespace.

    See `OptionParser.define`.
    R3RRR4R5R-R(R{R(RR3RRR4R5R-R((s5/usr/lib64/python2.7/site-packages/tornado/options.pyRscC�stj|d|�S(s]Parses global options from the command line.

    See `OptionParser.parse_command_line`.
    RP(R{RV(RORP((s5/usr/lib64/python2.7/site-packages/tornado/options.pyRVscC�stj|d|�S(sYParses global options from a config file.

    See `OptionParser.parse_config_file`.
    RP(R{R](RZRP((s5/usr/lib64/python2.7/site-packages/tornado/options.pyR]scC�s
tj|�S(siPrints all the command line options to stderr (or another file).

    See `OptionParser.print_help`.
    (R{RL(R^((s5/usr/lib64/python2.7/site-packages/tornado/options.pyRL"scC�stj|�dS(sqAdds a parse callback, to be invoked when option parsing is done.

    See `OptionParser.add_parse_callback`
    N(R{Ru(R((s5/usr/lib64/python2.7/site-packages/tornado/options.pyRu*s(%R
t
__future__RRRRR�R�R�R6RgRjttornado.escapeRRttornado.logRttornadoRttornado.utilRR	R�R
R�RRvRR{R<RxRRyRVR]RLRu(((s5/usr/lib64/python2.7/site-packages/tornado/options.pyt<module>Fs0"��	
		

Zerion Mini Shell 1.0