grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a
Îña' ã @ s² d Z ddlZddlZddlZdZdZddd„ZG dd„ deƒZG d d
„ d
e ƒZ
G dd„ de ƒZG d
d„ de ƒZe
dkr®ddlZejej Zejed�Zeeƒ e ejdk¡ dS )a�
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 io
>>> infile = io.StringIO('Hello *{author}*')
>>> outfile = io.StringIO()
>>> asciidoc = AsciiDocAPI()
>>> asciidoc.options('--no-header-footer')
>>> asciidoc.attributes['author'] = 'Joe Bloggs'
>>> asciidoc.execute(infile, outfile, backend='html4')
>>> print(outfile.getvalue())
Hello Joe Bloggs
>>> asciidoc.attributes['author'] = 'Bill Smith'
>>> infile = io.StringIO('Hello _{author}_')
>>> outfile = io.StringIO()
>>> asciidoc.execute(infile, outfile, backend='docbook')
>>> print(outfile.getvalue())
Hello Bill Smith
2. Check error handling:
>>> import io
>>> asciidoc = AsciiDocAPI()
>>> infile = io.StringIO('---------')
>>> outfile = io.StringIO()
>>> asciidoc.execute(infile, outfile)
Traceback (most recent call last):
File "", line 1, in
File "asciidocapi.py", line 189, in execute
raise AsciiDocError(self.messages[-1])
AsciiDocError: ERROR: : line 1: [blockdef-listing] missing closing delimiter
Copyright (C) 2002-2013 Stuart Rackham.
Copyright (C) 2013-2020 AsciiDoc Contributors.
Free use of this software is granted under the terms of the GNU General
Public License version 2 (GPLv2).
é Nz0.1.2z8.4.1c C sN |du rt j dd¡}| t j¡D ]&}t j || ¡}t j |¡r"| S q"dS )z=
Find file fname in paths. Return None if not found.
NÚPATHÚ )ÚosÚenvironÚgetÚsplitÚpathsepÚpathÚjoinÚisfile)Úfnamer ÚdirZfpath© r ú//usr/lib/python3.9/site-packages/asciidocapi.pyÚfind_in_pathA s
r c @ s e Zd ZdS )Ú
AsciiDocErrorN)Ú__name__Ú
__module__Ú__qualname__r r r r r O s r c @ s0 e Zd ZdZg fdd„Zd dd„Zd
dd„ZdS )ÚOptionsz-
Stores asciidoc(1) command options.
c C s |d d … | _ d S ©N)Úvalues)Úselfr r r r Ú__init__W s zOptions.__init__Nc C s | ||¡ dS )zShortcut for append method.N)Úappend©r ÚnameÚvaluer r r Ú__call__Z s zOptions.__call__c C s, t |ƒttfv rt|ƒ}| j ||f¡ d S r )ÚtypeÚintÚfloatÚstrr r r r r r r ^ s zOptions.append)N)N)r r r Ú__doc__r r r r r r r r S s
r c @ s0 e Zd ZdZdd„ Zdd„ Zdd„ Zdd „ Zd
S )ÚVersiona÷
Parse and compare AsciiDoc version numbers. Instance attributes:
string: String version number '.[.][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'
c C sn || _ t d| j ¡}|s&td| j ƒ‚| ¡ }t|d ƒ| _t|d ƒ| _t|d pVdƒ| _|d pfd| _ d S ) Nz#^(\d+)\.(\d+)(\.(\d+))?\s*(.*?)\s*$zinvalid version number: %sr é é Ú0é r )
ÚstringÚreÚmatchÚ
ValueErrorÚgroupsr ÚmajorÚminorÚmicroÚsuffix)r ÚversionZreor- r r r r ƒ s zVersion.__init__c C sL | j |j k rdS | j |j krH| j|jk r,dS | j|jkrH| j|jk rHdS dS ©NTF©r. r/ r0 ©r Úotherr r r Ú__lt__Ž s zVersion.__lt__c C sL | j |j krdS | j |j krH| j|jkr,dS | j|jkrH| j|jkrHdS dS )NFTr4 r5 r r r Ú__le__› s zVersion.__le__c C s, | j |j kr(| j|jkr(| j|jkr(dS dS r3 r4 r5 r r r Ú__eq__§ s
ÿ
þzVersion.__eq__N)r r r r# r r7 r8 r9 r r r r r$ d s
r$ c @ s. e Zd ZdZd
dd„Zddd„Zddd „ZdS )
ÚAsciiDocAPIz
AsciiDoc API class.
Nc C sè t ƒ | _i | _g | _tj d¡}|r>tj |¡sÎt d| ƒ‚n�|r`|}tj |¡sÎt d| ƒ‚nntj
tj t¡¡}dD ]}t
||d�}|rx qÎqxdD ]}t
|ƒ}|r– qÎq–dD ]}tj |¡r° qÎq°t dƒ‚tj |¡| _| ¡ dS )zX
Locate and import asciidoc.py.
Initialize instance attributes.
ZASCIIDOC_PYzmissing ASCIIDOC_PY file: %szmissing file: %s)zasciidoc.pyzasciidoc.pycÚasciidoc)r zfailed to locate asciidocN)r ÚoptionsÚ
attributesÚmessagesr r r r r r ÚdirnameÚrealpathÚ__file__r ÚcmdÚ_AsciiDocAPI__import_asciidoc)r Zasciidoc_pyrB Z this_pathr r r r r ´ s4 zAsciiDocAPI.__init__Fc
C s4 t j | j¡d dv r–tj dt j | j¡¡ zZz,|rLddl}| | j ¡ nddl }|| _ W n t
y| td| j ƒ‚Y n0 W tjd= n
tjd= 0 ntzPddlm
}m} ddlm} |d| jƒ}|d|ƒ}||ƒ} |j | ¡ | | _ W n" t
�y td| j ƒ‚Y n0 t| j jƒttƒk �r0td ttf ƒ‚dS )
a
Import asciidoc module (script or compiled .pyc).
See
http://groups.google.com/group/asciidoc/browse_frm/thread/66e7b59d12cd2f91
for an explanation of why a seemingly straight-forward job turned out
quite complicated.
r% )z.pyz.pycr Nzfailed to import )Úspec_from_loaderÚmodule_from_spec)ÚSourceFileLoaderr; z-asciidocapi %s requires asciidoc %s or better)r r ÚsplitextrB ÚsysÚinsertr? Ú importlibÚreloadr; ÚImportErrorr Úimportlib.utilrD rE Úimportlib.machineryrF ÚloaderÚexec_moduler$ ZVERSIONÚMIN_ASCIIDOC_VERSIONÚAPI_VERSION)
r rK rJ r; rD rE rF rO ÚspecÚmoduler r r Z__import_asciidocá s8
ÿÿzAsciiDocAPI.__import_asciidocc
C s$ g | _ t| jjƒ}|dur$|d|ƒ |dur6|d|ƒ | j ¡ D ]J\}}|dks\|d dv rb|}n|du rt|d }nd||f }|d |ƒ q@|g}| jd
d� zDz*| j | j |j|¡ W | jj dd… | _ n| jj dd… | _ 0 W n< t
�y } z"| j�r
t| j d ƒ‚W Y d} ~ n
d} ~ 0 0 dS )z‹
Compile infile to outfile using backend format.
infile can outfile can be file path strings or file like objects.
Nz
--out-filez --backendr éÿÿÿÿz!@ú!z%s=%sz--attributeT)rK )
r> r r<