B
    u9a,-                 @   s   d ddddddddd	d
dg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 G dd deZG dd dedZG dd
 d
ZdS )ascii_lettersascii_lowercaseascii_uppercasecapwordsdigits	hexdigits	octdigits	printablepunctuation
whitespace	FormatterTemplate    Nz 	
ZabcdefghijklmnopqrstuvwxyzZABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789ZabcdefZABCDEFZ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.7/string.py	<genexpr>0   s    zcapwords.<locals>.<genexpr>)joinsplit)ssepr   r   r   r   %   s    )ChainMapc                   s    e Zd ZdZ fddZ  ZS )_TemplateMetaclassa/  
    %(delim)s(?:
      (?P<escaped>%(delim)s) |   # Escape sequence of two delimiters
      (?P<named>%(id)s)      |   # delimiter and a Python identifier
      {(?P<braced>%(bid)s)}  |   # delimiter and a braced identifier
      (?P<invalid>)              # Other ill-formed delimiter exprs
    )
    c                sb   t t| ||| d|kr$| j}n$tjt| j| j| jp@| jd }t	|| j
tjB | _d S )Npattern)ZdelimidZbid)superr   __init__r   _reescape	delimiter	idpatternbraceidpatterncompileflagsVERBOSE)clsnamebasesZdctr   )	__class__r   r   r   A   s    
z_TemplateMetaclass.__init__)__name__
__module____qualname__r   r   __classcell__r   r   )r+   r   r   7   s   r   c               @   s>   e Zd ZdZdZdZejZdd Z	dd Z
dd	 Zd
d ZdS )r   $z(?a:[_a-z][_a-z0-9]*)Nc             C   s
   || _ d S )N)template)selfr1   r   r   r   r   Z   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)startr1   
splitlineslenr   
ValueError)r2   moilinescolnolinenor   r   r   _invalid_   s    
zTemplate._invalidc                 sl   | st d| ^} t| dkr(t d| s2| n|rFt|| d  n| d   fdd}j|jS )Nz>descriptor 'substitute' of 'Template' object needs an argumentr5   zToo many positional argumentsr   c                sd   |  dp|  d}|d k	r(t | S |  dd k	r<jS |  dd k	rT|  tdjd S )Nnamedbracedescapedr3   z#Unrecognized named group in pattern)groupstrr"   rA   r;   r   )r<   rB   )mappingr2   r   r   converty   s    
z$Template.substitute.<locals>.convert)	TypeErrorr:   	_ChainMapr   subr1   )argskwsrH   r   )rG   r2   r   
substitutek   s    zTemplate.substitutec                 sl   | st d| ^} t| dkr(t d| s2| n|rFt|| d  n| d   fdd}j|jS )NzCdescriptor 'safe_substitute' of 'Template' object needs an argumentr5   zToo many positional argumentsr   c                s|   |  dp|  d}|d k	rByt | S  tk
r@   |   S X |  dd k	rVjS |  dd k	rl|   S tdjd S )NrB   rC   rD   r3   z#Unrecognized named group in pattern)rE   rF   KeyErrorr"   r;   r   )r<   rB   )rG   r2   r   r   rH      s    
z)Template.safe_substitute.<locals>.convert)rI   r:   rJ   r   rK   r1   )rL   rM   rH   r   )rG   r2   r   safe_substitute   s    zTemplate.safe_substitute)r,   r-   r.   r"   r#   r$   r    
IGNORECASEr&   r   rA   rN   rP   r   r   r   r   r   N   s   )	metaclassc               @   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   sN   | st d| ^}} y| ^}} W n tk
r>   t dd Y nX ||| |S )Nz;descriptor 'format' of 'Formatter' object needs an argumentz@format() missing 1 required positional argument: 'format_string')rI   r;   vformat)rL   kwargsr2   format_stringr   r   r   format   s    
zFormatter.formatc             C   s.   t  }| ||||d\}}| ||| |S )N   )set_vformatcheck_unused_args)r2   rU   rL   rT   	used_argsresult_r   r   r   rS      s    zFormatter.vformatr   c          	   C   s   |dk rt dg }x| |D ]\}}	}
}|r:|| |	d k	r |	dkrl|dkrZt dt|}	|d7 }n|	 r|rt dd}| |	||\}}|| | ||}| j|
||||d |d\}
}|| 	||
 q W d
||fS )Nr   zMax string recursion exceededr6   FzJcannot switch from manual field specification to automatic field numberingr5   )auto_arg_index)r;   parseappendrF   isdigit	get_fieldaddconvert_fieldrY   format_fieldr   )r2   rU   rL   rT   r[   Zrecursion_depthr^   r\   Zliteral_text
field_nameformat_spec
conversionobjZarg_usedr   r   r   rY      s4    


zFormatter._vformatc             C   s   t |tr|| S || S d S )N)
isinstanceint)r2   keyrL   rT   r   r   r   	get_value   s    
zFormatter.get_valuec             C   s   d S )Nr   )r2   r[   rL   rT   r   r   r   rZ      s    zFormatter.check_unused_argsc             C   s
   t ||S )N)rV   )r2   valuerg   r   r   r   re     s    zFormatter.format_fieldc             C   sN   |d k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})rF   reprasciir;   rV   )r2   rn   rh   r   r   r   rd     s    zFormatter.convert_fieldc             C   s
   t |S )N)_stringZformatter_parser)r2   rU   r   r   r   r_     s    zFormatter.parsec       	      C   sN   t |\}}| |||}x(|D ] \}}|r:t||}q"|| }q"W ||fS )N)rs   Zformatter_field_name_splitrm   getattr)	r2   rf   rL   rT   firstrestri   Zis_attrr=   r   r   r   rb   $  s    zFormatter.get_fieldN)r   )r,   r-   r.   rV   rS   rY   rm   rZ   re   rd   r_   rb   r   r   r   r   r      s   
5	)N)__all__rs   r
   r   r   r   r   r   r   r	   r   r   rer    collectionsr   rJ   typer   r   r   r   r   r   r   <module>   s$   


a