This file is indexed.

/usr/share/doc/docutils-doc/docs/peps/pep-0258.html is in docutils-doc 0.12+dfsg-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
 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
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
<?xml version="1.0" encoding="utf-8" ?>
<!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" xml:lang="en" lang="en">
<!--
This HTML is auto-generated.  DO NOT EDIT THIS FILE!  If you are writing a new
PEP, see http://www.python.org/dev/peps/pep-0001 for instructions and links
to templates.  DO NOT USE THIS HTML FILE AS YOUR TEMPLATE!
-->
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="generator" content="Docutils 0.12: http://docutils.sourceforge.net/" />
  <title>PEP 258 -- Docutils Design Specification</title>
  <link rel="stylesheet" href="../../css/pep.css" type="text/css" />
</head>
<body bgcolor="white">
<table class="navigation" cellpadding="0" cellspacing="0"
       width="100%" border="0">
<tr><td class="navicon" width="150" height="35">
<a href="http://www.python.org/" title="Python Home Page">
[Python]</a></td>
<td class="textlinks" align="left">
[<b><a href="http://www.python.org/">Python Home</a></b>]
[<b><a href="http://www.python.org/dev/peps/">PEP Index</a></b>]
[<b><a href="./pep-0258.txt">PEP Source</a></b>]
</td></tr></table>
<div class="document">
<table class="rfc2822 docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">PEP:</th><td class="field-body">258</td>
</tr>
<tr class="field"><th class="field-name">Title:</th><td class="field-body">Docutils Design Specification</td>
</tr>
<tr class="field"><th class="field-name">Version:</th><td class="field-body">6154</td>
</tr>
<tr class="field"><th class="field-name">Last-Modified:</th><td class="field-body"><a class="reference external" href="http://svn.python.org/view/*checkout*/peps/trunk/pep-0258.txt">2009-10-05 21:08:10 +0200 (Mon, 05. Okt 2009)</a></td>
</tr>
<tr class="field"><th class="field-name">Author:</th><td class="field-body">David Goodger &lt;goodger&#32;&#97;t&#32;python.org&gt;</td>
</tr>
<tr class="field"><th class="field-name">Discussions-To:</th><td class="field-body">&lt;<a class="reference external" href="mailto:doc-sig&#64;python.org?subject=PEP%20258">doc-sig&#32;&#97;t&#32;python.org</a>&gt;</td>
</tr>
<tr class="field"><th class="field-name">Status:</th><td class="field-body">Draft</td>
</tr>
<tr class="field"><th class="field-name">Type:</th><td class="field-body">Standards Track</td>
</tr>
<tr class="field"><th class="field-name">Content-Type:</th><td class="field-body"><a class="reference external" href="http://www.python.org/dev/peps/pep-0012">text/x-rst</a></td>
</tr>
<tr class="field"><th class="field-name">Requires:</th><td class="field-body"><a class="reference external" href="http://www.python.org/dev/peps/pep-0256">256</a> <a class="reference external" href="http://www.python.org/dev/peps/pep-0257">257</a></td>
</tr>
<tr class="field"><th class="field-name">Created:</th><td class="field-body">31-May-2001</td>
</tr>
<tr class="field"><th class="field-name">Post-History:</th><td class="field-body">13-Jun-2001</td>
</tr>
</tbody>
</table>
<hr />
<div class="contents topic" id="contents">
<p class="topic-title first">Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#abstract" id="id22">Abstract</a></li>
<li><a class="reference internal" href="#specification" id="id23">Specification</a><ul>
<li><a class="reference internal" href="#docutils-project-model" id="id24">Docutils Project Model</a><ul>
<li><a class="reference internal" href="#publisher" id="id25">Publisher</a></li>
<li><a class="reference internal" href="#readers" id="id26">Readers</a></li>
<li><a class="reference internal" href="#parsers" id="id27">Parsers</a></li>
<li><a class="reference internal" href="#transformer" id="id28">Transformer</a></li>
<li><a class="reference internal" href="#writers" id="id29">Writers</a></li>
<li><a class="reference internal" href="#input-output" id="id30">Input/Output</a></li>
</ul>
</li>
<li><a class="reference internal" href="#docutils-package-structure" id="id31">Docutils Package Structure</a></li>
<li><a class="reference internal" href="#front-end-tools" id="id32">Front-End Tools</a></li>
<li><a class="reference internal" href="#document-tree" id="id33">Document Tree</a></li>
<li><a class="reference internal" href="#error-handling" id="id34">Error Handling</a></li>
<li><a class="reference internal" href="#python-source-reader" id="id35">Python Source Reader</a><ul>
<li><a class="reference internal" href="#processing-model" id="id36">Processing Model</a></li>
<li><a class="reference internal" href="#ast-mining" id="id37">AST Mining</a></li>
<li><a class="reference internal" href="#docstring-extraction-rules" id="id38">Docstring Extraction Rules</a><ul>
<li><a class="reference internal" href="#attribute-docstrings" id="id39">Attribute Docstrings</a></li>
<li><a class="reference internal" href="#additional-docstrings" id="id40">Additional Docstrings</a></li>
</ul>
</li>
<li><a class="reference internal" href="#choice-of-docstring-format" id="id41">Choice of Docstring Format</a></li>
<li><a class="reference internal" href="#identifier-cross-references" id="id42">Identifier Cross-References</a></li>
<li><a class="reference internal" href="#stylist-transforms" id="id43">Stylist Transforms</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#references-and-footnotes" id="id44">References and Footnotes</a></li>
<li><a class="reference internal" href="#project-web-site" id="id45">Project Web Site</a></li>
<li><a class="reference internal" href="#copyright" id="id46">Copyright</a></li>
<li><a class="reference internal" href="#acknowledgements" id="id47">Acknowledgements</a></li>
</ul>
</div>
<div class="section" id="abstract">
<h1><a class="toc-backref" href="#id22">Abstract</a></h1>
<p>This PEP documents design issues and implementation details for
Docutils, a Python Docstring Processing System (DPS).  The rationale
and high-level concepts of a DPS are documented in <a class="reference external" href="http://www.python.org/dev/peps/pep-0256">PEP 256</a>, &quot;Docstring
Processing System Framework&quot; <a class="footnote-reference" href="#pep-256" id="id1">[1]</a>.  Also see <a class="reference external" href="http://www.python.org/dev/peps/pep-0256">PEP 256</a> for a
&quot;Road Map to the Docstring PEPs&quot;.</p>
<p>Docutils is being designed modularly so that any of its components can
be replaced easily.  In addition, Docutils is not limited to the
processing of Python docstrings; it processes standalone documents as
well, in several contexts.</p>
<p>No changes to the core Python language are required by this PEP.  Its
deliverables consist of a package for the standard library and its
documentation.</p>
</div>
<div class="section" id="specification">
<h1><a class="toc-backref" href="#id23">Specification</a></h1>
<div class="section" id="docutils-project-model">
<h2><a class="toc-backref" href="#id24">Docutils Project Model</a></h2>
<p>Project components and data flow:</p>
<pre class="literal-block">
                 +---------------------------+
                 |        Docutils:          |
                 | docutils.core.Publisher,  |
                 | docutils.core.publish_*() |
                 +---------------------------+
                  /            |            \
                 /             |             \
        1,3,5   /        6     |              \ 7
       +--------+       +-------------+       +--------+
       | READER | ----&gt; | TRANSFORMER | ====&gt; | WRITER |
       +--------+       +-------------+       +--------+
        /     \\                                  |
       /       \\                                 |
 2    /      4  \\                             8  |
