U
    '1e                     @   s   d Z dZdZddlZG dd dZedZedZG d	d
 d
eZe	dk rd$ddZ
e
ddddd e
ddddd e
ddddd e
ddddd e
ddd e
ddd e
ddd e
ddd e
ddd e
ddd e
d d!d e
d"d#d dS )%)	FormatterDecimalFormatterz3.3.0z]
These help format numbers and dates in a user friendly way.
Used by the graphics framework.
    Nc                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )r   z5Base formatter - simply applies python format stringsc                 C   s
   || _ d S Npattern)selfr    r   </tmp/pip-unpacked-wheel-109iniqw/reportlab/lib/formatters.py__init__   s    zFormatter.__init__c                 C   s
   | j | S r   r   )r   objr   r   r	   format   s    zFormatter.formatc                 C   s   d| j j| jf S )Nz%s('%s'))	__class____name__r   r   r   r   r	   __repr__   s    zFormatter.__repr__c                 C   s
   |  |S r   )r   )r   xr   r   r	   __call__   s    zFormatter.__call__N)r   
__module____qualname____doc__r
   r   r   r   r   r   r   r	   r      s
   r   z^\d*\.z0+$c                   @   s2   e Zd ZdZdddZdd Zd	d
 Zdd ZdS )r   zlets you specify how to build a decimal.

    A future NumberFormatter class will take Microsoft-style patterns
    instead - "$#,##0.00" is WAY easier than this.   .Nc                 C   s4   |dkr| j | _n|| _|| _|| _|| _|| _d S )Nauto)_calcPlacesZ
calcPlacesplacesdotcommaprefixsuffix)r   r   
decimalSepthousandSepr   r   r   r   r	   r
       s    
zDecimalFormatter.__init__c                 C   s   t dd |D | _dS )zMcalled with the full set of values to be formatted so we can calculate placesc                 S   s(   g | ] }t td td t|qS ) )len_tz_resub_ld_restr).0vr   r   r	   
<listcomp>,   s     z0DecimalFormatter._calcPlaces.<locals>.<listcomp>N)maxr   )r   Vr   r   r	   r   *   s    zDecimalFormatter._calcPlacesc                 C   s"  |dk }|r| }| j | j }}|dk}|r6|r6| }dt| d | }|r|d\}}|| }|r|r|d d|fkr|d d }qhnd}| jd k	rd}|r|dd |dd   }	}
|	dkr|
| }n| j|
 | }|	}q|}|| }|rd	| }| jr| j| }| jr|| j }|S )
Nr   z%.fr   0r!   -)r   r   r&   splitr   r   r   )r   numsignr   sepstripZstrIntZstrFracZstrNewleftrightZstrBodyr   r   r	   r   .   s@      

 

zDecimalFormatter.formatc                 C   s2   d| j j| jt| jt| jt| jt| jf S )NzB%s(places=%d, decimalSep=%s, thousandSep=%s, prefix=%s, suffix=%s))r   r   r   reprr   r   r   r   r   r   r   r	   r   S   s    zDecimalFormatter.__repr__)r   r   NNN)r   r   r   r   r
   r   r   r   r   r   r   r	   r      s
   

%r   __main__r   r   c           	   
   C   sL   t |||||}|| }td|j|j|j|j|j|||kr>dp@df  d S )NzEplaces=%2d dot=%-4s comma=%-4s prefix=%-4s suffix=%-4s result=%10s %sOKBAD)r   printr   r   r   r   r   )	nsr   r   r    r   r   r,   rr   r   r	   t^   s    r@   g33333G@z1,000.9   ,)r    gG@z1,001.0z1,001r-   z1000.9z1001.0Z1001g@@z1000.1gfffffD@z1000.6g;OC@z1000.4gC@Z1000)r   r   NNN)__all____version__r   rer   compiler%   r#   r   r   r@   r   r   r   r	   <module>   s*   

B

