a
    Dg                     @   s   d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
 d dlmZ d dlmZmZ ejjjZejjjjjZdddd	ZdddZdd Zdd Zdd ZdS )    )DecimalN)ImproperlyConfigured)formats)avoid_wrapping)gettextngettextuse_l10nc                 O   s.   | du s| dkr"t |d| i|S tdd S )NFexplicitr	   zA number was used directly on a template. Numbers output on templates should be passed through one of |intcomma, |localize, |unlocalize or |filesizeformat to avoid issues with USE_THOUSAND_SEPARATOR.)original_numberformatr   )r	   argskwargs r   X/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/test/numberformat.pypatched_numberformat   s
    r   Tc              	   C   s\   |rPzt | ttfst| } W n  ttfy>   t| d Y S 0 tj| dddS t| |dS )NFr
   T)r	   Zforce_groupingr   )	
isinstancefloatr   int	TypeError
ValueErrororiginal_intcommar   number_format)valuer	   r   r   r   patched_intcomma!   s    r   c           	   
   C   s2  zt | } W n4 tttfy@   tdddddi }t| Y S 0 dd }d}d}d	}d
}d}| dk }|rp|  } | |k rtdd| d| i }n| |k rtd|| |  }np| |k rtd|| |  }nR| |k rtd|| |  }n4| |k rtd|| |  }ntd|| |  }|r*d| }t|S )zg
    Format the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB,
    102 bytes, etc.).
    z%(size)d bytez%(size)d bytesr   sizec                 S   s   t jt| ddddS )N   r
   r   )r   r   roundr   r   r   r   filesize_number_format;   s    z6patched_filesizeformat.<locals>.filesize_number_formati   i   i   @l        l           z%s KBz%s MBz%s GBz%s TBz%s PBz-%s)r   r   r   UnicodeDecodeErrorr   r   r   )	bytes_r   r   ZKBZMBZGBZTBZPBnegativer   r   r   patched_filesizeformat0   s8    
r"   c                 C   s   t tj| ddS )Nr
   r   )strr   localizer   r   r   r   patched_localizeZ   s    r%   c                   C   s\   t tjj_ttjjjj_	t
tjj_tjjjjdt
dd ttjj_tjjjjdtdd d S )NfilesizeformatT)is_safer$   F)r   djangoutilsnumberformatformatr   contribhumanizetemplatetagsintcommar"   templateZdefaultfiltersr&   registerfilterr%   Zl10nr$   r   r   r   r   patch_number_formats^   s    




r3   )T)decimalr   Z-django.contrib.humanize.templatetags.humanizer(   Zdjango.template.defaultfiltersZdjango.templatetags.l10nZdjango.utils.numberformatZdjango.core.exceptionsr   Zdjango.utilsr   Zdjango.utils.htmlr   Zdjango.utils.translationr   r   r)   r*   r+   r   r,   r-   r.   r/   r   r   r   r"   r%   r3   r   r   r   r   <module>   s   

*