+-------+   +--------+                        +--------+
| INPUT |   | PARSER |                        | OUTPUT |
+-------+   +--------+                        +--------+
</pre>
<p>The numbers above each component indicate the path a document's data
takes.  Double-width lines between Reader &amp; Parser and between
Transformer &amp; Writer indicate that data sent along these paths should
be standard (pure &amp; unextended) Docutils doc trees.  Single-width
lines signify that internal tree extensions or completely unrelated
representations are possible, but they must be supported at both ends.</p>
<div class="section" id="publisher">
<h3><a class="toc-backref" href="#id25">Publisher</a></h3>
<p>The <tt class="docutils literal">docutils.core</tt> module contains a &quot;Publisher&quot; facade class and
several convenience functions: &quot;publish_cmdline()&quot; (for command-line
front ends), &quot;publish_file()&quot; (for programmatic use with file-like
I/O), and &quot;publish_string()&quot; (for programmatic use with string I/O).
The Publisher class encapsulates the high-level logic of a Docutils
system.  The Publisher class has overall responsibility for
processing, controlled by the <tt class="docutils literal">Publisher.publish()</tt> method:</p>
<ol class="arabic simple">
<li>Set up internal settings (may include config files &amp; command-line
options) and I/O objects.</li>
<li>Call the Reader object to read data from the source Input object
and parse the data with the Parser object.  A document object is
returned.</li>
<li>Set up and apply transforms via the Transformer object attached to
the document.</li>
<li>Call the Writer object which translates the document to the final
output format and writes the formatted data to the destination
Output object.  Depending on the Output object, the output may be
returned from the Writer, and then from the <tt class="docutils literal">publish()</tt> method.</li>
</ol>
<p>Calling the &quot;publish&quot; function (or instantiating a &quot;Publisher&quot; object)
with component names will result in default behavior.  For custom
behavior (customizing component settings), create custom component
objects first, and pass <em>them</em> to the Publisher or <tt class="docutils literal">publish_*</tt>
convenience functions.</p>
</div>
<div class="section" id="readers">
<h3><a class="toc-backref" href="#id26">Readers</a></h3>
<p>Readers understand the input context (where the data is coming from),
send the whole input or discrete &quot;chunks&quot; to the parser, and provide
the context to bind the chunks together back into a cohesive whole.</p>
<p>Each reader is a module or package exporting a &quot;Reader&quot; class with a
&quot;read&quot; method.  The base &quot;Reader&quot; class can be found in the
<tt class="docutils literal">docutils/readers/__init__.py</tt> module.</p>
<p>Most Readers will have to be told what parser to use.  So far (see the
list of examples below), only the Python Source Reader (&quot;PySource&quot;;
still incomplete) will be able to determine the parser on its own.</p>
<p>Responsibilities:</p>
<ul class="simple">
<li>Get input text from the source I/O.</li>
<li>Pass the input text to the parser, along with a fresh <a class="reference internal" href="#document-tree">document
tree</a> root.</li>
</ul>
<p>Examples:</p>
<ul>
<li><p class="first">Standalone (Raw/Plain): Just read a text file and process it.
The reader needs to be told which parser to use.</p>
<p>The &quot;Standalone Reader&quot; has been implemented in module
<tt class="docutils literal">docutils.readers.standalone</tt>.</p>
</li>
<li><p class="first">Python Source: See <a class="reference internal" href="#python-source-reader">Python Source Reader</a> below.  This Reader is
currently in development in the Docutils sandbox.</p>
</li>
<li><p class="first">Email: <a class="reference external" href="http://www.faqs.org/rfcs/rfc822.html">RFC-822</a> headers, quoted excerpts, signatures, MIME parts.</p>
</li>
<li><p class="first">PEP: <a class="reference external" href="http://www.faqs.org/rfcs/rfc822.html">RFC-822</a> headers, &quot;PEP xxxx&quot; and &quot;RFC xxxx&quot; conversion to URIs.
The &quot;PEP Reader&quot; has been implemented in module
<tt class="docutils literal">docutils.readers.pep</tt>; see <a class="reference external" href="http://www.python.org/dev/peps/pep-0287">PEP 287</a> and <a class="reference external" href="http://www.python.org/dev/peps/pep-0012">PEP 12</a>.</p>
</li>
<li><p class="first">Wiki: Global reference lookups of &quot;wiki links&quot; incorporated into
transforms.  (CamelCase only or unrestricted?)  Lazy
indentation?</p>
</li>
<li><p class="first">Web Page: As standalone, but recognize meta fields as meta tags.
Support for templates of some sort?  (After <tt class="docutils literal">&lt;body&gt;</tt>, before
<tt class="docutils literal">&lt;/body&gt;</tt>?)</p>
</li>
<li><p class="first">FAQ: Structured &quot;question &amp; answer(s)&quot; constructs.</p>
</li>
<li><p class="first">Compound document: Merge chapters into a book.  Master manifest
file?</p>
</li>
</ul>
</div>
<div class="section" id="parsers">
<h3><a class="toc-backref" href="#id27">Parsers</a></h3>
<p>Parsers analyze their input and produce a Docutils <a class="reference internal" href="#document-tree">document tree</a>.
They don't know or care anything about the source or destination of
the data.</p>
<p>Each input parser is a module or package exporting a &quot;Parser&quot; class
with a &quot;parse&quot; method.  The base &quot;Parser&quot; class can be found in the
<tt class="docutils literal">docutils/parsers/__init__.py</tt> module.</p>
<p>Responsibilities: Given raw input text and a doctree root node,
populate the doctree by parsing the input text.</p>
<p>Example: The only parser implemented so far is for the
reStructuredText markup.  It is implemented in the
<tt class="docutils literal">docutils/parsers/rst/</tt> package.</p>
<p>The development and integration of other parsers is possible and
encouraged.</p>
</div>
<div class="section" id="transformer">
<span id="transforms"></span><h3><a class="toc-backref" href="#id28">Transformer</a></h3>
<p>The Transformer class, in <tt class="docutils literal">docutils/transforms/__init__.py</tt>, stores
transforms and applies them to documents.  A transformer object is
attached to every new document tree.  The <a class="reference internal" href="#publisher">Publisher</a> calls
<tt class="docutils literal">Transformer.apply_transforms()</tt> to apply all stored transforms to
the document tree.  Transforms change the document tree from one form
to another, add to the tree, or prune it.  Transforms resolve
references and footnote numbers, process interpreted text, and do
other context-sensitive processing.</p>
<p>Some transforms are specific to components (Readers, Parser, Writers,
Input, Output).  Standard component-specific transforms are specified
in the <tt class="docutils literal">default_transforms</tt> attribute of component classes.  After
the Reader has finished processing, the <a class="reference internal" href="#publisher">Publisher</a> calls
<tt class="docutils literal">Transformer.populate_from_components()</tt> with a list of components
and all default transforms are stored.</p>
<p>Each transform is a class in a module in the <tt class="docutils literal">docutils/transforms/</tt>
package, a subclass of <tt class="docutils literal">docutils.tranforms.Transform</tt>.  Transform
classes each have a <tt class="docutils literal">default_priority</tt> attribute which is used by
the Transformer to apply transforms in order (low to high).  The
default priority can be overridden when adding transforms to the
Transformer object.</p>
<p>Transformer responsibilities:</p>
<ul class="simple">
<li>Apply transforms to the document tree, in priority order.</li>
<li>Store a mapping of component type name ('reader', 'writer', etc.) to
component objects.  These are used by certain transforms (such as
&quot;components.Filter&quot;) to determine suitability.</li>
</ul>
<p>Transform responsibilities:</p>
<ul class="simple">
<li>Modify a doctree in-place, either purely transforming one structure
into another, or adding new structures based on the doctree and/or
external data.</li>
</ul>
<p>Examples of transforms (in the <tt class="docutils literal">docutils/transforms/</tt> package):</p>
<ul class="simple">
<li>frontmatter.DocInfo: Conversion of document metadata (bibliographic
information).</li>
<li>references.AnonymousHyperlinks: Resolution of anonymous references
to corresponding targets.</li>
<li>parts.Contents: Generates a table of contents for a document.</li>
<li>document.Merger: Combining multiple populated doctrees into one.
(Not yet implemented or fully understood.)</li>
<li>document.Splitter: Splits a document into a tree-structure of
subdocuments, perhaps by section.  It will have to transform
references appropriately.  (Neither implemented not remotely
understood.)</li>
<li>components.Filter: Includes or excludes elements which depend on a
specific Docutils component.</li>
</ul>
</div>
<div class="section" id="writers">
<h3><a class="toc-backref" href="#id29">Writers</a></h3>
<p>Writers produce the final output (HTML, XML, TeX, etc.).  Writers
translate the internal <a class="reference internal" href="#document-tree">document tree</a> structure into the final data
format, possibly running Writer-specific <a class="reference internal" href="#transforms">transforms</a> first.</p>
<p>By the time the document gets to the Writer, it should be in final
form.  The Writer's job is simply (and only) to translate from the
Docutils doctree structure to the target format.  Some small
transforms may be required, but they should be local and
format-specific.</p>
<p>Each writer is a module or package exporting a &quot;Writer&quot; class with a
&quot;write&quot; method.  The base &quot;Writer&quot; class can be found in the
<tt class="docutils literal">docutils/writers/__init__.py</tt> module.</p>
<p>Responsibilities:</p>
<ul class="simple">
<li>Translate doctree(s) into specific output formats.<ul>
<li>Transform references into format-native forms.</li>
</ul>
</li>
<li>Write the translated output to the destination I/O.</li>
</ul>
<p>Examples:</p>
<ul class="simple">
<li>XML: Various forms, such as:<ul>
<li>Docutils XML (an expression of the internal document tree,
implemented as <tt class="docutils literal">docutils.writers.docutils_xml</tt>).</li>
<li>DocBook (being implemented in the Docutils sandbox).</li>
</ul>
</li>
<li>HTML (XHTML implemented as <tt class="docutils literal">docutils.writers.html4css1</tt>).</li>
<li>PDF (a ReportLabs interface is being developed in the Docutils
sandbox).</li>
<li>TeX (a LaTeX Writer is being implemented in the sandbox).</li>
<li>Docutils-native pseudo-XML (implemented as
<tt class="docutils literal">docutils.writers.pseudoxml</tt>, used for testing).</li>
<li>Plain text</li>
<li>reStructuredText?</li>
</ul>
</div>
<div class="section" id="input-output">
<h3><a class="toc-backref" href="#id30">Input/Output</a></h3>
<p>I/O classes provide a uniform API for low-level input and output.
Subclasses will exist for a variety of input/output mechanisms.
However, they can be considered an implementation detail.  Most
applications should be satisfied using one of the convenience
functions associated with the <a class="reference internal" href="#publisher">Publisher</a>.</p>
<p>I/O classes are currently in the preliminary stages; there's a lot of
work yet to be done.  Issues:</p>
<ul class="simple">
<li>How to represent multi-file input (files &amp; directories) in the API?</li>
<li>How to represent multi-file output?  Perhaps &quot;Writer&quot; variants, one
for each output distribution type?  Or Output objects with
associated transforms?</li>
</ul>
<p>Responsibilities:</p>
<ul class="simple">
<li>Read data from the input source (Input objects) or write data to the
output destination (Output objects).</li>
</ul>
<p>Examples of input sources:</p>
<ul class="simple">
<li>A single file on disk or a stream (implemented as
<tt class="docutils literal">docutils.io.FileInput</tt>).</li>
<li>Multiple files on disk (<tt class="docutils literal">MultiFileInput</tt>?).</li>
<li>Python source files: modules and packages.</li>
<li>Python strings, as received from a client application
(implemented as <tt class="docutils literal">docutils.io.StringInput</tt>).</li>
</ul>
<p>Examples of output destinations:</p>
<ul class="simple">
<li>A single file on disk or a stream (implemented as
<tt class="docutils literal">docutils.io.FileOutput</tt>).</li>
<li>A tree of directories and files on disk.</li>
<li>A Python string, returned to a client application (implemented as
<tt class="docutils literal">docutils.io.StringOutput</tt>).</li>
<li>No output; useful for programmatic applications where only a portion
of the normal output is to be used (implemented as
<tt class="docutils literal">docutils.io.NullOutput</tt>).</li>
<li>A single tree-shaped data structure in memory.</li>
<li>Some other set of data structures in memory.</li>
</ul>
</div>
</div>
<div class="section" id="docutils-package-structure">
<h2><a class="toc-backref" href="#id31">Docutils Package Structure</a></h2>
<ul>
<li><p class="first">Package &quot;docutils&quot;.</p>
<ul>
<li><p class="first">Module &quot;__init__.py&quot; contains: class &quot;Component&quot;, a base class for
Docutils components; class &quot;SettingsSpec&quot;, a base class for
specifying runtime settings (used by docutils.frontend); and class
&quot;TransformSpec&quot;, a base class for specifying transforms.</p>
</li>
<li><p class="first">Module &quot;docutils.core&quot; contains facade class &quot;Publisher&quot; and
convenience functions.  See <a class="reference internal" href="#publisher">Publisher</a> above.</p>
</li>
<li><p class="first">Module &quot;docutils.frontend&quot; provides runtime settings support, for
programmatic use and front-end tools (including configuration file
support, and command-line argument and option processing).</p>
</li>
<li><p class="first">Module &quot;docutils.io&quot; provides a uniform API for low-level input
and output.  See <a class="reference internal" href="#input-output">Input/Output</a> above.</p>
</li>
<li><p class="first">Module &quot;docutils.nodes&quot; contains the Docutils document tree
element class library plus tree-traversal Visitor pattern base
classes.  See <a class="reference internal" href="#document-tree">Document Tree</a> below.</p>
</li>
<li><p class="first">Module &quot;docutils.statemachine&quot; contains a finite state machine
specialized for regular-expression-based text filters and parsers.
The reStructuredText parser implementation is based on this
module.</p>
</li>
<li><p class="first">Module &quot;docutils.urischemes&quot; contains a mapping of known URI
schemes (&quot;http&quot;, &quot;ftp&quot;, &quot;mail&quot;, etc.).</p>
</li>
<li><p class="first">Module &quot;docutils.utils&quot; contains utility functions and classes,
including a logger class (&quot;Reporter&quot;; see <a class="reference internal" href="#error-handling">Error Handling</a>
below).</p>
</li>
<li><p class="first">Package &quot;docutils.parsers&quot;: markup <a class="reference internal" href="#parsers">parsers</a>.</p>
<ul class="simple">
<li>Function &quot;get_parser_class(parser_name)&quot; returns a parser module
by name.  Class &quot;Parser&quot; is the base class of specific parsers.
(<tt class="docutils literal">docutils/parsers/__init__.py</tt>)</li>
<li>Package &quot;docutils.parsers.rst&quot;: the reStructuredText parser.</li>
<li>Alternate markup parsers may be added.</li>
</ul>
<p>See <a class="reference internal" href="#parsers">Parsers</a> above.</p>
</li>
<li><p class="first">Package &quot;docutils.readers&quot;: context-aware input readers.</p>
<ul class="simple">
<li>Function &quot;get_reader_class(reader_name)&quot; returns a reader module
by name or alias.  Class &quot;Reader&quot; is the base class of specific
readers.  (<tt class="docutils literal">docutils/readers/__init__.py</tt>)</li>
<li>Module &quot;docutils.readers.standalone&quot; reads independent document
files.</li>
<li>Module &quot;docutils.readers.pep&quot; reads PEPs (Python Enhancement
Proposals).</li>
<li>Module &quot;docutils.readers.doctree&quot; is used to re-read a
previously stored document tree for reprocessing.</li>
<li>Readers to be added for: Python source code (structure &amp;
docstrings), email, FAQ, and perhaps Wiki and others.</li>
</ul>
<p>See <a class="reference internal" href="#readers">Readers</a> above.</p>
</li>
<li><p class="first">Package &quot;docutils.writers&quot;: output format writers.</p>
<ul class="simple">
<li>Function &quot;get_writer_class(writer_name)&quot; returns a writer module
by name.  Class &quot;Writer&quot; is the base class of specific writers.
(<tt class="docutils literal">docutils/writers/__init__.py</tt>)</li>
<li>Package &quot;docutils.writers.html4css1&quot; is a simple HyperText
Markup Language document tree writer for HTML 4.01 and CSS1.</li>
<li>Package &quot;docutils.writers.pep_html&quot; generates HTML from
reStructuredText PEPs.</li>
<li>Package &quot;docutils.writers.s5_html&quot; generates S5/HTML slide
shows.</li>
<li>Package &quot;docutils.writers.latex2e&quot; writes LaTeX.</li>
<li>Package &quot;docutils.writers.newlatex2e&quot; also writes LaTeX; it is a
new implementation.</li>
<li>Module &quot;docutils.writers.docutils_xml&quot; writes the internal
document tree in XML form.</li>
<li>Module &quot;docutils.writers.pseudoxml&quot; is a simple internal
document tree writer; it writes indented pseudo-XML.</li>
<li>Module &quot;docutils.writers.null&quot; is a do-nothing writer; it is
used for specialized purposes such as storing the internal
document tree.</li>
<li>Writers to be added: HTML 3.2 or 4.01-loose, XML (various forms,
such as DocBook), PDF, plaintext, reStructuredText, and perhaps
others.</li>
</ul>
<p>Subpackages of &quot;docutils.writers&quot; contain modules and data files
(such as stylesheets) that support the individual writers.</p>
<p>See <a class="reference internal" href="#writers">Writers</a> above.</p>
</li>
<li><p class="first">Package &quot;docutils.transforms&quot;: tree transform classes.</p>
<ul class="simple">
<li>Class &quot;Transformer&quot; stores transforms and applies them to
document trees.  (<tt class="docutils literal">docutils/transforms/__init__.py</tt>)</li>
<li>Class &quot;Transform&quot; is the base class of specific transforms.
(<tt class="docutils literal">docutils/transforms/__init__.py</tt>)</li>
<li>Each module contains related transform classes.</li>
</ul>
<p>See <a class="reference internal" href="#transforms">Transforms</a> above.</p>
</li>
<li><p class="first">Package &quot;docutils.languages&quot;: Language modules contain
language-dependent strings and mappings.  They are named for their
language identifier (as defined in <a class="reference internal" href="#choice-of-docstring-format">Choice of Docstring Format</a>
below), converting dashes to underscores.</p>
<ul class="simple">
<li>Function &quot;get_language(language_code)&quot;, returns matching
language module.  (<tt class="docutils literal">docutils/languages/__init__.py</tt>)</li>
<li>Modules: en.py (English), de.py (German), fr.py (French), it.py
(Italian), sk.py (Slovak), sv.py (Swedish).</li>
<li>Other languages to be added.</li>
</ul>
</li>
</ul>
</li>
<li><p class="first">Third-party modules: &quot;extras&quot; directory.  These modules are
installed only if they're not already present in the Python
installation.</p>
<ul class="simple">
<li><tt class="docutils literal">extras/roman.py</tt> contains Roman numeral conversion routines.</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="front-end-tools">
<h2><a class="toc-backref" href="#id32">Front-End Tools</a></h2>
<p>The <tt class="docutils literal">tools/</tt> directory contains several front ends for common
Docutils processing.  See <a class="reference external" href="http://docutils.sourceforge.net/docs/user/tools.html">Docutils Front-End Tools</a> <a class="footnote-reference" href="#id4" id="id5">[4]</a> for details.</p>
</div>
<div class="section" id="document-tree">
<h2><a class="toc-backref" href="#id33">Document Tree</a></h2>
<p>A single intermediate data structure is used internally by Docutils,
in the interfaces between components; it is defined in the
<tt class="docutils literal">docutils.nodes</tt> module.  It is not required that this data
structure be used <em>internally</em> by any of the components, just
<em>between</em> components as outlined in the diagram in the <a class="reference internal" href="#docutils-project-model">Docutils
Project Model</a> above.</p>
<p>Custom node types are allowed, provided that either (a) a transform
converts them to standard Docutils nodes before they reach the Writer
proper, or (b) the custom node is explicitly supported by certain
Writers, and is wrapped in a filtered &quot;pending&quot; node.  An example of
condition (a) is the <a class="reference internal" href="#python-source-reader">Python Source Reader</a> (see below), where a
&quot;stylist&quot; transform converts custom nodes.  The HTML <tt class="docutils literal">&lt;meta&gt;</tt> tag is
an example of condition (b); it is supported by the HTML Writer but
not by others.  The reStructuredText &quot;meta&quot; directive creates a
&quot;pending&quot; node, which contains knowledge that the embedded &quot;meta&quot; node
can only be handled by HTML-compatible writers.  The &quot;pending&quot; node is
resolved by the <tt class="docutils literal">docutils.transforms.components.Filter</tt> transform,
which checks that the calling writer supports HTML; if it doesn't, the
&quot;pending&quot; node (and enclosed &quot;meta&quot; node) is removed from the
document.</p>
<p>The document tree data structure is similar to a DOM tree, but with
specific node names (classes) instead of DOM's generic nodes. The
schema is documented in an XML DTD (eXtensible Markup Language
Document Type Definition), which comes in two parts:</p>
<ul class="simple">
<li>the Docutils Generic DTD, <a class="reference external" href="http://docutils.sourceforge.net/docs/ref/docutils.dtd">docutils.dtd</a> <a class="footnote-reference" href="#id6" id="id7">[5]</a>, and</li>
<li>the OASIS Exchange Table Model, <a class="reference external" href="http://docutils.sourceforge.net/docs/ref/soextblx.dtd">soextbl.dtd</a> <a class="footnote-reference" href="#id8" id="id9">[6]</a>.</li>
</ul>
<p>The DTD defines a rich set of elements, suitable for many input and
output formats.  The DTD retains all information necessary to
reconstruct the original input text, or a reasonable facsimile
thereof.</p>
<p>See <a class="reference external" href="http://docutils.sourceforge.net/docs/ref/doctree.html">The Docutils Document Tree</a> <a class="footnote-reference" href="#id10" id="id11">[7]</a> for details (incomplete).</p>
</div>
<div class="section" id="error-handling">
<h2><a class="toc-backref" href="#id34">Error Handling</a></h2>
<p>When the parser encounters an error in markup, it inserts a system
message (DTD element &quot;system_message&quot;).  There are five levels of
system messages:</p>
<ul class="simple">
<li>Level-0, &quot;DEBUG&quot;: an internal reporting issue.  There is no effect
on the processing.  Level-0 system messages are handled separately
from the others.</li>
<li>Level-1, &quot;INFO&quot;: a minor issue that can be ignored.  There is little
or no effect on the processing.  Typically level-1 system messages
are not reported.</li>
<li>Level-2, &quot;WARNING&quot;: an issue that should be addressed.  If ignored,
there may be minor problems with the output.  Typically level-2
system messages are reported but do not halt processing.</li>
<li>Level-3, &quot;ERROR&quot;: a major issue that should be addressed.  If
ignored, the output will contain unpredictable errors.  Typically
level-3 system messages are reported but do not halt processing.</li>
<li>Level-4, &quot;SEVERE&quot;: a critical error that must be addressed.
Typically level-4 system messages are turned into exceptions which
do halt processing.  If ignored, the output will contain severe
errors.</li>
</ul>
<p>Although the initial message levels were devised independently, they
have a strong correspondence to <a class="reference external" href="http://www.openvms.compaq.com:8000/73final/5841/841pro_027.html#error_cond_severity">VMS error condition severity
levels</a> <a class="footnote-reference" href="#id12" id="id13">[8]</a>; the names in quotes for levels 1 through 4 were borrowed
from VMS.  Error handling has since been influenced by the <a class="reference external" href="http://logging.apache.org/log4j/docs/index.html">log4j
project</a> <a class="footnote-reference" href="#id14" id="id15">[9]</a>.</p>
</div>
<div class="section" id="python-source-reader">
<h2><a class="toc-backref" href="#id35">Python Source Reader</a></h2>
<p>The Python Source Reader (&quot;PySource&quot;) is the Docutils component that
reads Python source files, extracts docstrings in context, then
parses, links, and assembles the docstrings into a cohesive whole.  It
is a major and non-trivial component, currently under experimental
development in the Docutils sandbox.  High-level design issues are
presented here.</p>
<div class="section" id="processing-model">
<h3><a class="toc-backref" href="#id36">Processing Model</a></h3>
<p>This model will evolve over time, incorporating experience and
discoveries.</p>
<ol class="arabic simple">
<li>The PySource Reader uses an Input class to read in Python packages
and modules, into a tree of strings.</li>
<li>The Python modules are parsed, converting the tree of strings into
a tree of abstract syntax trees with docstring nodes.</li>
<li>The abstract syntax trees are converted into an internal
representation of the packages/modules.  Docstrings are extracted,
as well as code structure details.  See <a class="reference internal" href="#ast-mining">AST Mining</a> below.
Namespaces are constructed for lookup in step 6.</li>
<li>One at a time, the docstrings are parsed, producing standard
Docutils doctrees.</li>
<li>PySource assembles all the individual docstrings' doctrees into a
Python-specific custom Docutils tree paralleling the
package/module/class structure; this is a custom Reader-specific
internal representation (see the <a class="reference external" href="http://docutils.sourceforge.net/docs/dev/pysource.dtd">Docutils Python Source DTD</a> <a class="footnote-reference" href="#id16" id="id17">[10]</a>).
Namespaces must be merged: Python identifiers, hyperlink targets.</li>
<li>Cross-references from docstrings (interpreted text) to Python
identifiers are resolved according to the Python namespace lookup
rules.  See <a class="reference internal" href="#identifier-cross-references">Identifier Cross-References</a> below.</li>
<li>A &quot;Stylist&quot; transform is applied to the custom doctree (by the
<a class="reference internal" href="#transformer">Transformer</a>), custom nodes are rendered using standard nodes as
primitives, and a standard document tree is emitted.  See <a class="reference internal" href="#stylist-transforms">Stylist
Transforms</a> below.</li>
<li>Other transforms are applied to the standard doctree by the
<a class="reference internal" href="#transformer">Transformer</a>.</li>
<li>The standard doctree is sent to a Writer, which translates the
document into a concrete format (HTML, PDF, etc.).</li>
<li>The Writer uses an Output class to write the resulting data to its
destination (disk file, directories and files, etc.).</li>
</ol>
</div>
<div class="section" id="ast-mining">
<h3><a class="toc-backref" href="#id37">AST Mining</a></h3>
<p>Abstract Syntax Tree mining code will be written (or adapted) that
scans a parsed Python module, and returns an ordered tree containing
the names, docstrings (including attribute and additional docstrings;
see below), and additional info (in parentheses below) of all of the
following objects:</p>
<ul class="simple">
<li>packages</li>
<li>modules</li>
<li>module attributes (+ initial values)</li>
<li>classes (+ inheritance)</li>
<li>class attributes (+ initial values)</li>
<li>instance attributes (+ initial values)</li>
<li>methods (+ parameters &amp; defaults)</li>
<li>functions (+ parameters &amp; defaults)</li>
</ul>
<p>(Extract comments too?  For example, comments at the start of a module
would be a good place for bibliographic field lists.)</p>
<p>In order to evaluate interpreted text cross-references, namespaces for
each of the above will also be required.</p>
<p>See the python-dev/docstring-develop thread &quot;AST mining&quot;, started on
2001-08-14.</p>
</div>
<div class="section" id="docstring-extraction-rules">
<h3><a class="toc-backref" href="#id38">Docstring Extraction Rules</a></h3>
<ol class="arabic">
<li><p class="first">What to examine:</p>
<ol class="loweralpha simple">
<li>If the &quot;<tt class="docutils literal">__all__</tt>&quot; variable is present in the module being
documented, only identifiers listed in &quot;<tt class="docutils literal">__all__</tt>&quot; are
examined for docstrings.</li>
<li>In the absence of &quot;<tt class="docutils literal">__all__</tt>&quot;, all identifiers are examined,
except those whose names are private (names begin with &quot;_&quot; but
don't begin and end with &quot;__&quot;).</li>
<li>1a and 1b can be overridden by runtime settings.</li>
</ol>
</li>
<li><p class="first">Where:</p>
<p>Docstrings are string literal expressions, and are recognized in
the following places within Python modules:</p>
<ol class="loweralpha simple">
<li>At the beginning of a module, function definition, class
definition, or method definition, after any comments.  This is
the standard for Python <tt class="docutils literal">__doc__</tt> attributes.</li>
<li>Immediately following a simple assignment at the top level of a
module, class definition, or <tt class="docutils literal">__init__</tt> method definition,
after any comments.  See <a class="reference internal" href="#attribute-docstrings">Attribute Docstrings</a> below.</li>
<li>Additional string literals found immediately after the
docstrings in (a) and (b) will be recognized, extracted, and
concatenated.  See <a class="reference internal" href="#additional-docstrings">Additional Docstrings</a> below.</li>
<li>&#64;&#64;&#64; 2.2-style &quot;properties&quot; with attribute docstrings?  Wait for
syntax?</li>
</ol>
</li>
<li><p class="first">How:</p>
<p>Whenever possible, Python modules should be parsed by Docutils, not
imported.  There are several reasons:</p>
<ul class="simple">
<li>Importing untrusted code is inherently insecure.</li>
<li>Information from the source is lost when using introspection to
examine an imported module, such as comments and the order of
definitions.</li>
<li>Docstrings are to be recognized in places where the byte-code
compiler ignores string literal expressions (2b and 2c above),
meaning importing the module will lose these docstrings.</li>
</ul>
<p>Of course, standard Python parsing tools such as the &quot;parser&quot;
library module should be used.</p>
<p>When the Python source code for a module is not available
(i.e. only the <tt class="docutils literal">.pyc</tt> file exists) or for C extension modules, to
access docstrings the module can only be imported, and any
limitations must be lived with.</p>
</li>
</ol>
<p>Since attribute docstrings and additional docstrings are ignored by
the Python byte-code compiler, no namespace pollution or runtime bloat
will result from their use.  They are not assigned to <tt class="docutils literal">__doc__</tt> or
to any other attribute.  The initial parsing of a module may take a
slight performance hit.</p>
<div class="section" id="attribute-docstrings">
<h4><a class="toc-backref" href="#id39">Attribute Docstrings</a></h4>
<p>(This is a simplified version of <a class="reference external" href="http://www.python.org/dev/peps/pep-0224">PEP 224</a> <a class="footnote-reference" href="#pep-224" id="id2">[2]</a>.)</p>
<p>A string literal immediately following an assignment statement is
interpreted by the docstring extraction machinery as the docstring of
the target of the assignment statement, under the following
conditions:</p>
<ol class="arabic">
<li><p class="first">The assignment must be in one of the following contexts:</p>
<ol class="loweralpha simple">
<li>At the top level of a module (i.e., not nested inside a compound
statement such as a loop or conditional): a module attribute.</li>
<li>At the top level of a class definition: a class attribute.</li>
<li>At the top level of the &quot;<tt class="docutils literal">__init__</tt>&quot; method definition of a
class: an instance attribute.  Instance attributes assigned in
other methods are assumed to be implementation details.  (&#64;&#64;&#64;
<tt class="docutils literal">__new__</tt> methods?)</li>
<li>A function attribute assignment at the top level of a module or
class definition.</li>
</ol>
<p>Since each of the above contexts are at the top level (i.e., in the
outermost suite of a definition), it may be necessary to place
dummy assignments for attributes assigned conditionally or in a
loop.</p>
</li>
<li><p class="first">The assignment must be to a single target, not to a list or a tuple
of targets.</p>
</li>
<li><p class="first">The form of the target:</p>
<ol class="loweralpha simple">
<li>For contexts 1a and 1b above, the target must be a simple
identifier (not a dotted identifier, a subscripted expression,
or a sliced expression).</li>
<li>For context 1c above, the target must be of the form
&quot;<tt class="docutils literal">self.attrib</tt>&quot;, where &quot;<tt class="docutils literal">self</tt>&quot; matches the &quot;<tt class="docutils literal">__init__</tt>&quot;
method's first parameter (the instance parameter) and &quot;attrib&quot;
is a simple identifier as in 3a.</li>
<li>For context 1d above, the target must be of the form
&quot;<tt class="docutils literal">name.attrib</tt>&quot;, where &quot;<tt class="docutils literal">name</tt>&quot; matches an already-defined
function or method name and &quot;attrib&quot; is a simple identifier as
in 3a.</li>
</ol>
</li>
</ol>
<p>Blank lines may be used after attribute docstrings to emphasize the
connection between the assignment and the docstring.</p>
<p>Examples:</p>
<pre class="literal-block">
g = 'module attribute (module-global variable)'
&quot;&quot;&quot;This is g's docstring.&quot;&quot;&quot;

class AClass:

    c = 'class attribute'
    &quot;&quot;&quot;This is AClass.c's docstring.&quot;&quot;&quot;

    def __init__(self):
        &quot;&quot;&quot;Method __init__'s docstring.&quot;&quot;&quot;

        self.i = 'instance attribute'
        &quot;&quot;&quot;This is self.i's docstring.&quot;&quot;&quot;

def f(x):
    &quot;&quot;&quot;Function f's docstring.&quot;&quot;&quot;
    return x**2

f.a = 1
&quot;&quot;&quot;Function attribute f.a's docstring.&quot;&quot;&quot;
</pre>
</div>
<div class="section" id="additional-docstrings">
<h4><a class="toc-backref" href="#id40">Additional Docstrings</a></h4>
<p>(This idea was adapted from <a class="reference external" href="http://www.python.org/dev/peps/pep-0216">PEP 216</a> <a class="footnote-reference" href="#pep-216" id="id3">[3]</a>.)</p>
<p>Many programmers would like to make extensive use of docstrings for
API documentation.  However, docstrings do take up space in the
running program, so some programmers are reluctant to &quot;bloat up&quot; their
code.  Also, not all API documentation is applicable to interactive
environments, where <tt class="docutils literal">__doc__</tt> would be displayed.</p>
<p>Docutils' docstring extraction tools will concatenate all string
literal expressions which appear at the beginning of a definition or
after a simple assignment.  Only the first strings in definitions will
be available as <tt class="docutils literal">__doc__</tt>, and can be used for brief usage text
suitable for interactive sessions; subsequent string literals and all
attribute docstrings are ignored by the Python byte-code compiler and
may contain more extensive API information.</p>
<p>Example:</p>
<pre class="literal-block">
def function(arg):
    &quot;&quot;&quot;This is __doc__, function's docstring.&quot;&quot;&quot;
    &quot;&quot;&quot;
    This is an additional docstring, ignored by the byte-code
    compiler, but extracted by Docutils.
    &quot;&quot;&quot;
    pass
</pre>
<div class="topic">
<p class="topic-title first">Issue: <tt class="docutils literal">from __future__ import</tt></p>
<p>This would break &quot;<tt class="docutils literal">from __future__ import</tt>&quot; statements introduced
in Python 2.1 for multiple module docstrings (main docstring plus
additional docstring(s)).  The Python Reference Manual specifies:</p>
<blockquote>
<p>A future statement must appear near the top of the module.  The
only lines that can appear before a future statement are:</p>
<ul class="simple">
<li>the module docstring (if any),</li>
<li>comments,</li>
<li>blank lines, and</li>
<li>other future statements.</li>
</ul>
</blockquote>
<p>Resolution?</p>
<ol class="arabic simple">
<li>Should we search for docstrings after a <tt class="docutils literal">__future__</tt>
statement?  Very ugly.</li>
<li>Redefine <tt class="docutils literal">__future__</tt> statements to allow multiple preceding
string literals?</li>
<li>Or should we not even worry about this?  There probably
shouldn't be <tt class="docutils literal">__future__</tt> statements in production code, after
all.  Perhaps modules with <tt class="docutils literal">__future__</tt> statements will simply
have to put up with the single-docstring limitation.</li>
</ol>
</div>
</div>
</div>
<div class="section" id="choice-of-docstring-format">
<h3><a class="toc-backref" href="#id41">Choice of Docstring Format</a></h3>
<p>Rather than force everyone to use a single docstring format, multiple
input formats are allowed by the processing system.  A special
variable, <tt class="docutils literal">__docformat__</tt>, may appear at the top level of a module
before any function or class definitions.  Over time or through
decree, a standard format or set of formats should emerge.</p>
<p>A module's <tt class="docutils literal">__docformat__</tt> variable only applies to the objects
defined in the module's file.  In particular, the <tt class="docutils literal">__docformat__</tt>
variable in a package's <tt class="docutils literal">__init__.py</tt> file does not apply to objects
defined in subpackages and submodules.</p>
<p>The <tt class="docutils literal">__docformat__</tt> variable is a string containing the name of the
format being used, a case-insensitive string matching the input
parser's module or package name (i.e., the same name as required to
&quot;import&quot; the module or package), or a registered alias.  If no
<tt class="docutils literal">__docformat__</tt> is specified, the default format is &quot;plaintext&quot; for
now; this may be changed to the standard format if one is ever
established.</p>
<p>The <tt class="docutils literal">__docformat__</tt> string may contain an optional second field,
separated from the format name (first field) by a single space: a
case-insensitive language identifier as defined in <a class="reference external" href="http://www.faqs.org/rfcs/rfc1766.html">RFC 1766</a>.  A
typical language identifier consists of a 2-letter language code from
<a class="reference external" href="http://www.loc.gov/standards/iso639-2/englangn.html">ISO 639</a> <a class="footnote-reference" href="#id18" id="id19">[11]</a> (3-letter codes used only if no 2-letter code exists; <a class="reference external" href="http://www.faqs.org/rfcs/rfc1766.html">RFC
1766</a> is currently being revised to allow 3-letter codes).  If no
language identifier is specified, the default is &quot;en&quot; for English.
The language identifier is passed to the parser and can be used for
language-dependent markup features.</p>
</div>
<div class="section" id="identifier-cross-references">
<h3><a class="toc-backref" href="#id42">Identifier Cross-References</a></h3>
<p>In Python docstrings, interpreted text is used to classify and mark up
program identifiers, such as the names of variables, functions,
classes, and modules.  If the identifier alone is given, its role is
inferred implicitly according to the Python namespace lookup rules.
For functions and methods (even when dynamically assigned),
parentheses ('()') may be included:</p>
<pre class="literal-block">
This function uses `another()` to do its work.
</pre>
<p>For class, instance and module attributes, dotted identifiers are used
when necessary.  For example (using reStructuredText markup):</p>
<pre class="literal-block">
class Keeper(Storer):

    &quot;&quot;&quot;
    Extend `Storer`.  Class attribute `instances` keeps track
    of the number of `Keeper` objects instantiated.
    &quot;&quot;&quot;

    instances = 0
    &quot;&quot;&quot;How many `Keeper` objects are there?&quot;&quot;&quot;

    def __init__(self):
        &quot;&quot;&quot;
        Extend `Storer.__init__()` to keep track of instances.

        Keep count in `Keeper.instances`, data in `self.data`.
        &quot;&quot;&quot;
        Storer.__init__(self)
        Keeper.instances += 1

        self.data = []
        &quot;&quot;&quot;Store data in a list, most recent last.&quot;&quot;&quot;

    def store_data(self, data):
        &quot;&quot;&quot;
        Extend `Storer.store_data()`; append new `data` to a
        list (in `self.data`).
        &quot;&quot;&quot;
        self.data = data
