a
    zeF)                     @   s   g d Z ddlZdZdZdZee ZdZed d Zd	Zd
Z	ee e	 e Z
dddZddlZddlmZ i ZG dd dZe  G dd dZdS ))ascii_lettersascii_lowercaseascii_uppercasecapwordsdigits	hexdigits	octdigits	printablepunctuation
whitespace	FormatterTemplate    Nz 	
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789ZabcdefZABCDEF01234567z !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~c                 C   s   |pd dd | |D S )N c                 s   s   | ]}|  V  qd S N)
capitalize).0x r   /usr/lib/python3.9/string.py	<genexpr>0       zcapwords.<locals>.<genexpr>)joinsplit)ssepr   r   r   r   %   s    r   )ChainMapc                       sV   e Zd ZdZdZdZejZ fddZ	dd Z
dd	 Zefd
dZefddZ  ZS )r   $z(?a:[_a-z][_a-z0-9]*)Nc              	      sr   t    d| jv r| j}n<t| j}| j}| jp8| j}d| d| d| d| d	}t	|| j
tjB | _d S )Npatternz
            z(?:
              (?P<escaped>zC)  |   # Escape sequence of two delimiters
              (?P<named>zJ)       |   # delimiter and a Python identifier
              {(?P<braced>z)} |   # delimiter and a braced identifier
              (?P<invalid>)             # Other ill-formed delimiter exprs
            )
            )super__init_subclass____dict__r!   _reescape	delimiter	idpatternbraceidpatterncompileflagsVERBOSE)clsr!   delimidbid	__class__r   r   r#   E   s     

zTemplate.__init_subclass__c                 C   s
   || _ d S r   )template)selfr3   r   r   r   __init__W   s    zTemplate.__init__c                 C   sd   | d}| jd | jdd}|s.d}d}n"|td|d d  }t|}td||f d S )NinvalidT)keepends    z.Invalid placeholder in string: line %d, col %d)startr3   
splitlineslenr   
ValueError)r4   moilinescolnolinenor   r   r   _invalid\   s    
zTemplate._invalidc                   s:    t u r| n|rt|   fdd}j|jS )Nc                    sd   |  dp|  d}|d ur(t | S |  dd ur<jS |  dd urT|  tdjd S Nnamedbracedescapedr6   z#Unrecognized named group in pattern)groupstrr'   rD   r>   r!   r?   rF   mappingr4   r   r   convertn   s    
z$Template.substitute.<locals>.convert_sentinel_dict	_ChainMapr!   subr3   r4   rM   kwsrN   r   rL   r   
substituteh   s    
zTemplate.substitutec                   s:    t u r| n|rt|   fdd}j|jS )Nc                    s   |  dp|  d}|d urFzt | W S  tyD   |    Y S 0 |  dd urZjS |  dd urp|   S tdjd S rE   )rI   rJ   KeyErrorr'   r>   r!   rK   rL   r   r   rN      s    z)Template.safe_substitute.<locals>.convertrO   rS   r   rL   r   safe_substitute{   s    
zTemplate.safe_substitute)__name__
__module____qualname__r'   r(   r)   r%   
IGNORECASEr+   r#   r5   rD   rP   rU   rW   __classcell__r   r   r1   r   r   9   s   r   c                   @   sV   e Z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d Z
dd ZdS )r   c                O   s   |  |||S r   )vformat)r4   format_stringargskwargsr   r   r   format   s    zFormatter.formatc                 C   s.   t  }| ||||d\}}| ||| |S )N   )set_vformatcheck_unused_args)r4   r^   r_   r`   	used_argsresult_r   r   r   r]      s    zFormatter.vformatr   c              	   C   s   |dk rt dg }| |D ]\}}	}
}|r8|| |	d ur|	dkrj|du rXt dt|}	|d7 }n|	 r|r~t dd}| |	||\}}|| | ||}| j|
||||d |d\}
}|| 	||
 qd
||fS )Nr   zMax string recursion exceededr9   FzJcannot switch from manual field specification to automatic field numberingr8   )auto_arg_index)r>   parseappendrJ   isdigit	get_fieldaddconvert_fieldrd   format_fieldr   )r4   r^   r_   r`   rf   recursion_depthri   rg   literal_text
field_nameformat_spec
conversionobjarg_usedr   r   r   rd      s6    



zFormatter._vformatc                 C   s   t |tr|| S || S d S r   )
isinstanceint)r4   keyr_   r`   r   r   r   	get_value   s    
zFormatter.get_valuec                 C   s   d S r   r   )r4   rf   r_   r`   r   r   r   re      s    zFormatter.check_unused_argsc                 C   s
   t ||S r   )ra   )r4   valuert   r   r   r   rp      s    zFormatter.format_fieldc                 C   sN   |d u r|S |dkrt |S |dkr,t|S |dkr<t|S td|d S )Nr   raz"Unknown conversion specifier {0!s})rJ   reprasciir>   ra   )r4   r|   ru   r   r   r   ro      s    zFormatter.convert_fieldc                 C   s
   t |S r   )_stringformatter_parser)r4   r^   r   r   r   rj     s    zFormatter.parsec           	      C   sJ   t |\}}| |||}|D ] \}}|r8t||}q || }q ||fS r   )r   formatter_field_name_splitr{   getattr)	r4   rs   r_   r`   firstrestrv   is_attrr@   r   r   r   rm     s    
zFormatter.get_fieldN)r   )rX   rY   rZ   ra   r]   rd   r{   re   rp   ro   rj   rm   r   r   r   r   r      s    
6	r   )N)__all__r   r
   r   r   r   r   r   r   r	   r   r   rer%   collectionsr   rQ   rP   r   r#   r   r   r   r   r   <module>   s"   
Y