/usr/share/doc/python-configobj-doc/html/validate.html is in python-configobj-doc 5.0.6-2.
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 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>2. Validation Schema with validate.py — configobj 5.0.6 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '5.0.6',
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>
<link rel="top" title="configobj 5.0.6 documentation" href="index.html" />
<link rel="prev" title="1. Reading and Writing Config Files" href="configobj.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="configobj.html" title="1. Reading and Writing Config Files"
accesskey="P">previous</a> |</li>
<li><a href="index.html">configobj 5.0.6 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="validation-schema-with-validate-py">
<span id="validate-doc"></span><h1><a class="toc-backref" href="#id1">2. Validation Schema with validate.py</a><a class="headerlink" href="#validation-schema-with-validate-py" title="Permalink to this headline">¶</a></h1>
<div class="section" id="using-the-validator-class">
<h2><a class="toc-backref" href="#id2">2.1. Using the Validator class</a><a class="headerlink" href="#using-the-validator-class" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Authors:</th><td class="field-body">Michael Foord, Nicola Larosa, Rob Dennis, Eli Courtwright, Mark Andrews</td>
</tr>
<tr class="field-even field"><th class="field-name">Version:</th><td class="field-body">Validate 2.0.0</td>
</tr>
<tr class="field-odd field"><th class="field-name">Date:</th><td class="field-body">2014/02/08</td>
</tr>
<tr class="field-even field"><th class="field-name">Homepage:</th><td class="field-body"><a class="reference external" href="https://github.com/DiffSK/configobj">Github Page</a></td>
</tr>
<tr class="field-odd field"><th class="field-name">License:</th><td class="field-body"><a class="reference external" href="http://opensource.org/licenses/BSD-3-Clause">BSD License</a></td>
</tr>
<tr class="field-even field"><th class="field-name">Support:</th><td class="field-body"><a class="reference external" href="http://lists.sourceforge.net/lists/listinfo/configobj-develop">Mailing List</a></td>
</tr>
</tbody>
</table>
<div class="contents topic" id="validate-manual">
<p class="topic-title first">Validate Manual</p>
<ul class="simple">
<li><a class="reference internal" href="#validation-schema-with-validate-py" id="id1">Validation Schema with validate.py</a><ul>
<li><a class="reference internal" href="#using-the-validator-class" id="id2">Using the Validator class</a><ul>
<li><a class="reference internal" href="#introduction" id="id3">Introduction</a></li>
<li><a class="reference internal" href="#downloading" id="id4">Downloading</a><ul>
<li><a class="reference internal" href="#files" id="id5">Files</a></li>
</ul>
</li>
<li><a class="reference internal" href="#the-standard-functions" id="id6">The standard functions</a></li>
<li><a class="reference internal" href="#using-validator" id="id7">Using Validator</a><ul>
<li><a class="reference internal" href="#instantiate" id="id8">Instantiate</a></li>
<li><a class="reference internal" href="#adding-functions" id="id9">Adding functions</a></li>
<li><a class="reference internal" href="#writing-the-check" id="id10">Writing the check</a></li>
<li><a class="reference internal" href="#the-check-method" id="id11">The check method</a><ul>
<li><a class="reference internal" href="#default-values" id="id12">Default Values</a></li>
<li><a class="reference internal" href="#list-values" id="id13">List Values</a></li>
</ul>
</li>
<li><a class="reference internal" href="#get-default-value" id="id14">get_default_value</a></li>
</ul>
</li>
<li><a class="reference internal" href="#validator-exceptions" id="id15">Validator Exceptions</a></li>
<li><a class="reference internal" href="#writing-check-functions" id="id16">Writing check functions</a><ul>
<li><a class="reference internal" href="#example" id="id17">Example</a></li>
</ul>
</li>
<li><a class="reference internal" href="#known-issues" id="id18">Known Issues</a></li>
<li><a class="reference internal" href="#todo" id="id19">TODO</a></li>
<li><a class="reference internal" href="#issues" id="id20">ISSUES</a></li>
<li><a class="reference internal" href="#changelog" id="id21">CHANGELOG</a><ul>
<li><a class="reference internal" href="#version-2-0-0" id="id22">2014/02/08 - Version 2.0.0</a></li>
<li><a class="reference internal" href="#version-1-0-1" id="id23">2009/10/25 - Version 1.0.1</a></li>
<li><a class="reference internal" href="#version-1-0-0" id="id24">2009/04/13 - Version 1.0.0</a></li>
<li><a class="reference internal" href="#version-0-3-2" id="id25">2008/02/24 - Version 0.3.2</a></li>
<li><a class="reference internal" href="#version-0-3-1" id="id26">2008/02/05 - Version 0.3.1</a></li>
<li><a class="reference internal" href="#version-0-3-0" id="id27">2008/02/05 - Version 0.3.0</a></li>
<li><a class="reference internal" href="#version-0-2-3" id="id28">2007/02/04 Version 0.2.3</a></li>
<li><a class="reference internal" href="#version-0-2-3-alpha1" id="id29">2006/12/17 Version 0.2.3-alpha1</a></li>
<li><a class="reference internal" href="#version-0-2-2" id="id30">2006/04/29 Version 0.2.2</a></li>
<li><a class="reference internal" href="#version-0-2-1" id="id31">2005/12/16 Version 0.2.1</a></li>
<li><a class="reference internal" href="#version-0-2-0" id="id32">2005/08/18 Version 0.2.0</a></li>
<li><a class="reference internal" href="#version-0-1-0" id="id33">2005/02/01 Version 0.1.0</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="introduction">
<h3><a class="toc-backref" href="#id3">2.1.1. Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h3>
<p>Validation is used to check that supplied values conform to a specification.</p>
<p>The value can be supplied as a string, e.g. from a config file. In this case
the check will also <em>convert</em> the value to the required type. This allows you
to add validation as a transparent layer to access data stored as strings. The
validation checks that the data is correct <em>and</em> converts it to the expected
type.</p>
<p>Checks are also strings, and are easy to write. One generic system can be used
to validate information from different sources via a single consistent
mechanism.</p>
<p>Checks look like function calls, and map to function calls. They can include
parameters and keyword arguments. These arguments are passed to the relevant
function by the <tt class="docutils literal"><span class="pre">Validator</span></tt> instance, along with the value being checked.</p>
<p>The syntax for checks also allows for specifying a default value. This default
value can be <tt class="docutils literal"><span class="pre">None</span></tt>, no matter what the type of the check. This can be used
to indicate that a value was missing, and so holds no useful value.</p>
<p>Functions either return a new value, or raise an exception. See <a class="reference internal" href="#validator-exceptions">Validator
Exceptions</a> for the low down on the exception classes that <tt class="docutils literal"><span class="pre">validate.py</span></tt>
defines.</p>
<p>Some standard functions are provided, for basic data types; these come built
into every validator. Additional checks are easy to write: they can be provided
when the <tt class="docutils literal"><span class="pre">Validator</span></tt> is instantiated, or added afterwards.</p>
<p>Validate was primarily written to support ConfigObj, but is designed to be
applicable to many other situations.</p>
<p>For support and bug reports please use the ConfigObj <a class="reference external" href="https://github.com/DiffSK/configobj">Github Page</a></p>
</div>
<div class="section" id="downloading">
<h3><a class="toc-backref" href="#id4">2.1.2. Downloading</a><a class="headerlink" href="#downloading" title="Permalink to this headline">¶</a></h3>
<p>The current version is <strong>2.0.0</strong>, dated 8th February 2014.</p>
<p>You can obtain validate in the following ways :</p>
<div class="section" id="files">
<h4><a class="toc-backref" href="#id5">2.1.2.1. Files</a><a class="headerlink" href="#files" title="Permalink to this headline">¶</a></h4>
<ul class="simple">
<li>validate.py from <a class="reference external" href="https://github.com/DiffSK/configobj">Github Page</a></li>
<li>The latest development version can be obtained from the <a class="reference external" href="https://github.com/DiffSK/configobj">Github Page</a>.</li>
</ul>
</div>
</div>
<div class="section" id="the-standard-functions">
<h3><a class="toc-backref" href="#id6">2.1.3. The standard functions</a><a class="headerlink" href="#the-standard-functions" title="Permalink to this headline">¶</a></h3>
<p>The standard functions come built-in to every <tt class="docutils literal"><span class="pre">Validator</span></tt> instance. They work
with the following basic data types :</p>
<ul class="simple">
<li>integer</li>
<li>float</li>
<li>boolean</li>
<li>string</li>
<li>ip_addr</li>
</ul>
<p>plus lists of these datatypes.</p>
<p>Adding additional checks is done through coding simple functions.</p>
<p>The full set of standard checks are :</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">‘integer’:</th><td class="field-body"><p class="first">matches integer values (including negative). Takes optional ‘min’
and ‘max’ arguments:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">integer</span><span class="p">()</span>
<span class="n">integer</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">9</span><span class="p">)</span> <span class="c"># any value from 3 to 9</span>
<span class="n">integer</span><span class="p">(</span><span class="nb">min</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> <span class="c"># any positive value</span>
<span class="n">integer</span><span class="p">(</span><span class="nb">max</span><span class="o">=</span><span class="mi">9</span><span class="p">)</span>
</pre></div>
</div>
</td>
</tr>
<tr class="field-even field"><th class="field-name">‘float’:</th><td class="field-body"><p class="first">matches float values
Has the same parameters as the integer check.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">‘boolean’:</th><td class="field-body"><dl class="first docutils">
<dt>matches boolean values: <tt class="docutils literal"><span class="pre">True</span></tt> or <tt class="docutils literal"><span class="pre">False</span></tt>.</dt>
<dd><p class="first">Acceptable string values for True are:</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="n">true</span><span class="p">,</span> <span class="n">on</span><span class="p">,</span> <span class="n">yes</span><span class="p">,</span> <span class="mi">1</span>
</pre></div>
</div>
</dd>
</dl>
<p>Acceptable string values for False are:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">false</span><span class="p">,</span> <span class="n">off</span><span class="p">,</span> <span class="n">no</span><span class="p">,</span> <span class="mi">0</span>
</pre></div>
</div>
<p>Any other value raises an error.</p>
</td>
</tr>
<tr class="field-even field"><th class="field-name">‘string’:</th><td class="field-body"><p class="first">matches any string. Takes optional keyword args ‘min’ and ‘max’ to
specify min and max length of string.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">‘ip_addr’:</th><td class="field-body"><p class="first">matches an Internet Protocol address, v.4, represented by a
dotted-quad string, i.e. ‘1.2.3.4’.</p>
</td>
</tr>
<tr class="field-even field"><th class="field-name">‘list’:</th><td class="field-body"><p class="first">matches any list. Takes optional keyword args ‘min’, and ‘max’ to
specify min and max sizes of the list. The list checks always
return a list.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">force_list:</th><td class="field-body"><p class="first">matches any list, but if a single value is passed in will
coerce it into a list containing that value. Useful for
configobj if the user forgot the trailing comma to turn
a single value into a list.</p>
</td>
</tr>
<tr class="field-even field"><th class="field-name">‘tuple’:</th><td class="field-body"><p class="first">matches any list. This check returns a tuple rather than a list.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">‘int_list’:</th><td class="field-body"><p class="first">Matches a list of integers. Takes the same arguments as list.</p>
</td>
</tr>
<tr class="field-even field"><th class="field-name">‘float_list’:</th><td class="field-body"><p class="first">Matches a list of floats. Takes the same arguments as list.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">‘bool_list’:</th><td class="field-body"><p class="first">Matches a list of boolean values. Takes the same arguments as
list.</p>
</td>
</tr>
<tr class="field-even field"><th class="field-name">‘string_list’:</th><td class="field-body"><p class="first">Matches a list of strings. Takes the same arguments as list.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">‘ip_addr_list’:</th><td class="field-body"><p class="first">Matches a list of IP addresses. Takes the same arguments as
list.</p>
</td>
</tr>
<tr class="field-even field"><th class="field-name">‘mixed_list’:</th><td class="field-body"><p class="first">Matches a list with different types in specific positions.
List size must match the number of arguments.</p>
<p>Each position can be one of:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nb">int</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="n">boolean</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="n">ip_addr</span>
</pre></div>
</div>
<p>So to specify a list with two strings followed by two integers,
you write the check as:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">mixed_list</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span>
</pre></div>
</div>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">‘pass’:</th><td class="field-body"><p class="first">matches everything: it never fails and the value is unchanged. It is
also the default if no check is specified.</p>
</td>
</tr>
<tr class="field-even field"><th class="field-name">‘option’:</th><td class="field-body"><p class="first">matches any from a list of options.
You specify this test with:</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="n">option</span><span class="p">(</span><span class="s">'option 1'</span><span class="p">,</span> <span class="s">'option 2'</span><span class="p">,</span> <span class="s">'option 3'</span><span class="p">)</span>
</pre></div>
</div>
</td>
</tr>
</tbody>
</table>
<p>The following code will work without you having to specifically add the
functions yourself.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">validate</span> <span class="kn">import</span> <span class="n">Validator</span>
<span class="c">#</span>
<span class="n">vtor</span> <span class="o">=</span> <span class="n">Validator</span><span class="p">()</span>
<span class="n">newval1</span> <span class="o">=</span> <span class="n">vtor</span><span class="o">.</span><span class="n">check</span><span class="p">(</span><span class="s">'integer'</span><span class="p">,</span> <span class="n">value1</span><span class="p">)</span>
<span class="n">newval2</span> <span class="o">=</span> <span class="n">vtor</span><span class="o">.</span><span class="n">check</span><span class="p">(</span><span class="s">'boolean'</span><span class="p">,</span> <span class="n">value2</span><span class="p">)</span>
<span class="c"># etc ...</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Of course, if these checks fail they raise exceptions. So you should wrap
them in <tt class="docutils literal"><span class="pre">try...except</span></tt> blocks. Better still, use ConfigObj for a higher
level interface.</p>
</div>
</div>
<div class="section" id="using-validator">
<h3><a class="toc-backref" href="#id7">2.1.4. Using Validator</a><a class="headerlink" href="#using-validator" title="Permalink to this headline">¶</a></h3>
<p>Using <tt class="docutils literal"><span class="pre">Validator</span></tt> is very easy. It has one public attribute and one public
method.</p>
<p>Shown below are the different steps in using <tt class="docutils literal"><span class="pre">Validator</span></tt>.</p>
<p>The only additional thing you need to know, is about <a class="reference internal" href="#writing-check-functions">Writing check
functions</a>.</p>
<div class="section" id="instantiate">
<h4><a class="toc-backref" href="#id8">2.1.4.1. Instantiate</a><a class="headerlink" href="#instantiate" title="Permalink to this headline">¶</a></h4>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">validate</span> <span class="kn">import</span> <span class="n">Validator</span>
<span class="n">vtor</span> <span class="o">=</span> <span class="n">Validator</span><span class="p">()</span>
</pre></div>
</div>
<p>or even :</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">validate</span> <span class="kn">import</span> <span class="n">Validator</span>
<span class="c">#</span>
<span class="n">fdict</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">'check_name1'</span><span class="p">:</span> <span class="n">function1</span><span class="p">,</span>
<span class="s">'check_name2'</span><span class="p">:</span> <span class="n">function2</span><span class="p">,</span>
<span class="s">'check_name3'</span><span class="p">:</span> <span class="n">function3</span><span class="p">,</span>
<span class="p">}</span>
<span class="c">#</span>
<span class="n">vtor</span> <span class="o">=</span> <span class="n">Validator</span><span class="p">(</span><span class="n">fdict</span><span class="p">)</span>
</pre></div>
</div>
<p>The second method adds a set of your functions as soon as your validator is
created. They are stored in the <tt class="docutils literal"><span class="pre">vtor.functions</span></tt> dictionary. The ‘key’ you
give them in this dictionary is the name you use in your checks (not the
original function name).</p>
<p>Dictionary keys/functions you pass in can override the built-in ones if you
want.</p>
</div>
<div class="section" id="adding-functions">
<h4><a class="toc-backref" href="#id9">2.1.4.2. Adding functions</a><a class="headerlink" href="#adding-functions" title="Permalink to this headline">¶</a></h4>
<p>The code shown above, for adding functions on instantiation, has exactly the
same effect as the following code :</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">validate</span> <span class="kn">import</span> <span class="n">Validator</span>
<span class="c">#</span>
<span class="n">vtor</span> <span class="o">=</span> <span class="n">Validator</span><span class="p">()</span>
<span class="n">vtor</span><span class="o">.</span><span class="n">functions</span><span class="p">[</span><span class="s">'check_name1'</span><span class="p">]</span> <span class="o">=</span> <span class="n">function1</span>
<span class="n">vtor</span><span class="o">.</span><span class="n">functions</span><span class="p">[</span><span class="s">'check_name2'</span><span class="p">]</span> <span class="o">=</span> <span class="n">function2</span>
<span class="n">vtor</span><span class="o">.</span><span class="n">functions</span><span class="p">[</span><span class="s">'check_name3'</span><span class="p">]</span> <span class="o">=</span> <span class="n">function3</span>
</pre></div>
</div>
<p><tt class="docutils literal"><span class="pre">vtor.functions</span></tt> is just a dictionary that maps names to functions, so we
could also have called <tt class="docutils literal"><span class="pre">vtor.functions.update(fdict)</span></tt>.</p>
</div>
<div class="section" id="writing-the-check">
<h4><a class="toc-backref" href="#id10">2.1.4.3. Writing the check</a><a class="headerlink" href="#writing-the-check" title="Permalink to this headline">¶</a></h4>
<p>As we’ve heard, the checks map to the names in the <tt class="docutils literal"><span class="pre">functions</span></tt> dictionary.
You’ve got a full list of <a class="reference internal" href="#the-standard-functions">The standard functions</a> and the arguments they
take.</p>
<p>If you’re using <tt class="docutils literal"><span class="pre">Validator</span></tt> from ConfigObj, then your checks will look like:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">keyword</span> <span class="o">=</span> <span class="n">int_list</span><span class="p">(</span><span class="nb">max</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
</pre></div>
</div>
<p>but the check part will be identical .</p>
</div>
<div class="section" id="the-check-method">
<h4><a class="toc-backref" href="#id11">2.1.4.4. The check method</a><a class="headerlink" href="#the-check-method" title="Permalink to this headline">¶</a></h4>
<p>If you’re not using <tt class="docutils literal"><span class="pre">Validator</span></tt> from ConfigObj, then you’ll need to call the
<tt class="docutils literal"><span class="pre">check</span></tt> method yourself.</p>
<p>If the check fails then it will raise an exception, so you’ll want to trap
that. Here’s the basic example :</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">validate</span> <span class="kn">import</span> <span class="n">Validator</span><span class="p">,</span> <span class="n">ValidateError</span>
<span class="c">#</span>
<span class="n">vtor</span> <span class="o">=</span> <span class="n">Validator</span><span class="p">()</span>
<span class="n">check</span> <span class="o">=</span> <span class="s">"integer(0, 9)"</span>
<span class="n">value</span> <span class="o">=</span> <span class="mi">3</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">newvalue</span> <span class="o">=</span> <span class="n">vtor</span><span class="o">.</span><span class="n">check</span><span class="p">(</span><span class="n">check</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
<span class="k">except</span> <span class="n">ValidateError</span><span class="p">:</span>
<span class="k">print</span> <span class="s">'Check Failed.'</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">print</span> <span class="s">'Check passed.'</span>
</pre></div>
</div>
<div class="admonition caution">
<p class="first admonition-title">Caution</p>
<p class="last">Although the value can be a string, if it represents a list it should
already have been turned into a list of strings.</p>
</div>
<div class="section" id="default-values">
<h5><a class="toc-backref" href="#id12">2.1.4.4.1. Default Values</a><a class="headerlink" href="#default-values" title="Permalink to this headline">¶</a></h5>
<p>Some values may not be available, and you may want to be able to specify a
default as part of the check.</p>
<p>You do this by passing the keyword <tt class="docutils literal"><span class="pre">missing=True</span></tt> to the <tt class="docutils literal"><span class="pre">check</span></tt> method, as
well as a <tt class="docutils literal"><span class="pre">default=value</span></tt> in the check. (Constructing these checks is done
automatically by ConfigObj: you only need to know about the <tt class="docutils literal"><span class="pre">default=value</span></tt>
part) :</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">check1</span> <span class="o">=</span> <span class="s">'integer(default=50)'</span>
<span class="n">check2</span> <span class="o">=</span> <span class="s">'option("val 1", "val 2", "val 3", default="val 1")'</span>
<span class="k">assert</span> <span class="n">vtor</span><span class="o">.</span><span class="n">check</span><span class="p">(</span><span class="n">check1</span><span class="p">,</span> <span class="s">''</span><span class="p">,</span> <span class="n">missing</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> <span class="o">==</span> <span class="mi">50</span>
<span class="k">assert</span> <span class="n">vtor</span><span class="o">.</span><span class="n">check</span><span class="p">(</span><span class="n">check2</span><span class="p">,</span> <span class="s">''</span><span class="p">,</span> <span class="n">missing</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> <span class="o">==</span> <span class="s">"val 1"</span>
</pre></div>
</div>
<p>If you pass in <tt class="docutils literal"><span class="pre">missing=True</span></tt> to the check method, then the actual value is
ignored. If no default is specified in the check, a <tt class="docutils literal"><span class="pre">ValidateMissingValue</span></tt>
exception is raised. If a default is specified then that is passed to the
check instead.</p>
<p>If the check has <tt class="docutils literal"><span class="pre">default=None</span></tt> (case sensitive) then <tt class="docutils literal"><span class="pre">vtor.check</span></tt> will
<em>always</em> return <tt class="docutils literal"><span class="pre">None</span></tt> (the object). This makes it easy to tell your program
that this check contains no useful value when missing, i.e. the value is
optional, and may be omitted without harm.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">As of version 0.3.0, if you specify <tt class="docutils literal"><span class="pre">default='None'</span></tt> (note the quote marks
around <tt class="docutils literal"><span class="pre">None</span></tt>) then it will be interpreted as the string <tt class="docutils literal"><span class="pre">'None'</span></tt>.</p>
</div>
</div>
<div class="section" id="list-values">
<h5><a class="toc-backref" href="#id13">2.1.4.4.2. List Values</a><a class="headerlink" href="#list-values" title="Permalink to this headline">¶</a></h5>
<p>It’s possible that you would like your default value to be a list. It’s even
possible that you will write your own check functions - and would like to pass
them keyword arguments as lists from within the check.</p>
<p>To avoid confusing syntax with commas and quotes you use a list constructor to
specify that keyword arguments are lists. This includes the <tt class="docutils literal"><span class="pre">default</span></tt> value.
This makes checks look something like:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">checkname</span><span class="p">(</span><span class="n">default</span><span class="o">=</span><span class="nb">list</span><span class="p">(</span><span class="s">'val1'</span><span class="p">,</span> <span class="s">'val2'</span><span class="p">,</span> <span class="s">'val3'</span><span class="p">))</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="get-default-value">
<h4><a class="toc-backref" href="#id14">2.1.4.5. get_default_value</a><a class="headerlink" href="#get-default-value" title="Permalink to this headline">¶</a></h4>
<p><tt class="docutils literal"><span class="pre">Validator</span></tt> instances have a <tt class="docutils literal"><span class="pre">get_default_value</span></tt> method. It takes a <tt class="docutils literal"><span class="pre">check</span></tt> string
(the same string you would pass to the <tt class="docutils literal"><span class="pre">check</span></tt> method) and returns the default value,
converted to the right type. If the check doesn’t define a default value then this method
raises a <tt class="docutils literal"><span class="pre">KeyError</span></tt>.</p>
<p>If the <tt class="docutils literal"><span class="pre">check</span></tt> has been seen before then it will have been parsed and cached already,
so this method is not expensive to call (however the conversion is done each time).</p>
</div>
</div>
<div class="section" id="validator-exceptions">
<h3><a class="toc-backref" href="#id15">2.1.5. Validator Exceptions</a><a class="headerlink" href="#validator-exceptions" title="Permalink to this headline">¶</a></h3>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If you only use Validator through ConfigObj, it traps these Exceptions for
you. You will still need to know about them for writing your own check
functions.</p>
</div>
<p><tt class="docutils literal"><span class="pre">vtor.check</span></tt> indicates that the check has failed by raising an exception.
The appropriate error should be raised in the check function.</p>
<p>The base error class is <tt class="docutils literal"><span class="pre">ValidateError</span></tt>. All errors (except for <tt class="docutils literal"><span class="pre">VdtParamError</span></tt>)
raised are sub-classes of this.</p>
<p>If an unrecognised check is specified then <tt class="docutils literal"><span class="pre">VdtUnknownCheckError</span></tt> is
raised.</p>
<p>There are also <tt class="docutils literal"><span class="pre">VdtTypeError</span></tt> and <tt class="docutils literal"><span class="pre">VdtValueError</span></tt>.</p>
<p>If incorrect parameters are passed to a check function then it will (or should)
raise <tt class="docutils literal"><span class="pre">VdtParamError</span></tt>. As this indicates <em>programmer</em> error, rather than an error
in the value, it is a subclass of <tt class="docutils literal"><span class="pre">SyntaxError</span></tt> instead of <tt class="docutils literal"><span class="pre">ValidateError</span></tt>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This means it <em>won’t</em> be caught by ConfigObj - but propagated instead.</p>
</div>
<p>If the value supplied is the wrong type, then the check should raise
<tt class="docutils literal"><span class="pre">VdtTypeError</span></tt>. e.g. the check requires the value to be an integer (or
representation of an integer) and something else was supplied.</p>
<p>If the value supplied is the right type, but an unacceptable value, then the
check should raise <tt class="docutils literal"><span class="pre">VdtValueError</span></tt>. e.g. the check requires the value to
be an integer (or representation of an integer) less than ten and a higher
value was supplied.</p>
<p>Both <tt class="docutils literal"><span class="pre">VdtTypeError</span></tt> and <tt class="docutils literal"><span class="pre">VdtValueError</span></tt> are initialised with the
incorrect value. In other words you raise them like this :</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">raise</span> <span class="n">VdtTypeError</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="c">#</span>
<span class="k">raise</span> <span class="n">VdtValueError</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
</pre></div>
</div>
<p><tt class="docutils literal"><span class="pre">VdtValueError</span></tt> has the following subclasses, which should be raised if
they are more appropriate.</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">VdtValueTooSmallError</span></tt></li>
<li><tt class="docutils literal"><span class="pre">VdtValueTooBigError</span></tt></li>
<li><tt class="docutils literal"><span class="pre">VdtValueTooShortError</span></tt></li>
<li><tt class="docutils literal"><span class="pre">VdtValueTooLongError</span></tt></li>
</ul>
</div>
<div class="section" id="writing-check-functions">
<h3><a class="toc-backref" href="#id16">2.1.6. Writing check functions</a><a class="headerlink" href="#writing-check-functions" title="Permalink to this headline">¶</a></h3>
<p>Writing check functions is easy.</p>
<p>The check function will receive the value as its first argument, followed by
any other parameters and keyword arguments.</p>
<p>If the check fails, it should raise a <tt class="docutils literal"><span class="pre">VdtTypeError</span></tt> or a
<tt class="docutils literal"><span class="pre">VdtValueError</span></tt> (or an appropriate subclass).</p>
<p>All parameters and keyword arguments are <em>always</em> passed as strings. (Parsed
from the check string).</p>
<p>The value might be a string (or list of strings) and need
converting to the right type - alternatively it might already be a list of
integers. Our function needs to be able to handle either.</p>
<p>If the check passes then it should return the value (possibly converted to the
right type).</p>
<p>And that’s it !</p>
<div class="section" id="example">
<h4><a class="toc-backref" href="#id17">2.1.6.1. Example</a><a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h4>
<p>Here is an example function that requires a list of integers. Each integer
must be between 0 and 99.</p>
<p>It takes a single argument specifying the length of the list. (Which allows us
to use the same check in more than one place). If the length can’t be converted
to an integer then we need to raise <tt class="docutils literal"><span class="pre">VdtParamError</span></tt>.</p>
<p>Next we check that the value is a list. Anything else should raise a
<tt class="docutils literal"><span class="pre">VdtTypeError</span></tt>. The list should also have ‘length’ entries. If the list
has more or less entries then we will need to raise a
<tt class="docutils literal"><span class="pre">VdtValueTooShortError</span></tt> or a <tt class="docutils literal"><span class="pre">VdtValueTooLongError</span></tt>.</p>
<p>Then we need to check every entry in the list. Each entry should be an integer
between 0 and 99, or a string representation of an integer between 0 and 99.
Any other type is a <tt class="docutils literal"><span class="pre">VdtTypeError</span></tt>, any other value is a
<tt class="docutils literal"><span class="pre">VdtValueError</span></tt> (either too big, or too small).</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">special_list</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">length</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Check that the supplied value is a list of integers,</span>
<span class="sd"> with 'length' entries, and each entry between 0 and 99.</span>
<span class="sd"> """</span>
<span class="c"># length is supplied as a string</span>
<span class="c"># we need to convert it to an integer</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">length</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">length</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">VdtParamError</span><span class="p">(</span><span class="s">'length'</span><span class="p">,</span> <span class="n">length</span><span class="p">)</span>
<span class="c">#</span>
<span class="c"># Check the supplied value is a list</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
<span class="k">raise</span> <span class="n">VdtTypeError</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="c">#</span>
<span class="c"># check the length of the list is correct</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="o">></span> <span class="n">length</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">VdtValueTooLongError</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="o"><</span> <span class="n">length</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">VdtValueTooShortError</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="c">#</span>
<span class="c"># Next, check every member in the list</span>
<span class="c"># converting strings as necessary</span>
<span class="n">out</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">entry</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">entry</span><span class="p">,</span> <span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="nb">unicode</span><span class="p">,</span> <span class="nb">int</span><span class="p">)):</span>
<span class="c"># a value in the list</span>
<span class="c"># is neither an integer nor a string</span>
<span class="k">raise</span> <span class="n">VdtTypeError</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">entry</span><span class="p">,</span> <span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="nb">unicode</span><span class="p">)):</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">entry</span><span class="o">.</span><span class="n">isdigit</span><span class="p">():</span>
<span class="k">raise</span> <span class="n">VdtTypeError</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">entry</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">entry</span><span class="p">)</span>
<span class="k">if</span> <span class="n">entry</span> <span class="o"><</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">VdtValueTooSmallError</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">entry</span> <span class="o">></span> <span class="mi">99</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">VdtValueTooBigError</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="n">out</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">entry</span><span class="p">)</span>
<span class="c">#</span>
<span class="c"># if we got this far, all is well</span>
<span class="c"># return the new list</span>
<span class="k">return</span> <span class="n">out</span>
</pre></div>
</div>
<p>If you are only using validate from ConfigObj then the error type (<em>TooBig</em>,
<em>TooSmall</em>, etc) is lost - so you may only want to raise <tt class="docutils literal"><span class="pre">VdtValueError</span></tt>.</p>
<div class="admonition caution">
<p class="first admonition-title">Caution</p>
<p>If your function raises an exception that isn’t a subclass of
<tt class="docutils literal"><span class="pre">ValidateError</span></tt>, then ConfigObj won’t trap it. This means validation will
fail.</p>
<p class="last">This is why our function starts by checking the type of the value. If we
are passed the wrong type (e.g. an integer rather than a list) we get a
<tt class="docutils literal"><span class="pre">VdtTypeError</span></tt> rather than bombing out when we try to iterate over
the value.</p>
</div>
<p>If you are using validate in another circumstance you may want to create your
own subclasses of <tt class="docutils literal"><span class="pre">ValidateError</span></tt> which convey more specific information.</p>
</div>
</div>
<div class="section" id="known-issues">
<h3><a class="toc-backref" href="#id18">2.1.7. Known Issues</a><a class="headerlink" href="#known-issues" title="Permalink to this headline">¶</a></h3>
<p>The following parses and then blows up. The resulting error message
is confusing:</p>
<blockquote>
<div><tt class="docutils literal"><span class="pre">checkname(default=list(1,</span> <span class="pre">2,</span> <span class="pre">3,</span> <span class="pre">4)</span></tt></div></blockquote>
<p>This is because it parses as: <tt class="docutils literal"><span class="pre">checkname(default="list(1",</span> <span class="pre">2,</span> <span class="pre">3,</span> <span class="pre">4)</span></tt>.
That isn’t actually unreasonable, but the error message won’t help you
work out what has happened.</p>
</div>
<div class="section" id="todo">
<h3><a class="toc-backref" href="#id19">2.1.8. TODO</a><a class="headerlink" href="#todo" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li>A regex check function ?</li>
<li>A timestamp check function ? (Using the <tt class="docutils literal"><span class="pre">parse</span></tt> function from <tt class="docutils literal"><span class="pre">DateUtil</span></tt> perhaps).</li>
</ul>
</div>
<div class="section" id="issues">
<h3><a class="toc-backref" href="#id20">2.1.9. ISSUES</a><a class="headerlink" href="#issues" title="Permalink to this headline">¶</a></h3>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Please file any bug reports to the <a class="reference external" href="https://github.com/DiffSK/configobj">Github Page</a></p>
</div>
<p>If we could pull tuples out of arguments, it would be easier
to specify arguments for ‘mixed_lists’.</p>
</div>
<div class="section" id="changelog">
<h3><a class="toc-backref" href="#id21">2.1.10. CHANGELOG</a><a class="headerlink" href="#changelog" title="Permalink to this headline">¶</a></h3>
<div class="section" id="version-2-0-0">
<h4><a class="toc-backref" href="#id22">2.1.10.1. 2014/02/08 - Version 2.0.0</a><a class="headerlink" href="#version-2-0-0" title="Permalink to this headline">¶</a></h4>
<ul class="simple">
<li>Python 3 single-source compatibility at the cost of a more restrictive set of versions: 2.6, 2.7, 3.2, 3.3 (otherwise unchanged)</li>
<li>New maintainers: Rob Dennis and Eli Courtwright</li>
<li>New home on github</li>
</ul>
</div>
<div class="section" id="version-1-0-1">
<h4><a class="toc-backref" href="#id23">2.1.10.2. 2009/10/25 - Version 1.0.1</a><a class="headerlink" href="#version-1-0-1" title="Permalink to this headline">¶</a></h4>
<ul class="simple">
<li>BUGFIX: Fixed compatibility with Python 2.3.</li>
</ul>
</div>
<div class="section" id="version-1-0-0">
<h4><a class="toc-backref" href="#id24">2.1.10.3. 2009/04/13 - Version 1.0.0</a><a class="headerlink" href="#version-1-0-0" title="Permalink to this headline">¶</a></h4>
<ul class="simple">
<li>BUGFIX: can now handle multiline strings.</li>
<li>Addition of ‘force_list’ validation option.</li>
</ul>
<p>As the API is stable and there are no known bugs or outstanding feature requests I am marking this 1.0.</p>
</div>
<div class="section" id="version-0-3-2">
<h4><a class="toc-backref" href="#id25">2.1.10.4. 2008/02/24 - Version 0.3.2</a><a class="headerlink" href="#version-0-3-2" title="Permalink to this headline">¶</a></h4>
<p>BUGFIX: Handling of None as default value fixed.</p>
</div>
<div class="section" id="version-0-3-1">
<h4><a class="toc-backref" href="#id26">2.1.10.5. 2008/02/05 - Version 0.3.1</a><a class="headerlink" href="#version-0-3-1" title="Permalink to this headline">¶</a></h4>
<p>BUGFIX: Unicode checks no longer broken.</p>
</div>
<div class="section" id="version-0-3-0">
<h4><a class="toc-backref" href="#id27">2.1.10.6. 2008/02/05 - Version 0.3.0</a><a class="headerlink" href="#version-0-3-0" title="Permalink to this headline">¶</a></h4>
<p>Improved performance with a parse cache.</p>
<p>New <tt class="docutils literal"><span class="pre">get_default_value</span></tt> method. Given a check it returns the default
value (converted to the correct type) or raises a <tt class="docutils literal"><span class="pre">KeyError</span></tt> if the
check doesn’t specify a default.</p>
<p>Added ‘tuple’ check and corresponding ‘is_tuple’ function (which always returns a tuple).</p>
<p>BUGFIX: A quoted ‘None’ as a default value is no longer treated as None,
but as the string ‘None’.</p>
<p>BUGFIX: We weren’t unquoting keyword arguments of length two, so an
empty string didn’t work as a default.</p>
<p>BUGFIX: Strings no longer pass the ‘is_list’ check. Additionally, the
list checks always return lists.</p>
<p>A couple of documentation bug fixes.</p>
<p>Removed CHANGELOG from module.</p>
</div>
<div class="section" id="version-0-2-3">
<h4><a class="toc-backref" href="#id28">2.1.10.7. 2007/02/04 Version 0.2.3</a><a class="headerlink" href="#version-0-2-3" title="Permalink to this headline">¶</a></h4>
<p>Release of 0.2.3</p>
</div>
<div class="section" id="version-0-2-3-alpha1">
<h4><a class="toc-backref" href="#id29">2.1.10.8. 2006/12/17 Version 0.2.3-alpha1</a><a class="headerlink" href="#version-0-2-3-alpha1" title="Permalink to this headline">¶</a></h4>
<p>By Nicola Larosa</p>
<p>Fixed validate doc to talk of <tt class="docutils literal"><span class="pre">boolean</span></tt> instead of <tt class="docutils literal"><span class="pre">bool</span></tt>; changed the
<tt class="docutils literal"><span class="pre">is_bool</span></tt> function to <tt class="docutils literal"><span class="pre">is_boolean</span></tt> (Sourceforge bug #1531525).</p>
</div>
<div class="section" id="version-0-2-2">
<h4><a class="toc-backref" href="#id30">2.1.10.9. 2006/04/29 Version 0.2.2</a><a class="headerlink" href="#version-0-2-2" title="Permalink to this headline">¶</a></h4>
<p>Addressed bug where a string would pass the <tt class="docutils literal"><span class="pre">is_list</span></tt> test. (Thanks to
Konrad Wojas.)</p>
</div>
<div class="section" id="version-0-2-1">
<h4><a class="toc-backref" href="#id31">2.1.10.10. 2005/12/16 Version 0.2.1</a><a class="headerlink" href="#version-0-2-1" title="Permalink to this headline">¶</a></h4>
<p>Fixed bug so we can handle keyword argument values with commas.</p>
<p>We now use a list constructor for passing list values to keyword arguments
(including <tt class="docutils literal"><span class="pre">default</span></tt>):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">default</span><span class="o">=</span><span class="nb">list</span><span class="p">(</span><span class="s">"val"</span><span class="p">,</span> <span class="s">"val"</span><span class="p">,</span> <span class="s">"val"</span><span class="p">)</span>
</pre></div>
</div>
<p>Added the <tt class="docutils literal"><span class="pre">_test</span></tt> test.</p>
<p>Moved a function call outside a try...except block.</p>
</div>
<div class="section" id="version-0-2-0">
<h4><a class="toc-backref" href="#id32">2.1.10.11. 2005/08/18 Version 0.2.0</a><a class="headerlink" href="#version-0-2-0" title="Permalink to this headline">¶</a></h4>
<p>Updated by Michael Foord and Nicola Larosa</p>
<p>Does type conversion as well.</p>
</div>
<div class="section" id="version-0-1-0">
<h4><a class="toc-backref" href="#id33">2.1.10.12. 2005/02/01 Version 0.1.0</a><a class="headerlink" href="#version-0-1-0" title="Permalink to this headline">¶</a></h4>
<p>Initial version developed by Michael Foord and Mark Andrews.</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">2. Validation Schema with validate.py</a><ul>
<li><a class="reference internal" href="#using-the-validator-class">2.1. Using the Validator class</a><ul>
<li><a class="reference internal" href="#introduction">2.1.1. Introduction</a></li>
<li><a class="reference internal" href="#downloading">2.1.2. Downloading</a><ul>
<li><a class="reference internal" href="#files">2.1.2.1. Files</a></li>
</ul>
</li>
<li><a class="reference internal" href="#the-standard-functions">2.1.3. The standard functions</a></li>
<li><a class="reference internal" href="#using-validator">2.1.4. Using Validator</a><ul>
<li><a class="reference internal" href="#instantiate">2.1.4.1. Instantiate</a></li>
<li><a class="reference internal" href="#adding-functions">2.1.4.2. Adding functions</a></li>
<li><a class="reference internal" href="#writing-the-check">2.1.4.3. Writing the check</a></li>
<li><a class="reference internal" href="#the-check-method">2.1.4.4. The check method</a><ul>
<li><a class="reference internal" href="#default-values">2.1.4.4.1. Default Values</a></li>
<li><a class="reference internal" href="#list-values">2.1.4.4.2. List Values</a></li>
</ul>
</li>
<li><a class="reference internal" href="#get-default-value">2.1.4.5. get_default_value</a></li>
</ul>
</li>
<li><a class="reference internal" href="#validator-exceptions">2.1.5. Validator Exceptions</a></li>
<li><a class="reference internal" href="#writing-check-functions">2.1.6. Writing check functions</a><ul>
<li><a class="reference internal" href="#example">2.1.6.1. Example</a></li>
</ul>
</li>
<li><a class="reference internal" href="#known-issues">2.1.7. Known Issues</a></li>
<li><a class="reference internal" href="#todo">2.1.8. TODO</a></li>
<li><a class="reference internal" href="#issues">2.1.9. ISSUES</a></li>
<li><a class="reference internal" href="#changelog">2.1.10. CHANGELOG</a><ul>
<li><a class="reference internal" href="#version-2-0-0">2.1.10.1. 2014/02/08 - Version 2.0.0</a></li>
<li><a class="reference internal" href="#version-1-0-1">2.1.10.2. 2009/10/25 - Version 1.0.1</a></li>
<li><a class="reference internal" href="#version-1-0-0">2.1.10.3. 2009/04/13 - Version 1.0.0</a></li>
<li><a class="reference internal" href="#version-0-3-2">2.1.10.4. 2008/02/24 - Version 0.3.2</a></li>
<li><a class="reference internal" href="#version-0-3-1">2.1.10.5. 2008/02/05 - Version 0.3.1</a></li>
<li><a class="reference internal" href="#version-0-3-0">2.1.10.6. 2008/02/05 - Version 0.3.0</a></li>
<li><a class="reference internal" href="#version-0-2-3">2.1.10.7. 2007/02/04 Version 0.2.3</a></li>
<li><a class="reference internal" href="#version-0-2-3-alpha1">2.1.10.8. 2006/12/17 Version 0.2.3-alpha1</a></li>
<li><a class="reference internal" href="#version-0-2-2">2.1.10.9. 2006/04/29 Version 0.2.2</a></li>
<li><a class="reference internal" href="#version-0-2-1">2.1.10.10. 2005/12/16 Version 0.2.1</a></li>
<li><a class="reference internal" href="#version-0-2-0">2.1.10.11. 2005/08/18 Version 0.2.0</a></li>
<li><a class="reference internal" href="#version-0-1-0">2.1.10.12. 2005/02/01 Version 0.1.0</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="configobj.html"
title="previous chapter">1. Reading and Writing Config Files</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/validate.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="configobj.html" title="1. Reading and Writing Config Files"
>previous</a> |</li>
<li><a href="index.html">configobj 5.0.6 documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2014, Michael Foord, Nicola Larosa, Rob Dennis, Eli Courtwright.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
</div>
</body>
</html>
|