3
5Ad]!  ã               @   s<   d Z ddlZddlmZmZ G dd„ dƒZG dd„ dƒZdS )	z¸This module defines an indenter class that handles indentation
levels for automatic code generation.  It also defines other
miscellaneous classes useful for the tvtk code generation.

é    Né   )Úget_tvtk_nameÚcamel2enthoughtc               @   sJ   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )ÚIndentz¾This class manages indentation levels for dynamically generated
    Python code.  The class also provides a method that formats a text
    string suitably at a given indentation level.

    é   c             C   s8   d| _ d| _d| _| j|ƒ tjdƒ| _tjdƒ| _dS )zÈInitializes the object.

        Parameters
        ----------

        - nspace : `int`

          Specifies the number of spaces to use for each indentation
          level. Defaults to 4.

        Ú r   z^\s*$z\s*(\S)N)ÚtabÚtxtÚnspaceÚset_tabÚreÚcompileÚspace_reÚfind_space_re)Úselfr
   © r   út/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/mayavi-4.7.1-py3.6-linux-x86_64.egg/tvtk/indenter.pyÚ__init__   s    
zIndent.__init__c             C   s   | j S )N)r	   )r   r   r   r   Ú__repr__.   s    zIndent.__repr__c             C   s   || _ d| | _dS )z*Set the number of spaces a tab represents.ú N)r
   r   )r   r
   r   r   r   r   1   s    zIndent.set_tabc             C   s
   d| _ dS )z!Reset the indentation level to 0.r   N)r	   )r   r   r   r   Úreset6   s    zIndent.resetc             C   s   |  j | j7  _ dS )zIncrease the indentation level.N)r	   r   )r   r   r   r   Úincr:   s    zIndent.incrc             C   s   | j d| j … | _ dS )zDecrease the indentation level.N)r	   r
   )r   r   r   r   Údecr>   s    zIndent.decrc       
      C   s\  | j }| j}|jdƒ}d}t|ƒdkrNx6|dd… D ]}|j|ƒs4d}P q4W nt|ƒdkr^dS |rzdt| ƒ|d jƒ f S d}|j|d ƒ}y|jdƒ}W n tk
r²   d}Y nX g }	|j|d ƒsà|	j	dt| ƒ|d f ƒ xH|dd… D ]8}|�r|	j	dt| ƒ||d… f ƒ qî|	j	t| ƒƒ qîW |j|	d ƒ�rDd|	d	< n
|	j	dƒ dj
|	ƒS dS )
al  Formats given text as per current indentation levels.

        Note that the returned string always ends with a newline to
        avoid problems for subsequent lines in the output that have to
        deal trailing garbage in the last line.

        Parameters
        ----------

        - txt : `string`

          Input text string to be formatted.  Can contain newlines.

          If the input text is a single line of text then leading
          space is stripped and the current indentation is added to
          the left along with a newline and the resulting string is
          returned.

          If the input text is multi-line input the indentation of the
          first line is ignored, and the second line is considered.
          All subsequent lines have the current indentation followed
          by any extra space from the default indentation.

        Ú
r   Nr   z%s%s
z%s%sr   éÿÿÿÿr   )r   r   ÚsplitÚlenÚmatchÚreprÚstripÚstartÚAttributeErrorÚappendÚjoin)
r   r	   r   r   ÚdZ	one_linerÚiZ	strip_idxÚmÚretr   r   r   ÚformatB   s<    


 

zIndent.formatN)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r(   r   r   r   r   r      s   
r   c               @   sX   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )ÚVTKDocMassagera-  This class massages the documentation strings suitably for
    inclusion in the TVTK code.  The names of all the VTK classes are
    changed suitably and when possible the method names are also
    changed.

    This class is *not* generic and is *very* specific to VTK
    documentation strings.
    c             C   s2   t jdƒ| _dd„ | _t jdƒ| _t jdƒ| _d S )Nz(vtk[A-Z0-9]\S+)c             S   s   t | jdƒƒS )Nr   )r   Úgroup)r&   r   r   r   Ú<lambda>‘   s    z)VTKDocMassager.__init__.<locals>.<lambda>z([a-z0-9]+[A-Z])zC\+\+: .*?;\n*)r   r   ÚrenamerÚren_funcÚfunc_reÚcpp_method_re)r   r   r   r   r   �   s    
