o
    œˆ¾Xè'  ã                   @   sÎ   d Z dZd ¡ Zg d¢ZdZddlmZ dd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zee	e
eedœZG dd„ dƒZG dd„ dƒZ	 dadd„ Zdd„ Zdd„ ZddlmZ eeƒ [dd„ Zed kreeƒ  dS dS )!z3.3.0zHA Sequencer class counts things. It aids numbering and formatting lists.z#Sequencer getSequencer setSequencer)
é    é   é	   éI   é
   é   é   é‰   iI  é   ÚIVXLCDMr   )ÚisPy3c                 C   sp   | dk s| dkrt dƒ‚d}d}| r6t| dƒ\} }t| }|r0t|dƒ\}}t||  | }|s|d7 }| s|S )	Nr   iŸ  zillegal valueÚ éÿÿÿÿr   é   r   )Ú
ValueErrorÚdivmodÚ_RN_TEMPLATESÚ_RN_LETTERS)ÚvalueÚstrÚbaseÚindexÚtmp© r   úI/var/www/html/env/lib/python3.10/site-packages/reportlab/lib/sequencer.pyÚ	_format_I   s   þúr   c                 C   s   t | ƒ ¡ S ©N)r   Úlower©Únumr   r   r   Ú	_format_i    s   r   c                 C   s   t | ƒS )zThe simplest formatter)r   r   r   r   r   Ú_format_123#   ó   r    c                 C   ó   | d d }t |d ƒS )zUppercase.  Wraps around at 26.r   é   éA   ©Úchr©r   Únr   r   r   Ú_format_ABC'   ó   r)   c                 C   r"   )zLowercase.  Wraps around at 26.r   r#   éa   r%   r'   r   r   r   Ú_format_abc,   r*   r,   )ÚIÚiÚ1ÚAÚac                   @   sd   e Zd ZdZdd„ Zdd„ Zddd„Zd	d
„ ZeZdd„ Z	e
r$dd„ Zndd„ Zdd„ Zdd„ ZdS )Ú_Countera  Private class used by Sequencer.  Each counter
    knows its format, and the IDs of anything it
    resets, as well as its value. Starts at zero
    and increments just before you get the new value,
    so that it is still 'Chapter 5' and not 'Chapter 6'
    when you print 'Figure 5.1'c                 C   s   d| _ | j | _t| _g | _d S ©Nr   )Ú_baseÚ_valuer    Ú
_formatterÚ_resets©Úselfr   r   r   Ú__init__A   s   
z_Counter.__init__c                 C   s
   || _ d S r   )r6   )r9   Ú
formatFuncr   r   r   ÚsetFormatterG   s   
z_Counter.setFormatterNc                 C   s   |r|| _ d S | j| _ d S r   )r5   r4   )r9   r   r   r   r   ÚresetJ   s   
z_Counter.resetc                 C   s,   |  j d7  _ | j }| jD ]}| ¡  q|S )Nr   )r5   r7   r=   )r9   ÚvÚcounterr   r   r   ÚnextP   s
   

