File: //lib64/python3.6/site-packages/tornado/__pycache__/options.cpython-36.pyc
3
��fRc � @ s| d Z ddlZddlZddlZddlZddlZddlZddlmZm Z ddl
mZ ddlm
Z
mZ ddlZddlmZmZmZmZmZmZmZmZmZ ejr�ddlmZ G dd � d e�ZG d
d� de�ZG dd
� d
e�ZG dd� de�Z e� Z!d!e"ee#e"e"e$e"eegdf dd� dd�Z%d"ee" e$ee" d�dd�Z&d#e"e$dd�dd�Z'd$edd�dd�Z(eg df dd�dd �Z)ee!� dS )%a A command line parsing module that lets modules define their own options.
This module is inspired by Google's `gflags
<https://github.com/google/python-gflags>`_. The primary difference
with libraries such as `argparse` is that a global registry is used so
that options may be defined in any module (it also enables
`tornado.log` by default). The rest of Tornado does not depend on this
module, so feel free to use `argparse` or other configuration
libraries if you prefer them.
Options must be defined with `tornado.options.define` before use,
generally at the top level of a module. The options are then
accessible as attributes of `tornado.options.options`::
# myapp/db.py
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)
...
# myapp/server.py
from tornado.options import define, options
define("port", default=8080, help="port to listen on")
def start_server():
app = make_app()
app.listen(options.port)
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 `parse_command_line` or `parse_config_file`::
import myapp.db, myapp.server
import tornado.options
if __name__ == '__main__':
tornado.options.parse_command_line()
# or
tornado.options.parse_config_file("/etc/server.conf")
.. note::
When using multiple ``parse_*`` functions, pass ``final=False`` to all
but the last one, or side effects may occur twice (in particular,
this can result in log messages being doubled).
`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()
.. versionchanged:: 4.3
Dashes and underscores are fully interchangeable in option names;
options can be defined, set, and read with any mix of the two.
Dashes are typical for command-line usage while config files require
underscores.
� N)�_unicode�
native_str)�define_logging_options)�basestring_type�exec_in) �Any�Iterator�Iterable�Tuple�Set�Dict�Callable�List�TextIO)�Optionalc @ s e Zd ZdZdS )�Errorz1Exception raised by errors in the options module.N)�__name__�
__module__�__qualname__�__doc__� r r �/usr/lib64/python3.6/options.pyr r s r c @ s� e Zd ZdZdd�dd�Zeed�dd�Zeed�d d
�Zeedd�dd
�Z e
d�dd�Zeed�dd�Z
eed�dd�Zeedd�dd�Zeeeef d�dd�Zee d�dd�Zeeeef d�dd�Zeeef d�dd�Zd8eeeeeeeeegdf dd � d!d"�Zd9ee eee d$�d%d&�Zd:eedd'�d(d)�Zd;edd*�d+d,�Zedd-�d.d/�Z eg df dd0�d1d2�Z!dd�d3d4�Z"d5d�d6d7�Z#dS )<�OptionParserz�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.
N)�returnc C s, i | j d<