zVTKDocMassager.__init__c             C   sR   | j |ƒ}|jƒ  |j|jdƒƒ |j|jd| ƒƒ |j|jdƒƒ |jƒ  dS )zäWrite processed class documentation string into `out`.

        Parameters
        ----------
        - doc : `string`

          The documentation string.

        - out : file line object.

        - indent : `Indent`
        z"""r   N)Úmassager   Úwriter(   r   )r   ÚdocÚoutÚindentr'   r   r   r   Úwrite_class_doc™   s    
zVTKDocMassager.write_class_docc             C   sX   | j |ƒ}|jƒ  |j|jdƒƒ |j|jd| j|ƒ ƒƒ |j|jdƒƒ |jƒ  dS )a9  Write processed trait documentation string into `out`.

        This method removes the call signature information from the
        method.

        Parameters
        ----------
        - doc : `string`

          The documentation string.

        - out : file line object.

        - indent : `Indent`
        z"""r   N)Ú_remove_sigr   r5   r(   r4   r   )r   r6   r7   r8   r'   r   r   r   Úwrite_trait_doc­   s    
zVTKDocMassager.write_trait_docc             C   sÊ   |d|j dƒ… }t|ƒ}| j|d|j dƒ… ƒ}| jjd|ƒ}|jd| d| ƒ}|jƒ  |j|jdƒƒ |j|j|ƒƒ | j	|ƒ}|r®|jdƒ |j|jd| j
|ƒ ƒƒ |j|jdƒƒ |jƒ  dS )	a  Write processed method documentation string into `out`.

        The method signature is appopriately massaged.

        Parameters
        ----------
        - doc : `string`

          The documentation string.

        - out : file line object.

        - indent : `Indent`
        é   ú(Nz

r   zV.z"""r   )Úfindr   Ú_rename_classr3   ÚsubÚreplacer   r5   r(   r:   r4   r   )r   r6   r7   r8   Ú	orig_nameÚnameÚmy_sigr'   r   r   r   Úwrite_method_docÄ   s    

zVTKDocMassager.write_method_docc             C   s|   |d|j dƒ… }t|ƒ}| j|d|j dƒ… ƒ}| jjd|ƒ}|jd| d| ƒ}| j| j|ƒƒ}|rt|d | S |S dS )zÞReturn processed method documentation string from `doc`.

        The method signature is appopriately massaged.

        Parameters
        ----------
        - doc : `string`

          The documentation string.
        r<   r=   Nz

r   zV.r   )r>   r   r?   r3   r@   rA   r4   r:   )r   r6   rB   rC   rD   r'   r   r   r   Úget_method_docâ   s    zVTKDocMassager.get_method_docc             C   s   | j |ƒ}| j|ƒ}|S )z¥Returns massaged documentation string from passed
        docstring, `doc`.  This method basically renames the methods
        and classes in the docstring.
        )Ú_rename_methodsr?   )r   r6   r'   r   r   r   r4   ø   s    

zVTKDocMassager.massagec             C   s   | j j| j|ƒS )N)r0   r@   r1   )r   r6   r   r   r   r?     s    zVTKDocMassager._rename_classc             C   s.   |j dƒd }t|ƒ|kr&||d … S dS d S )Nz

r<   r   )r>   r   )r   r6   Úidxr   r   r   r:     s    zVTKDocMassager._remove_sigc             C   s”   |j dƒ}g }xz|D ]r}|j dƒ}g }xN|D ]F}|d d… dkrL|j|ƒ q,| jj|ƒrh|jt|ƒƒ q,|j|ƒ q,W |jdj|ƒƒ qW dj|ƒS )Nr   r   é   Úvtk)r   r"   r2   Úsearchr   r#   )r   r6   ÚlinesÚnlÚlineÚwordsÚnwÚwordr   r   r   rG     s    



zVTKDocMassager._rename_methodsN)r)   r*   r+   r,   r   r9   r;   rE   rF   r4   r?   r:   rG   r   r   r   r   r-   †   s   
r-   )r,   r   Úcommonr   r   r   r-   r   r   r   r   Ú<module>   s   q