z_Counter.nextc                 C   s   | j S r   )r5   r8   r   r   r   Ú_thisX   s   z_Counter._thisc                 C   s   |   t| ƒ¡S ©zReturns next value formatted)r6   r@   r8   r   r   r   Únextf\   ó   z_Counter.nextfc                 C   ó   |   |  ¡ ¡S rB   )r6   Ú__next__r8   r   r   r   rC   `   rD   c                 C   rE   r   )r6   rA   r8   r   r   r   Úthisfd   s   z_Counter.thisfc                 C   s   || j vr| j  |¡ d S d S r   )r7   Úappend)r9   ÚotherCounterr   r   r   Úchaing   s   
ÿz_Counter.chainr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r:   r<   r=   r@   rF   rA   r   rC   rG   rJ   r   r   r   r   r2   9   s    

r2   c                   @   s®   e Zd ZdZdd„ Zdd„ Zd%dd„Zd%d	d
„Zer$dd„ Z	d%dd„Z
nd%dd„Z
d%dd„Zd%dd„Zd%dd„Zdd„ Zdd„ Zd&dd„Zdd„ Zdd „ Zd!d"„ Zd#d$„ ZdS )'Ú	Sequenceran  Something to make it easy to number paragraphs, sections,
    images and anything else.  The features include registering
    new string formats for sequences, and 'chains' whereby
    some counters are reset when their parents.
    It keeps track of a number of
    'counters', which are created on request:
    Usage::
    
        >>> seq = layout.Sequencer()
        >>> seq.next('Bullets')
        1
        >>> seq.next('Bullets')
        2
        >>> seq.next('Bullets')
        3
        >>> seq.reset('Bullets')
        >>> seq.next('Bullets')
        1
        >>> seq.next('Figures')
        1
        >>>
    c                 C   s   i | _ i | _|  ¡  d S r   )Ú	_countersÚ_formattersÚ_resetr8   r   r   r   r:   ƒ   s   zSequencer.__init__c                 C   s\   | j  ¡  | j ¡  | j tttttdœ¡ t	| j | jd�}| j
 ¡  | j
 |¡ d | _d S )N)r/   r0   r1   r-   r.   )rP   rQ   )rP   ÚclearrQ   Úupdater    r)   r,   r   r   ÚdictÚ__dict__Ú_defaultCounter)r9   Údr   r   r   rR   ˆ   s   

ú

zSequencer._resetNc                 C   s4   z| j | W S  ty   tƒ }|| j |< | Y S w )zCreates one if not present)rP   ÚKeyErrorr2   )r9   r?   Úcntr   r   r   Ú_getCounter˜   s   
ýzSequencer._getCounterc                 C   ó   |s| j }|  |¡ ¡ S )z_Retrieves counter value but does not increment. For
        new counters, sets base value to 1.)rW   r[   rA   ©r9   r?   r   r   r   rA   ¡   ó   zSequencer._thisc                 C   s   t |  | j¡ƒS ©zuRetrieves the numeric value for the given counter, then
            increments it by one.  New counters start at one.)r@   r[   rW   r8   r   r   r   rF   ©   s   zSequencer.__next__c                 C   s2   |st | ƒS | j}z|| _t | ƒW || _S || _w r   )r@   rW   )r9   r?   Údcr   r   r   r@   ®   s   zSequencer.nextc                 C   r\   r_   )rW   r[   r@   r]   r   r   r   r@   ¹   r^   c                 C   r\   r   )rW   r[   rG   r]   r   r   r   rG   À   s   zSequencer.thisfc                 C   r\   )zqRetrieves the numeric value for the given counter, then
        increments it by one.  New counters start at one.)rW   r[   rC   r]   r   r   r   rC   Å   r^   zSequencer.nextfc                 C   s
   || _ dS )z$Changes the key used for the defaultN)rW   )r9   Údefaultr   r   r   ÚsetDefaultCounterÌ   s   
zSequencer.setDefaultCounterc                 C   s   || j |< dS )z§Registers a new formatting function.  The funtion
        must take a number as argument and return a string;
        fmt is a short menmonic string used to access it.N)rQ   )r9   ÚformatÚfuncr   r   r   ÚregisterFormatÐ   s   zSequencer.registerFormatc                 C   s   | j | }|  |¡ |¡ dS )zPSpecifies that the given counter should use
        the given format henceforth.N)rQ   r[   r<   )r9   r?   rc   rd   r   r   r   Ú	setFormatÖ   s   
zSequencer.setFormatr   c                 C   s   |s| j }||  |¡_d S r   )rW   r[   r5   )r9   r?   r   r   r   r   r=   Ü   s   zSequencer.resetc                 C   s"   |   |¡}|   |¡}| |¡ d S r   )r[   rJ   )r9   ÚparentÚchildÚpÚcr   r   r   rJ   á   s   

zSequencer.chainc                 C   s0   |dd… dkr|dd… }|   |¡S |  |¡S )zrAllows compact notation to support the format function.
        s['key'] gets current value, s['key+'] increments.r   Nú+)rC   rG   )r9   Úkeyr?   r   r   r   Ú__getitem__æ   s   

zSequencer.__getitem__c                 C   s   ||  S )z0The crowning jewels - formats multi-level lists.r   )r9   Útemplater   r   r   rc   ï   r!   zSequencer.formatc                 C   sN   t | j ¡ ƒ}| ¡  tdƒ |D ]\}}td|| ¡ |j| ¡ f ƒ qdS )z-Write current state to stdout for diagnosticszSequencer dump:z2    %s: value = %d, base = %d, format example = %sN)ÚlistrP   ÚitemsÚsortÚprintrA   r4   rG   )r9   Úcountersrl   r?   r   r   r   Údumpó   s   
ÿÿzSequencer.dumpr   r3   )rK   rL   rM   rN   r:   rR   r[   rA   r   rF   r@   rG   rC   rb   re   rf   r=   rJ   rm   rc   rt   r   r   r   r   rO   k   s(    

	




	rO   Nc                   C   s   t d u rtƒ a t S r   )Ú
_sequencerrO   r   r   r   r   ÚgetSequencerÿ   s   rv   c                 C   s   t }| a |S r   )ru   )ÚseqÚsr   r   r   ÚsetSequencer  s   ry   c                   C   s   t rt  ¡  d S d S r   )ru   rR   r   r   r   r   rR     s   ÿrR   )Úregister_resetc                     sn  t ƒ ‰ tdtˆ ƒtˆ ƒtˆ ƒf ƒ tdˆ  d¡ˆ  d¡ˆ  d¡f ƒ tdtˆ ƒ ƒ ˆ  d¡ tdtˆ ƒtˆ ƒtˆ ƒf ƒ ˆ  ¡  tdtˆ ƒtˆ ƒtˆ ƒf ƒ tƒ  tdƒ ˆ  d	d
¡ tdˆ  d	¡ˆ  d	¡ˆ  d	¡f ƒ dd„ } tƒ  tdƒ ˆ  d| ¡ ˆ  dd¡ tdd ‡ fdd„tddƒD ƒ¡ ƒ tƒ  tdƒ ˆ  	dd¡ tdˆ  d¡ ƒ tdˆ  d¡ ƒ tdˆ  d¡ ƒ tdˆ  d¡ ƒ tdˆ  d¡ ƒ tdˆ  d¡ ƒ tdˆ  d¡ ƒ tdˆ  d¡ ƒ tƒ  tdƒ tdˆ d	  ƒ tdˆ d  ƒ tdˆ d  ƒ tdˆ d	  ƒ tƒ  td ƒ td!ƒ td"ˆ  ƒ td"ˆ  ƒ td"ˆ  ƒ d S )#Nz)Counting using default sequence: %d %d %dz1Counting Figures: Figure %d, Figure %d, Figure %dÚfigurezBack to default again: %dÚlist1zSet default to list1: %d %d %dz#Set default to None again: %d %d %dz0Creating Appendix counter with format A, B, C...ÚAppendixr0   z)    Appendix %s, Appendix %s, Appendix %sc                 S   s   d| d d  S )N)ÚunÚdeuxÚtroisÚquatreÚcinqr   é   r   r   r   r   r   Úformat_french$  s   ztest.<locals>.format_frenchz+Defining a custom format with french words:ÚfrenchÚ
FrenchListz   ú c                 3   s   � | ]
}t ˆ  d ¡ƒV  qdS )r†   N)r   rC   )Ú.0r.   ©rx   r   r   Ú	<genexpr>*  s   € ztest.<locals>.<genexpr>r   é   z:Chaining H1 and H2 - H2 goes back to one when H1 increasesÚH1ÚH2z    H1 = %dz      H2 = %dz-GetItem notation - append a plus to incrementz    seq["Appendix"] = %sz    seq["Appendix+"] = %sz	Appendix+z8Finally, string format notation for nested lists.  Cool!z>The expression ("Figure %(Chapter)s.%(Figure+)s" % seq) gives:z"    Figure %(Chapter)s.%(Figure+)s)
rO   rr   r@   rb   rf   rC   re   ÚjoinÚrangerJ   )r„   r   r‰   r   Útest  sZ   ÿ
ÿ&r�   Ú__main__)Ú__version__rN   ÚsplitÚ__all__r   r   Ú	reportlabr   r   r   r    r)   r,   Ú_type2formatterr2   rO   ru   rv   ry   rR   Úreportlab.rl_configrz   r�   rK   r   r   r   r   Ú<module>   s@   	û2 0
ÿ