bpy.api package

Submodules

bpy.api.asciidocapi module

asciidocapi - AsciiDoc API wrapper class.

The AsciiDocAPI class provides an API for executing asciidoc. Minimal example compiles mydoc.txt to mydoc.html:

import asciidocapi asciidoc = asciidocapi.AsciiDocAPI() asciidoc.execute(‘mydoc.txt’)
  • Full documentation in asciidocapi.txt.
  • See the doctests below for more examples.

Doctests:

  1. Check execution:

    >>> import StringIO
    >>> infile = StringIO.StringIO('Hello *{author}*')
    >>> outfile = StringIO.StringIO()
    >>> asciidoc = AsciiDocAPI()
    >>> asciidoc.options('--no-header-footer')
    >>> asciidoc.attributes['author'] = 'Joe Bloggs'
    >>> asciidoc.execute(infile, outfile, backend='html4')
    >>> print outfile.getvalue()
    <p>Hello <strong>Joe Bloggs</strong></p>
    
    >>> asciidoc.attributes['author'] = 'Bill Smith'
    >>> infile = StringIO.StringIO('Hello _{author}_')
    >>> outfile = StringIO.StringIO()
    >>> asciidoc.execute(infile, outfile, backend='docbook')
    >>> print outfile.getvalue()
    <simpara>Hello <emphasis>Bill Smith</emphasis></simpara>
    
  2. Check error handling:

    >>> import StringIO
    >>> asciidoc = AsciiDocAPI()
    >>> infile = StringIO.StringIO('---------')
    >>> outfile = StringIO.StringIO()
    >>> asciidoc.execute(infile, outfile)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "asciidocapi.py", line 189, in execute
        raise AsciiDocError(self.messages[-1])
    AsciiDocError: ERROR: <stdin>: line 1: [blockdef-listing] missing closing delimiter
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "asciidocapi.py", line 189, in execute
        raise AsciiDocError(self.messages[-1])
    AsciiDocError: ERROR: <stdin>: line 1: [blockdef-listing] missing closing delimiter
    

Copyright (C) 2009 Stuart Rackham. Free use of this software is granted under the terms of the GNU General Public License (GPL).

class bpy.api.asciidocapi.AsciiDocAPI(asciidoc_py=None)[source]

Bases: object

AsciiDoc API class.

execute(infile, outfile=None, backend=None)[source]

Compile infile to outfile using backend format. infile can outfile can be file path strings or file like objects.

exception bpy.api.asciidocapi.AsciiDocError[source]

Bases: exceptions.Exception

class bpy.api.asciidocapi.Options(values=[])[source]

Bases: object

Stores asciidoc(1) command options.

append(name, value=None)[source]
class bpy.api.asciidocapi.Version(version)[source]

Bases: object

Parse and compare AsciiDoc version numbers. Instance attributes:

string: String version number ‘<major>.<minor>[.<micro>][suffix]’. major: Integer major version number. minor: Integer minor version number. micro: Integer micro version number. suffix: Suffix (begins with non-numeric character) is ignored when

comparing.

Doctest examples:

>>> Version('8.2.5') < Version('8.3 beta 1')
True
>>> Version('8.3.0') == Version('8.3. beta 1')
True
>>> Version('8.2.0') < Version('8.20')
True
>>> Version('8.20').major
8
>>> Version('8.20').minor
20
>>> Version('8.20').micro
0
>>> Version('8.20').suffix
''
>>> Version('8.20 beta 1').suffix
'beta 1'
bpy.api.asciidocapi.find_in_path(fname, path=None)[source]

Find file fname in paths. Return None if not found.

Module contents

Table Of Contents

Previous topic

bpy package

Next topic

bpy.handlers package

This Page