Current File : //proc/thread-self/root/kunden/lib/python3.9/site-packages/__pycache__/asciidocapi.cpython-39.pyc
a

��a'�@s�dZddlZddlZddlZdZdZddd�ZGdd�de�ZGd	d
�d
e	�Z
Gdd�de	�ZGd
d�de	�Ze
dkr�ddlZejejZejed�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())
   <p>Hello <strong>Joe Bloggs</strong></p>

   >>> asciidoc.attributes['author'] = 'Bill Smith'
   >>> infile = io.StringIO('Hello _{author}_')
   >>> outfile = io.StringIO()
   >>> asciidoc.execute(infile, outfile, backend='docbook')
   >>> print(outfile.getvalue())
   <simpara>Hello <emphasis>Bill Smith</emphasis></simpara>

2. Check error handling:

   >>> import io
   >>> asciidoc = AsciiDocAPI()
   >>> infile = io.StringIO('---------')
   >>> outfile = io.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


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.1cCsN|durtj�dd�}|�tj�D]&}tj�||�}tj�|�r"|Sq"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_pathAs
rc@seZdZdS)�
AsciiDocErrorN)�__name__�
__module__�__qualname__rrrrrOsrc@s0eZdZdZgfdd�Zd	dd�Zd
dd�ZdS)�Optionsz-
    Stores asciidoc(1) command options.
    cCs|dd�|_dS�N)�values)�selfrrrr�__init__WszOptions.__init__NcCs|�||�dS)zShortcut for append method.N)�append�r�name�valuerrr�__call__ZszOptions.__call__cCs,t|�ttfvrt|�}|j�||f�dSr)�type�int�float�strrrrrrrr^szOptions.append)N)N)rrr�__doc__rrrrrrrrSs
rc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�Versiona�
    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'

    cCsn||_t�d|j�}|s&td|j��|��}t|d�|_t|d�|_t|dpVd�|_|dpfd|_	dS)	Nz#^(\d+)\.(\d+)(\.(\d+))?\s*(.*?)\s*$zinvalid version number: %sr���0�r)
�string�re�match�
ValueError�groupsr �major�minor�micro�suffix)r�versionZreor-rrrr�szVersion.__init__cCsL|j|jkrdS|j|jkrH|j|jkr,dS|j|jkrH|j|jkrHdSdS�NTF�r.r/r0�r�otherrrr�__lt__�szVersion.__lt__cCsL|j|jkrdS|j|jkrH|j|jkr,dS|j|jkrH|j|jkrHdSdS)NFTr4r5rrr�__le__�szVersion.__le__cCs,|j|jkr(|j|jkr(|j|jkr(dSdSr3r4r5rrr�__eq__�s
�
�zVersion.__eq__N)rrrr#rr7r8r9rrrrr$ds

r$c@s.eZdZdZd
dd�Zddd�Zddd	�ZdS)
�AsciiDocAPIz
    AsciiDoc API class.
    NcCs�t�|_i|_g|_tj�d�}|r>tj�|�s�t	d|��n�|r`|}tj�|�s�t	d|��nntj�
tj�t��}dD]}t
||d�}|rxq�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.pyzasciidoc.pyc�asciidoc)r	zfailed to locate asciidocN)r�options�
attributes�messagesrrrr	rr�dirname�realpath�__file__r�cmd�_AsciiDocAPI__import_asciidoc)rZasciidoc_pyrBZ	this_pathrrrrr�s4zAsciiDocAPI.__init__Fc
Cs4tj�|j�ddvr�tj�dtj�|j��zZz,|rLddl}|�|j	�nddl	}||_	Wn t
y|td|j��Yn0Wtjd=n
tjd=0ntzPddlm
}m}ddlm}|d|j�}|d|�}||�}	|j�|	�|	|_	Wn"t
�ytd|j��Yn0t|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.pycrNzfailed to import )�spec_from_loader�module_from_spec)�SourceFileLoaderr;z-asciidocapi %s requires asciidoc %s or better)rr	�splitextrB�sys�insertr?�	importlib�reloadr;�ImportErrorr�importlib.utilrDrE�importlib.machineryrF�loader�exec_moduler$ZVERSION�MIN_ASCIIDOC_VERSION�API_VERSION)
rrKrJr;rDrErFrO�spec�modulerrrZ__import_asciidoc�s8


��zAsciiDocAPI.__import_asciidocc

Cs$g|_t|jj�}|dur$|d|�|dur6|d|�|j��D]J\}}|dks\|ddvrb|}n|durt|d}nd||f}|d	|�q@|g}|jd
d�zDz*|j�|j	|j|�W|jjdd�|_n|jjdd�|_0Wn<t
�y}	z"|	j�r
t|jd��WYd}	~	n
d}	~	00dS)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>rr<rr=�itemsrCr;�executerB�
SystemExit�coder)
rZinfileZoutfileZbackendZopts�k�v�s�args�errrrX	s,


,zAsciiDocAPI.execute)N)F)NN)rrrr#rrCrXrrrrr:�s
-
(r:�__main__)Zoptionflags)N)r#rHrr*rRrQr�	Exceptionr�objectrr$r:rZdoctestZNORMALIZE_WHITESPACE�ELLIPSISr<ZtestmodZtest_result�print�exitZfailedrrrr�<module>s 8
L{