Writer Module — xml2rfc v2.3.3 documentation

### Navigation

- index
- modules |
- previous |
- xml2rfc v2.3.3 documentation »

# Writer Module

## Abstract

The xml2rfc writer package contains a Base Writer Class interface (an abstract python class) with callback methods to write specific elements of an RFC document. Adding a new output format to xml2rfc would be done by extending this class.

Additionally, there is a collection of Formatted Writer Classes which provide implementations for various formats. Each writer takes an `XmlRfc` instance as a constructor argument, and has a single public `write()` method which converts and writes the rfc document to a specified filename.

## Formatted Writer Classes

The following writer implementations are provided in xml2rfc.

class `xml2rfc.writers.` `RawTextRfcWriter`(xmlrfc, width=72, quiet=False, verbose=False)

  Writes to a text file, unpaginated, no headers or footers.

  The page width is controlled by the width parameter.

  `write`(filename, tmpfile=None)

    Public method to write the RFC document to a file.

class `xml2rfc.writers.` `PaginatedTextRfcWriter`(xmlrfc, width=72, quiet=False, verbose=False)

  Writes to a text file, paginated with headers and footers

  The page width is controlled by the width parameter.

  `write`(filename, tmpfile=None)

    Public method to write the RFC document to a file.

class `xml2rfc.writers.` `NroffRfcWriter`(xmlrfc, width=72, quiet=False, verbose=False)

  Writes to an nroff formatted file

  The page width is controlled by the width parameter.

  `write`(filename, tmpfile=None)

    Public method to write the RFC document to a file.

class `xml2rfc.writers.` `HtmlRfcWriter`(xmlrfc, quiet=False, verbose=False, templates_dir=None)

  Writes to an HTML file.

  Uses HTML templates located in the templates directory.

  `write`(filename, tmpfile=None)

    Public method to write the RFC document to a file.

class `xml2rfc.writers.` `ExpandedXmlWriter`(xmlrfc, quiet=False, verbose=False)

  Writes a duplicate XML file but with all references expanded

  `write`(filename)

    Public method to write the XML document to a file

## Base Writer Class

The following interface provides all methods necessary for creation of an RFC document. To support a new format, the writer class must subclass BaseRfcWriter and override all methods–with the exception of `write()`, which contains the callback logic and should be left alone.

class `xml2rfc.writers.base.` `BaseRfcWriter`(xmlrfc, quiet=False, verbose=False)

  Base class for all writers

  All public methods need to be overridden for a writer implementation.

  `draw_table`(table, table_num=None)

    Draws a formatted table from a <texttable> element

    For HTML nothing is really ‘drawn’ since we can use <table>

  `insert_anchor`(text)

    Inserts a document anchor for internal links

  `insert_iref_index`()

    Marks the current buffer position to insert the index at

  `insert_toc`()

    Marks the current buffer position to insert ToC at

  `post_processing`()

    Last method that is called after traversing the XML RFC tree

  `pre_processing`()

    First method that is called before traversing the XML RFC tree

  `write`(filename, tmpfile=None)

    Public method to write the RFC document to a file.

  `write_address_card`(author)

    Writes the address information for an <author> element

  `write_heading`(text, bullet='', autoAnchor=None, anchor=None, level=1)

    Writes a section heading

  `write_label`(text, type='figure')

    Writes a table or figure label

  `write_paragraph`(text, align='left', autoAnchor=None)

    Writes a paragraph of text

  `write_raw`(text, indent=3, align='left', blanklines=0, delimiter=None)

    Writes a block of text that preserves all whitespace

  `write_reference_list`(list)

    Writes a <references> element

  `write_t_rec`(t, align='left', autoAnchor=None)

    Recursively writes <t> elements

  `write_title`(title, docName=None)

    Writes the document title

  `write_to_file`(file)

    Writes the finished buffer to a file

  `write_top`(left_header, right_header)

    Writes the main document header

    Takes two list arguments, one for each margin, and combines them so that they exist on the same lines of text

exception `xml2rfc.writers.base.` `RfcWriterError`(msg)

  Exception class for errors during document writing

### Navigation

- index
- modules |
- previous |
- xml2rfc v2.3.3 documentation »