/usr/share/doc/python-tornado-doc/html/options.html is in python-tornado-doc 4.4.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | <!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>tornado.options — Command-line parsing — Tornado 4.4.3 documentation</title>
<link rel="shortcut icon" href="_static/favicon.ico"/>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="index" title="Index"
href="genindex.html"/>
<link rel="search" title="Search" href="search.html"/>
<link rel="top" title="Tornado 4.4.3 documentation" href="index.html"/>
<link rel="up" title="Utilities" href="utilities.html"/>
<link rel="next" title="tornado.stack_context — Exception handling across asynchronous callbacks" href="stack_context.html"/>
<link rel="prev" title="tornado.log — Logging support" href="log.html"/>
<script src="_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="index.html" class="icon icon-home"> Tornado
</a>
<div class="version">
4.4.3
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="guide.html">User’s guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="webframework.html">Web framework</a></li>
<li class="toctree-l1"><a class="reference internal" href="http.html">HTTP servers and clients</a></li>
<li class="toctree-l1"><a class="reference internal" href="networking.html">Asynchronous networking</a></li>
<li class="toctree-l1"><a class="reference internal" href="coroutine.html">Coroutines and concurrency</a></li>
<li class="toctree-l1"><a class="reference internal" href="integration.html">Integration with other services</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="utilities.html">Utilities</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="autoreload.html"><code class="docutils literal"><span class="pre">tornado.autoreload</span></code> — Automatically detect code changes in development</a></li>
<li class="toctree-l2"><a class="reference internal" href="log.html"><code class="docutils literal"><span class="pre">tornado.log</span></code> — Logging support</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#"><code class="docutils literal"><span class="pre">tornado.options</span></code> — Command-line parsing</a></li>
<li class="toctree-l2"><a class="reference internal" href="stack_context.html"><code class="docutils literal"><span class="pre">tornado.stack_context</span></code> — Exception handling across asynchronous callbacks</a></li>
<li class="toctree-l2"><a class="reference internal" href="testing.html"><code class="docutils literal"><span class="pre">tornado.testing</span></code> — Unit testing support for asynchronous code</a></li>
<li class="toctree-l2"><a class="reference internal" href="util.html"><code class="docutils literal"><span class="pre">tornado.util</span></code> — General-purpose utilities</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently Asked Questions</a></li>
<li class="toctree-l1"><a class="reference internal" href="releases.html">Release notes</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">Tornado</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li><a href="utilities.html">Utilities</a> »</li>
<li><code class="docutils literal"><span class="pre">tornado.options</span></code> — Command-line parsing</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/options.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="module-tornado.options">
<span id="tornado-options-command-line-parsing"></span><h1><code class="docutils literal"><span class="pre">tornado.options</span></code> — Command-line parsing<a class="headerlink" href="#module-tornado.options" title="Permalink to this headline">¶</a></h1>
<p>A command line parsing module that lets modules define their own options.</p>
<p>Each module defines its own options which are added to the global
option namespace, e.g.:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">tornado.options</span> <span class="k">import</span> <span class="n">define</span><span class="p">,</span> <span class="n">options</span>
<span class="n">define</span><span class="p">(</span><span class="s2">"mysql_host"</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">"127.0.0.1:3306"</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"Main user DB"</span><span class="p">)</span>
<span class="n">define</span><span class="p">(</span><span class="s2">"memcache_hosts"</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">"127.0.0.1:11011"</span><span class="p">,</span> <span class="n">multiple</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">"Main user memcache servers"</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">connect</span><span class="p">():</span>
<span class="n">db</span> <span class="o">=</span> <span class="n">database</span><span class="o">.</span><span class="n">Connection</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">mysql_host</span><span class="p">)</span>
<span class="o">...</span>
</pre></div>
</div>
<p>The <code class="docutils literal"><span class="pre">main()</span></code> 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.</p>
<p>Your <code class="docutils literal"><span class="pre">main()</span></code> method can parse the command line or parse a config file with
either:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">tornado</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">parse_command_line</span><span class="p">()</span>
<span class="c1"># or</span>
<span class="n">tornado</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">parse_config_file</span><span class="p">(</span><span class="s2">"/etc/server.conf"</span><span class="p">)</span>
</pre></div>
</div>
<p>Command line formats are what you would expect (<code class="docutils literal"><span class="pre">--myoption=myvalue</span></code>).
Config files are just Python files. Global names become options, e.g.:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">myoption</span> <span class="o">=</span> <span class="s2">"myvalue"</span>
<span class="n">myotheroption</span> <span class="o">=</span> <span class="s2">"myothervalue"</span>
</pre></div>
</div>
<p>We support <a class="reference external" href="/usr/share/doc/python3-doc/html/library/datetime.html#datetime.datetime" title="(in Python v3.5)"><code class="xref py py-obj docutils literal"><span class="pre">datetimes</span></code></a>, <a class="reference external" href="/usr/share/doc/python3-doc/html/library/datetime.html#datetime.timedelta" title="(in Python v3.5)"><code class="xref py py-obj docutils literal"><span class="pre">timedeltas</span></code></a>, ints, and floats (just pass a <code class="docutils literal"><span class="pre">type</span></code> kwarg to
<a class="reference internal" href="#tornado.options.define" title="tornado.options.define"><code class="xref py py-obj docutils literal"><span class="pre">define</span></code></a>). We also accept multi-value options. See the documentation for
<a class="reference internal" href="#tornado.options.define" title="tornado.options.define"><code class="xref py py-obj docutils literal"><span class="pre">define()</span></code></a> below.</p>
<p><a class="reference internal" href="#tornado.options.options" title="tornado.options.options"><code class="xref py py-obj docutils literal"><span class="pre">tornado.options.options</span></code></a> is a singleton instance of <a class="reference internal" href="#tornado.options.OptionParser" title="tornado.options.OptionParser"><code class="xref py py-obj docutils literal"><span class="pre">OptionParser</span></code></a>, and
the top-level functions in this module (<a class="reference internal" href="#tornado.options.define" title="tornado.options.define"><code class="xref py py-obj docutils literal"><span class="pre">define</span></code></a>, <a class="reference internal" href="#tornado.options.parse_command_line" title="tornado.options.parse_command_line"><code class="xref py py-obj docutils literal"><span class="pre">parse_command_line</span></code></a>, etc)
simply call methods on it. You may create additional <a class="reference internal" href="#tornado.options.OptionParser" title="tornado.options.OptionParser"><code class="xref py py-obj docutils literal"><span class="pre">OptionParser</span></code></a>
instances to define isolated sets of options, such as for subcommands.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>By default, several options are defined that will configure the
standard <a class="reference external" href="/usr/share/doc/python3-doc/html/library/logging.html#module-logging" title="(in Python v3.5)"><code class="xref py py-obj docutils literal"><span class="pre">logging</span></code></a> module when <a class="reference internal" href="#tornado.options.parse_command_line" title="tornado.options.parse_command_line"><code class="xref py py-obj docutils literal"><span class="pre">parse_command_line</span></code></a> or <a class="reference internal" href="#tornado.options.parse_config_file" title="tornado.options.parse_config_file"><code class="xref py py-obj docutils literal"><span class="pre">parse_config_file</span></code></a>
are called. If you want Tornado to leave the logging configuration
alone so you can manage it yourself, either pass <code class="docutils literal"><span class="pre">--logging=none</span></code>
on the command line or do the following to disable it in code:</p>
<div class="last highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">tornado.options</span> <span class="k">import</span> <span class="n">options</span><span class="p">,</span> <span class="n">parse_command_line</span>
<span class="n">options</span><span class="o">.</span><span class="n">logging</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">parse_command_line</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 4.3: </span>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.</p>
</div>
<div class="section" id="global-functions">
<h2>Global functions<a class="headerlink" href="#global-functions" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="tornado.options.define">
<code class="descclassname">tornado.options.</code><code class="descname">define</code><span class="sig-paren">(</span><em>name</em>, <em>default=None</em>, <em>type=None</em>, <em>help=None</em>, <em>metavar=None</em>, <em>multiple=False</em>, <em>group=None</em>, <em>callback=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/tornado/options.html#define"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#tornado.options.define" title="Permalink to this definition">¶</a></dt>
<dd><p>Defines an option in the global namespace.</p>
<p>See <a class="reference internal" href="#tornado.options.OptionParser.define" title="tornado.options.OptionParser.define"><code class="xref py py-obj docutils literal"><span class="pre">OptionParser.define</span></code></a>.</p>
</dd></dl>
<dl class="data">
<dt id="tornado.options.options">
<code class="descclassname">tornado.options.</code><code class="descname">options</code><a class="headerlink" href="#tornado.options.options" title="Permalink to this definition">¶</a></dt>
<dd><p>Global options object. All defined options are available as attributes
on this object.</p>
</dd></dl>
<dl class="function">
<dt id="tornado.options.parse_command_line">
<code class="descclassname">tornado.options.</code><code class="descname">parse_command_line</code><span class="sig-paren">(</span><em>args=None</em>, <em>final=True</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/tornado/options.html#parse_command_line"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#tornado.options.parse_command_line" title="Permalink to this definition">¶</a></dt>
<dd><p>Parses global options from the command line.</p>
<p>See <a class="reference internal" href="#tornado.options.OptionParser.parse_command_line" title="tornado.options.OptionParser.parse_command_line"><code class="xref py py-obj docutils literal"><span class="pre">OptionParser.parse_command_line</span></code></a>.</p>
</dd></dl>
<dl class="function">
<dt id="tornado.options.parse_config_file">
<code class="descclassname">tornado.options.</code><code class="descname">parse_config_file</code><span class="sig-paren">(</span><em>path</em>, <em>final=True</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/tornado/options.html#parse_config_file"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#tornado.options.parse_config_file" title="Permalink to this definition">¶</a></dt>
<dd><p>Parses global options from a config file.</p>
<p>See <a class="reference internal" href="#tornado.options.OptionParser.parse_config_file" title="tornado.options.OptionParser.parse_config_file"><code class="xref py py-obj docutils literal"><span class="pre">OptionParser.parse_config_file</span></code></a>.</p>
</dd></dl>
<dl class="function">
<dt id="tornado.options.print_help">
<code class="descclassname">tornado.options.</code><code class="descname">print_help</code><span class="sig-paren">(</span><em>file=sys.stderr</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/tornado/options.html#print_help"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#tornado.options.print_help" title="Permalink to this definition">¶</a></dt>
<dd><p>Prints all the command line options to stderr (or another file).</p>
<p>See <a class="reference internal" href="#tornado.options.OptionParser.print_help" title="tornado.options.OptionParser.print_help"><code class="xref py py-obj docutils literal"><span class="pre">OptionParser.print_help</span></code></a>.</p>
</dd></dl>
<dl class="function">
<dt id="tornado.options.add_parse_callback">
<code class="descclassname">tornado.options.</code><code class="descname">add_parse_callback</code><span class="sig-paren">(</span><em>callback</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/tornado/options.html#add_parse_callback"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#tornado.options.add_parse_callback" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds a parse callback, to be invoked when option parsing is done.</p>
<p>See <a class="reference internal" href="#tornado.options.OptionParser.add_parse_callback" title="tornado.options.OptionParser.add_parse_callback"><code class="xref py py-obj docutils literal"><span class="pre">OptionParser.add_parse_callback</span></code></a></p>
</dd></dl>
<dl class="exception">
<dt id="tornado.options.Error">
<em class="property">exception </em><code class="descclassname">tornado.options.</code><code class="descname">Error</code><a class="reference internal" href="_modules/tornado/options.html#Error"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#tornado.options.Error" title="Permalink to this definition">¶</a></dt>
<dd><p>Exception raised by errors in the options module.</p>
</dd></dl>
</div>
<div class="section" id="optionparser-class">
<h2>OptionParser class<a class="headerlink" href="#optionparser-class" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="tornado.options.OptionParser">
<em class="property">class </em><code class="descclassname">tornado.options.</code><code class="descname">OptionParser</code><a class="reference internal" href="_modules/tornado/options.html#OptionParser"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#tornado.options.OptionParser" title="Permalink to this definition">¶</a></dt>
<dd><p>A collection of options, a dictionary with object-like access.</p>
<p>Normally accessed via static functions in the <a class="reference internal" href="#module-tornado.options" title="tornado.options"><code class="xref py py-obj docutils literal"><span class="pre">tornado.options</span></code></a> module,
which reference a global instance.</p>
<dl class="method">
<dt id="tornado.options.OptionParser.items">
<code class="descname">items</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/tornado/options.html#OptionParser.items"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#tornado.options.OptionParser.items" title="Permalink to this definition">¶</a></dt>
<dd><p>A sequence of (name, value) pairs.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.1.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="tornado.options.OptionParser.groups">
<code class="descname">groups</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/tornado/options.html#OptionParser.groups"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#tornado.options.OptionParser.groups" title="Permalink to this definition">¶</a></dt>
<dd><p>The set of option-groups created by <code class="docutils literal"><span class="pre">define</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.1.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="tornado.options.OptionParser.group_dict">
<code class="descname">group_dict</code><span class="sig-paren">(</span><em>group</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/tornado/options.html#OptionParser.group_dict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#tornado.options.OptionParser.group_dict" title="Permalink to this definition">¶</a></dt>
<dd><p>The names and values of options in a group.</p>
<p>Useful for copying options into Application settings:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">tornado.options</span> <span class="k">import</span> <span class="n">define</span><span class="p">,</span> <span class="n">parse_command_line</span><span class="p">,</span> <span class="n">options</span>
<span class="n">define</span><span class="p">(</span><span class="s1">'template_path'</span><span class="p">,</span> <span class="n">group</span><span class="o">=</span><span class="s1">'application'</span><span class="p">)</span>
<span class="n">define</span><span class="p">(</span><span class="s1">'static_path'</span><span class="p">,</span> <span class="n">group</span><span class="o">=</span><span class="s1">'application'</span><span class="p">)</span>
<span class="n">parse_command_line</span><span class="p">()</span>
<span class="n">application</span> <span class="o">=</span> <span class="n">Application</span><span class="p">(</span>
<span class="n">handlers</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="o">.</span><span class="n">group_dict</span><span class="p">(</span><span class="s1">'application'</span><span class="p">))</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.1.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="tornado.options.OptionParser.as_dict">
<code class="descname">as_dict</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/tornado/options.html#OptionParser.as_dict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#tornado.options.OptionParser.as_dict" title="Permalink to this definition">¶</a></dt>
<dd><p>The names and values of all options.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.1.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="tornado.options.OptionParser.define">
<code class="descname">define</code><span class="sig-paren">(</span><em>name</em>, <em>default=None</em>, <em>type=None</em>, <em>help=None</em>, <em>metavar=None</em>, <em>multiple=False</em>, <em>group=None</em>, <em>callback=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/tornado/options.html#OptionParser.define"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#tornado.options.OptionParser.define" title="Permalink to this definition">¶</a></dt>
<dd><p>Defines a new command line option.</p>
<p>If <code class="docutils literal"><span class="pre">type</span></code> is given (one of str, float, int, datetime, or timedelta)
or can be inferred from the <code class="docutils literal"><span class="pre">default</span></code>, we parse the command line
arguments based on the given type. If <code class="docutils literal"><span class="pre">multiple</span></code> is True, we accept
comma-separated values, and the option value is always a list.</p>
<p>For multi-value integers, we also accept the syntax <code class="docutils literal"><span class="pre">x:y</span></code>, which
turns into <code class="docutils literal"><span class="pre">range(x,</span> <span class="pre">y)</span></code> - very useful for long integer ranges.</p>
<p><code class="docutils literal"><span class="pre">help</span></code> and <code class="docutils literal"><span class="pre">metavar</span></code> are used to construct the
automatically generated command line help string. The help
message is formatted like:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="o">--</span><span class="n">name</span><span class="o">=</span><span class="n">METAVAR</span> <span class="n">help</span> <span class="n">string</span>
</pre></div>
</div>
<p><code class="docutils literal"><span class="pre">group</span></code> 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.</p>
<p>Command line option names must be unique globally. They can be parsed
from the command line with <a class="reference internal" href="#tornado.options.parse_command_line" title="tornado.options.parse_command_line"><code class="xref py py-obj docutils literal"><span class="pre">parse_command_line</span></code></a> or parsed from a
config file with <a class="reference internal" href="#tornado.options.parse_config_file" title="tornado.options.parse_config_file"><code class="xref py py-obj docutils literal"><span class="pre">parse_config_file</span></code></a>.</p>
<p>If a <code class="docutils literal"><span class="pre">callback</span></code> 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:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">define</span><span class="p">(</span><span class="s2">"config"</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">str</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"path to config file"</span><span class="p">,</span>
<span class="n">callback</span><span class="o">=</span><span class="k">lambda</span> <span class="n">path</span><span class="p">:</span> <span class="n">parse_config_file</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">final</span><span class="o">=</span><span class="kc">False</span><span class="p">))</span>
</pre></div>
</div>
<p>With this definition, options in the file specified by <code class="docutils literal"><span class="pre">--config</span></code> will
override options set earlier on the command line, but can be overridden
by later flags.</p>
</dd></dl>
<dl class="method">
<dt id="tornado.options.OptionParser.parse_command_line">
<code class="descname">parse_command_line</code><span class="sig-paren">(</span><em>args=None</em>, <em>final=True</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/tornado/options.html#OptionParser.parse_command_line"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#tornado.options.OptionParser.parse_command_line" title="Permalink to this definition">¶</a></dt>
<dd><p>Parses all options given on the command line (defaults to
<a class="reference external" href="/usr/share/doc/python3-doc/html/library/sys.html#sys.argv" title="(in Python v3.5)"><code class="xref py py-obj docutils literal"><span class="pre">sys.argv</span></code></a>).</p>
<p>Note that <code class="docutils literal"><span class="pre">args[0]</span></code> is ignored since it is the program name
in <a class="reference external" href="/usr/share/doc/python3-doc/html/library/sys.html#sys.argv" title="(in Python v3.5)"><code class="xref py py-obj docutils literal"><span class="pre">sys.argv</span></code></a>.</p>
<p>We return a list of all arguments that are not parsed as options.</p>
<p>If <code class="docutils literal"><span class="pre">final</span></code> is <code class="docutils literal"><span class="pre">False</span></code>, parse callbacks will not be run.
This is useful for applications that wish to combine configurations
from multiple sources.</p>
</dd></dl>
<dl class="method">
<dt id="tornado.options.OptionParser.parse_config_file">
<code class="descname">parse_config_file</code><span class="sig-paren">(</span><em>path</em>, <em>final=True</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/tornado/options.html#OptionParser.parse_config_file"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#tornado.options.OptionParser.parse_config_file" title="Permalink to this definition">¶</a></dt>
<dd><p>Parses and loads the Python config file at the given path.</p>
<p>If <code class="docutils literal"><span class="pre">final</span></code> is <code class="docutils literal"><span class="pre">False</span></code>, parse callbacks will not be run.
This is useful for applications that wish to combine configurations
from multiple sources.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 4.1: </span>Config files are now always interpreted as utf-8 instead of
the system default encoding.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 4.4: </span>The special variable <code class="docutils literal"><span class="pre">__file__</span></code> is available inside config
files, specifying the absolute path to the config file itself.</p>
</div>
</dd></dl>
<dl class="method">
<dt id="tornado.options.OptionParser.print_help">
<code class="descname">print_help</code><span class="sig-paren">(</span><em>file=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/tornado/options.html#OptionParser.print_help"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#tornado.options.OptionParser.print_help" title="Permalink to this definition">¶</a></dt>
<dd><p>Prints all the command line options to stderr (or another file).</p>
</dd></dl>
<dl class="method">
<dt id="tornado.options.OptionParser.add_parse_callback">
<code class="descname">add_parse_callback</code><span class="sig-paren">(</span><em>callback</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/tornado/options.html#OptionParser.add_parse_callback"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#tornado.options.OptionParser.add_parse_callback" title="Permalink to this definition">¶</a></dt>
<dd><p>Adds a parse callback, to be invoked when option parsing is done.</p>
</dd></dl>
<dl class="method">
<dt id="tornado.options.OptionParser.mockable">
<code class="descname">mockable</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/tornado/options.html#OptionParser.mockable"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#tornado.options.OptionParser.mockable" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a wrapper around self that is compatible with
<a class="reference external" href="/usr/share/doc/python3-doc/html/library/unittest.mock.html#unittest.mock.patch" title="(in Python v3.5)"><code class="xref py py-obj docutils literal"><span class="pre">mock.patch</span></code></a>.</p>
<p>The <a class="reference external" href="/usr/share/doc/python3-doc/html/library/unittest.mock.html#unittest.mock.patch" title="(in Python v3.5)"><code class="xref py py-obj docutils literal"><span class="pre">mock.patch</span></code></a> function (included in
the standard library <a class="reference external" href="/usr/share/doc/python3-doc/html/library/unittest.mock.html#module-unittest.mock" title="(in Python v3.5)"><code class="xref py py-obj docutils literal"><span class="pre">unittest.mock</span></code></a> package since Python 3.3,
or in the third-party <code class="docutils literal"><span class="pre">mock</span></code> package for older versions of
Python) is incompatible with objects like <code class="docutils literal"><span class="pre">options</span></code> that
override <code class="docutils literal"><span class="pre">__getattr__</span></code> and <code class="docutils literal"><span class="pre">__setattr__</span></code>. This function
returns an object that can be used with <a class="reference external" href="/usr/share/doc/python3-doc/html/library/unittest.mock.html#unittest.mock.patch.object" title="(in Python v3.5)"><code class="xref py py-obj docutils literal"><span class="pre">mock.patch.object</span></code></a> to modify option values:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">mock</span><span class="o">.</span><span class="n">patch</span><span class="o">.</span><span class="n">object</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">mockable</span><span class="p">(),</span> <span class="s1">'name'</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="k">assert</span> <span class="n">options</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="n">value</span>
</pre></div>
</div>
</dd></dl>
</dd></dl>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="stack_context.html" class="btn btn-neutral float-right" title="tornado.stack_context — Exception handling across asynchronous callbacks" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="log.html" class="btn btn-neutral" title="tornado.log — Logging support" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2009-2017, The Tornado Authors.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'./',
VERSION:'4.4.3',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>
|