o
    h                     @   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)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   Y/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/wagtail/test/numberformat.pypatched_numberformat   s
   r   Tc              	   C   s\   |r(zt | ttfst| } W n ttfy   t| d Y S w tj| dddS t| |dS )NFr
   T)r	   force_groupingr   )	
isinstancefloatr   int	TypeError
ValueErrororiginal_intcommar   number_format)valuer	   r   r   r   patched_intcomma!   s   r   c           	   
   C   s.  zt | } W n tttfy    tdddddi }t| Y S w dd }d}d}d	}d
}d}| dk }|r8|  } | |k rGtdd| d| i }nF| |k rVtd|| |  }n7| |k retd|| |  }n(| |k rttd|| |  }n| |k rtd|| |  }n
td|| |  }|rd| }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   KBMBGBTBPBnegativer   r   r   patched_filesizeformat0   s:   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(   templatedefaultfiltersr,   registerfilterr+   l10nr*   r   r   r   r   patch_number_formats^   s   





r;   )T)decimalr   -django.contrib.humanize.templatetags.humanizer.   django.template.defaultfiltersdjango.templatetags.l10ndjango.utils.numberformatdjango.core.exceptionsr   django.utilsr   django.utils.htmlr   django.utils.translationr   r   r/   r0   r1   r   r2   r3   r4   r5   r   r   r   r(   r+   r;   r   r   r   r   <module>   s    

*