</pre>
<p>Each of the identifiers quoted with backquotes (&quot;`&quot;) will become
references to the definitions of the identifiers themselves.</p>
</div>
<div class="section" id="stylist-transforms">
<h3><a class="toc-backref" href="#id43">Stylist Transforms</a></h3>
<p>Stylist transforms are specialized transforms specific to the PySource
Reader.  The PySource Reader doesn't have to make any decisions as to
style; it just produces a logically constructed document tree, parsed
and linked, including custom node types.  Stylist transforms
understand the custom nodes created by the Reader and convert them
into standard Docutils nodes.</p>
<p>Multiple Stylist transforms may be implemented and one can be chosen
at runtime (through a &quot;--style&quot; or &quot;--stylist&quot; command-line option).
Each Stylist transform implements a different layout or style; thus
the name.  They decouple the context-understanding part of the Reader
from the layout-generating part of processing, resulting in a more
flexible and robust system.  This also serves to &quot;separate style from
content&quot;, the SGML/XML ideal.</p>
<p>By keeping the piece of code that does the styling small and modular,
it becomes much easier for people to roll their own styles.  The
&quot;barrier to entry&quot; is too high with existing tools; extracting the
stylist code will lower the barrier considerably.</p>
</div>
</div>
</div>
<div class="section" id="references-and-footnotes">
<h1><a class="toc-backref" href="#id44">References and Footnotes</a></h1>
<table class="docutils footnote" frame="void" id="pep-256" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td><a class="reference external" href="http://www.python.org/dev/peps/pep-0256">PEP 256</a>, Docstring Processing System Framework, Goodger
(<a class="reference external" href="http://www.python.org/peps/pep-0256.html">http://www.python.org/peps/pep-0256.html</a>)</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="pep-224" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id2">[2]</a></td><td><a class="reference external" href="http://www.python.org/dev/peps/pep-0224">PEP 224</a>, Attribute Docstrings, Lemburg
(<a class="reference external" href="http://www.python.org/peps/pep-0224.html">http://www.python.org/peps/pep-0224.html</a>)</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="pep-216" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id3">[3]</a></td><td><a class="reference external" href="http://www.python.org/dev/peps/pep-0216">PEP 216</a>, Docstring Format, Zadka
(<a class="reference external" href="http://www.python.org/peps/pep-0216.html">http://www.python.org/peps/pep-0216.html</a>)</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id4" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id5">[4]</a></td><td><a class="reference external" href="http://docutils.sourceforge.net/docs/user/tools.html">http://docutils.sourceforge.net/docs/user/tools.html</a></td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id6" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id7">[5]</a></td><td><a class="reference external" href="http://docutils.sourceforge.net/docs/ref/docutils.dtd">http://docutils.sourceforge.net/docs/ref/docutils.dtd</a></td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id8" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id9">[6]</a></td><td><a class="reference external" href="http://docutils.sourceforge.net/docs/ref/soextblx.dtd">http://docutils.sourceforge.net/docs/ref/soextblx.dtd</a></td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id10" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id11">[7]</a></td><td><a class="reference external" href="http://docutils.sourceforge.net/docs/ref/doctree.html">http://docutils.sourceforge.net/docs/ref/doctree.html</a></td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id12" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id13">[8]</a></td><td><a class="reference external" href="http://www.openvms.compaq.com:8000/73final/5841/841pro_027.html#error_cond_severity">http://www.openvms.compaq.com:8000/73final/5841/841pro_027.html#error_cond_severity</a></td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id14" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id15">[9]</a></td><td><a class="reference external" href="http://logging.apache.org/log4j/docs/index.html">http://logging.apache.org/log4j/docs/index.html</a></td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id16" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id17">[10]</a></td><td><a class="reference external" href="http://docutils.sourceforge.net/docs/dev/pysource.dtd">http://docutils.sourceforge.net/docs/dev/pysource.dtd</a></td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id18" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id19">[11]</a></td><td><a class="reference external" href="http://www.loc.gov/standards/iso639-2/englangn.html">http://www.loc.gov/standards/iso639-2/englangn.html</a></td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id20" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id21">[12]</a></td><td><a class="reference external" href="http://www.python.org/sigs/doc-sig/">http://www.python.org/sigs/doc-sig/</a></td></tr>
</tbody>
</table>
</div>
<div class="section" id="project-web-site">
<h1><a class="toc-backref" href="#id45">Project Web Site</a></h1>
<p>A SourceForge project has been set up for this work at
<a class="reference external" href="http://docutils.sourceforge.net/">http://docutils.sourceforge.net/</a>.</p>
</div>
<div class="section" id="copyright">
<h1><a class="toc-backref" href="#id46">Copyright</a></h1>
<p>This document has been placed in the public domain.</p>
</div>
<div class="section" id="acknowledgements">
<h1><a class="toc-backref" href="#id47">Acknowledgements</a></h1>
<p>This document borrows ideas from the archives of the <a class="reference external" href="http://www.python.org/sigs/doc-sig/">Python
Doc-SIG</a> <a class="footnote-reference" href="#id20" id="id21">[12]</a>.  Thanks to all members past &amp; present.</p>
<!-- Local Variables:
mode: indented-text
indent-tabs-mode: nil
sentence-end-double-space: t
fill-column: 70
End: -->
</div>

</div>
</body>
</html>