B
    ª0H[Îd  ã               @   s:  d Z ddlZddlZddlZddlmZmZmZm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZmZmZmZmZmZm Z! ddl"m#Z#m$Z$ ddl%m&Z&m'Z'm(Z(m)Z*m+Z+ ddl,m-Z-m.Z. ddl/m0Z0m1Z1 ddl2m3Z3m4Z4 ddl5m6Z6 e6ƒ Z7dd„ Z8e7j9dd�e8dd„ ƒƒZ:e7j9dd�e8dd„ ƒƒZ;e7 9d¡e8dd„ ƒƒZ<e7j9dd�d•dd „ƒZ=e7j9dd�e8d!d"„ ƒƒZ>e7j9ddd#�e8d–d$d%„ƒƒZ?e7j9dd�e8d&d'„ ƒƒZ@e7j9d(d�e8d)d*„ ƒƒZAe7j9dd�e8d+d,„ ƒƒZ)e7j9dd�d-d.„ ƒZBe7j9dd�e8d/d0„ ƒƒZCe7j9dd�e8d1d2„ ƒƒZDe7j9dd�e8d3d4„ ƒƒZEe7j9dd�e8d5d6„ ƒƒZFe7j9dd�e8d7d8„ ƒƒZGe7j9d(d�e8d9d:„ ƒƒZHe7j9d(d�e8d—d;d<„ƒƒZIe7j9ddd#�e8d˜d=d>„ƒƒZ e7j9ddd#�e8d™d?d@„ƒƒZJe7j9d(d�e8dAdB„ ƒƒZKe7j9dd�e8dCdD„ ƒƒZLe7j9dd�e8dEdF„ ƒƒZMe7j9dd�e8dGdH„ ƒƒZNe7j9dd�e8dIdJ„ ƒƒZOe7j9e8dKdL„ ƒƒZPe7j9dMdd�e8dNdO„ ƒƒZQe7j9dd�e8dPdQ„ ƒƒZRe7j9dRddd#�e8dšdSdT„ƒƒZSe7j9ddd#�e8d›dUdV„ƒƒZTe7j9dd�e8dWdX„ ƒƒZUe7j9dd�dYdZ„ ƒZVe7j9dd�e8d[d\„ ƒƒZWd]d^„ ZXe7j9d(d�d_d`„ ƒZYe7j9d(d�dadb„ ƒZZe7j9d(d�dcdd„ ƒZ[e7j9ddd#�dœdedf„ƒZ\e7j9dd�dgdh„ ƒZ]e7j9d(d�didj„ ƒZ^e7j9d(d�dkdl„ ƒZ_e7j9dd�dmdn„ ƒZe7j9dodd�dpdq„ ƒZ`e7j9ddd#�d�drds„ƒZae7j9d(d�dtdu„ ƒZbe7j9d(d�dvdw„ ƒZce7j9dd(dx�dždydz„ƒZde7j9dd(dx�dŸd{d|„ƒZee7j9d}d(d�d d~d„ƒZfe7j9d€d(d�d¡d�d‚„ƒZge7j9d(d�dƒd„„ ƒZhe7j9d(d�d…d†„ ƒZie7j9d(d�d‡dˆ„ ƒZje7j9d(d�d¢d‰dŠ„ƒZke7j9dd�d‹dŒ„ ƒZle7j9d(d�d£dŽd�„ƒZme7j9d�dd�d‘d’„ ƒZne7j9dd�d“d”„ ƒZdS )¤zDefault variable filters.é    N)ÚROUND_HALF_UPÚContextÚDecimalÚInvalidOperation)Úwraps)Ú
itemgetter)Úpformat)Úquote)Úformats)ÚformatÚtime_format)Ú
iri_to_uri)Úavoid_wrappingÚconditional_escapeÚescapeÚescapejsÚ
linebreaksÚ
strip_tagsÚurlize)ÚSafeDataÚ	mark_safe)Ú	TruncatorÚnormalize_newlinesÚphone2numericÚslugifyÚwrap)Ú	timesinceÚ	timeuntil)ÚgettextÚngettexté   )ÚVariableÚVariableDoesNotExist)ÚLibraryc                s(   ‡ ‡fdd„‰ t ˆdˆƒˆ _tˆƒˆ ƒS )z˜
    Decorator for filters which should only receive strings. The object
    passed as the first positional argument will be converted to a string.
    c                 sP   | rFt | ƒ} t| d ƒ| d< t| d tƒrFtˆ jddƒrFtˆ| |ŽƒS ˆ| |ŽS )Nr   Úis_safeF)ÚlistÚstrÚ
isinstancer   ÚgetattrÚ_decorated_functionr   )ÚargsÚkwargs)Ú_decÚfunc© úbC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\django\template\defaultfilters.pyr,   (   s    zstringfilter.<locals>._decr)   )r(   r)   r   )r-   r.   )r,   r-   r/   Ústringfilter#   s    r0   T)r$   c             C   s   |   dd¡  dd¡  dd¡S )z§
    Add slashes before quotes. Useful for escaping strings in CSV, for
    example. Less useful for escaping JavaScript; use the ``escapejs``
    filter instead.
    ú\z\\ú"z\"ú'z\')Úreplace)Úvaluer.   r.   r/   Ú
addslashes=   s    r6   c             C   s   | o| d   ¡ | dd…  S )z,Capitalize the first character of the value.r   r    N)Úupper)r5   r.   r.   r/   ÚcapfirstH   s    r8   r   c             C   s   t | ƒS )z4Hex encode characters for use in JavaScript strings.)r   )r5   r.   r.   r/   Úescapejs_filterO   s    r9   éÿÿÿÿc             C   sÊ  yt | ƒ}t|ƒ}W nD tk
rX   yttt| ƒƒƒ}W n tttfk
rR   dS X Y nX yt|ƒ}W n tk
rz   |S X yt|ƒ| }W n tttfk
r¦   |S X |sÌ|dk rÌt	t
 dt|ƒ d¡ƒS |dkrÞtdƒ}ntdƒtdƒt|ƒ  }| ¡ }t|d ƒ}||�r|d  n|d 7 }t|ƒ| d }	| |tt|	d�¡ ¡ \}
}}d	d
„ t|ƒD ƒ}x"t|ƒt|ƒk�rˆ| d¡ �qhW | | d¡ |
�r¨| d¡ d t|ƒ¡}t	t
 |t|ƒ¡ƒS )aò  
    Display a float to a specified number of decimal places.

    If called without an argument, display the floating point number with one
    decimal place -- but only if there's a decimal place to be displayed:

    * num1 = 34.23234
    * num2 = 34.00000
    * num3 = 34.26000
    * {{ num1|floatformat }} displays "34.2"
    * {{ num2|floatformat }} displays "34"
    * {{ num3|floatformat }} displays "34.3"

    If arg is positive, always display exactly arg number of decimal places:

    * {{ num1|floatformat:3 }} displays "34.232"
    * {{ num2|floatformat:3 }} displays "34.000"
    * {{ num3|floatformat:3 }} displays "34.260"

    If arg is negative, display arg number of decimal places -- but only if
    there are places to be displayed:

    * {{ num1|floatformat:"-3" }} displays "34.232"
    * {{ num2|floatformat:"-3" }} displays "34"
    * {{ num3|floatformat:"-3" }} displays "34.260"

    If the input float is infinity or NaN, display the string representation
    of that value.
    Ú r   z%dr    z1.0é
   é   )Úprecc             S   s   g | ]}t |ƒ‘qS r.   )r&   )Ú.0Údigitr.   r.   r/   ú
<listcomp>—   s    zfloatformat.<locals>.<listcomp>Ú0Ú.ú-)Úreprr   r   r&   ÚfloatÚ
ValueErrorÚ	TypeErrorÚintÚOverflowErrorr   r
   Únumber_formatÚabsÚas_tupleÚlenÚquantizer   r   ÚreversedÚappendÚinsertÚjoin)ÚtextÚargZ	input_valÚdÚpÚmÚexpZtuplZunitsr>   ÚsignÚdigitsÚexponentÚnumberr.   r.   r/   ÚfloatformatV   sD    

r^   c             C   s   t | ƒS )z%Escape an IRI value for use in a URL.)r   )r5   r.   r.   r/   Ú	iriencode¡   s    r_   )r$   Zneeds_autoescapec             C   s¤   |   d¡}tttt|ƒƒƒƒ}|r,t| tƒr`xht|ƒD ]$\}}d| d |d |f ||< q6W n6x4t|ƒD ](\}}d| d |d t|ƒf ||< qjW td |¡ƒS )zDisplay text with line numbers.Ú
z%0zd. %sr    )	Úsplitr&   rN   r'   r   Ú	enumerater   r   rS   )r5   Ú
autoescapeÚlinesÚwidthÚiÚliner.   r.   r/   Úlinenumbers¨   s    
"$rh   c             C   s   |   ¡ S )z$Convert a string into all lowercase.)Úlower)r5   r.   r.   r/   ri   ¹   s    ri   Fc             C   s   t | ƒS )z‡
    Return the value turned into a list.

    For an integer, it's a list of digits.
    For a string, it's a list of characters.
    )r%   )r5   r.   r.   r/   Ú	make_listÀ   s    	rj   c             C   s   t | ƒS )zÆ
    Convert to ASCII. Convert spaces to hyphens. Remove characters that aren't
    alphanumerics, underscores, or hyphens. Convert to lowercase. Also strip
    leading and trailing whitespace.
    )Ú_slugify)r5   r.   r.   r/   r   Ì   s    r   c          	   C   s@   t | tƒrt| ƒ} ydt|ƒ |  S  ttfk
r:   dS X dS )aN  
    Format the variable according to the arg, a string formatting specifier.

    This specifier uses Python string formating syntax, with the exception that
    the leading "%" is dropped.

    See https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting
    for documentation of Python string formatting.
    ú%r;   N)r'   Útupler&   rG   rH   )r5   rU   r.   r.   r/   Ústringformat×   s    
rn   c             C   s(   t  ddd„ |  ¡ ¡}t  ddd„ |¡S )z Convert a string into titlecase.z([a-z])'([A-Z])c             S   s   |   d¡ ¡ S )Nr   )Úgroupri   )rX   r.   r.   r/   Ú<lambda>î   s    ztitle.<locals>.<lambda>z	\d([A-Z])c             S   s   |   d¡ ¡ S )Nr   )ro   ri   )rX   r.   r.   r/   rp   ï   s    )ÚreÚsubÚtitle)r5   Útr.   r.   r/   rs   ê   s    rs   c             C   s0   yt |ƒ}W n tk
r    | S X t| ƒ |¡S )z3Truncate a string after `arg` number of characters.)rI   rG   r   Úchars)r5   rU   Úlengthr.   r.   r/   Útruncatecharsò   s
    rw   c             C   s4   yt |ƒ}W n tk
r    | S X t| ƒj|dd�S )zW
    Truncate HTML after `arg` number of chars.
    Preserve newlines in the HTML.
    T)Úhtml)rI   rG   r   ru   )r5   rU   rv   r.   r.   r/   Útruncatechars_htmlý   s
    ry   c             C   s4   yt |ƒ}W n tk
r    | S X t| ƒj|dd�S )z_
    Truncate a string after `arg` number of words.
    Remove newlines within the string.
    z ...)Útruncate)rI   rG   r   Úwords)r5   rU   rv   r.   r.   r/   Útruncatewords  s
    r|   c             C   s6   yt |ƒ}W n tk
r    | S X t| ƒj|ddd�S )zW
    Truncate HTML after `arg` number of words.
    Preserve newlines in the HTML.
    Tz ...)rx   rz   )rI   rG   r   r{   )r5   rU   rv   r.   r.   r/   Útruncatewords_html  s
    r}   c             C   s   |   ¡ S )z$Convert a string into all uppercase.)r7   )r5   r.   r.   r/   r7   '  s    r7   c             C   s    i }|dk	r||d< t | f|ŽS )a&  
    Escape a value for use in a URL.

    The ``safe`` parameter determines the characters which should not be
    escaped by Python's quote() function. If not provided, use the default safe
    characters (but an empty string can be provided when *all* characters
    should be escaped).
    NÚsafe)r	   )r5   r~   r+   r.   r.   r/   Ú	urlencode.  s    r   c             C   s   t t| d|d�ƒS )z0Convert URLs in plain text into clickable links.T)Únofollowrc   )r   Ú_urlize)r5   rc   r.   r.   r/   r   ?  s    r   c             C   s   t t| t|ƒd|d�ƒS )zÅ
    Convert URLs into clickable links, truncating URLs to the given character
    limit, and adding 'rel=nofollow' attribute to discourage spamming.

    Argument: Length to truncate URLs to.
    T)Ztrim_url_limitr€   rc   )r   r�   rI   )r5   Úlimitrc   r.   r.   r/   ÚurlizetruncF  s    	rƒ   c             C   s   t |  ¡ ƒS )zReturn the number of words.)rN   ra   )r5   r.   r.   r/   Ú	wordcountR  s    r„   c             C   s   t | t|ƒƒS )z Wrap words at `arg` line length.)r   rI   )r5   rU   r.   r.   r/   ÚwordwrapY  s    r…   c             C   s   |   t|ƒ¡S )z1Left-align the value in a field of a given width.)ÚljustrI   )r5   rU   r.   r.   r/   r†   `  s    r†   c             C   s   |   t|ƒ¡S )z2Right-align the value in a field of a given width.)ÚrjustrI   )r5   rU   r.   r.   r/   r‡   g  s    r‡   c             C   s   |   t|ƒ¡S )z-Center the value in a field of a given width.)ÚcenterrI   )r5   rU   r.   r.   r/   rˆ   n  s    rˆ   c             C   s.   t | tƒ}|  |d¡} |r*|dkr*t| ƒS | S )z/Remove all values of arg from the given string.r;   ú;)r'   r   r4   r   )r5   rU   r~   r.   r.   r/   Úcutu  s
    
rŠ   r   c             C   s   t | ƒS )z7Mark the value as a string that should be auto-escaped.)r   )r5   r.   r.   r/   Úescape_filter„  s    r‹   c             C   s   t | ƒS )z®
    Escape a string's HTML. Return a new string containing the escaped
    characters (as opposed to "escape", which marks the content for later
    possible escaping).
    )r   )r5   r.   r.   r/   Úforce_escape‹  s    rŒ   r   c             C   s   |ot | tƒ }tt| |ƒƒS )zÑ
    Replace line breaks in plain text with appropriate HTML; a single
    newline becomes an HTML line break (``<br />``) and a new line
    followed by a blank line becomes a paragraph break (``</p>``).
    )r'   r   r   r   )r5   rc   r.   r.   r/   Úlinebreaks_filter–  s    r�   c             C   s4   |ot | tƒ }t| ƒ} |r$t| ƒ} t|  dd¡ƒS )z]
    Convert all newlines in a piece of plain text to HTML line breaks
    (``<br />``).
    r`   z<br />)r'   r   r   r   r   r4   )r5   rc   r.   r.   r/   Úlinebreaksbr¢  s
    rŽ   c             C   s   t | ƒS )z;Mark the value as a string that should not be auto-escaped.)r   )r5   r.   r.   r/   r~   °  s    r~   c             C   s   dd„ | D ƒS )z¬
    A "safe" filter for sequences. Mark each element in the sequence,
    individually, as safe, after converting them to strings. Return a list
    with the results.
    c             S   s   g | ]}t t|ƒƒ‘qS r.   )r   r&   )r?   Úobjr.   r.   r/   rA   ¾  s    zsafeseq.<locals>.<listcomp>r.   )r5   r.   r.   r/   Úsafeseq·  s    r�   c             C   s   t | ƒS )zStrip all [X]HTML tags.)r   )r5   r.   r.   r/   Ú	striptagsÁ  s    r‘   c             C   s4   yt | ƒ W n tk
r&   t| ƒjS X t| ƒS dS )a¶  
    When arg is convertible to float, behave like operator.itemgetter(arg)
    Otherwise, behave like Variable(arg).resolve

    >>> _property_resolver(1)('abc')
    'b'
    >>> _property_resolver('1')('abc')
    Traceback (most recent call last):
    ...
    TypeError: string indices must be integers
    >>> class Foo:
    ...     a = 42
    ...     b = 3.14
    ...     c = 'Hey!'
    >>> _property_resolver('b')(Foo())
    3.14
    N)rF   rG   r!   Úresolver   )rU   r.   r.   r/   Ú_property_resolverÌ  s
    r“   c          	   C   s.   yt | t|ƒd�S  ttfk
r(   dS X dS )zc
    Given a list of dicts, return that list sorted by the property given in
    the argument.
    )Úkeyr;   N)Úsortedr“   rH   r"   )r5   rU   r.   r.   r/   Údictsortæ  s    r–   c          	   C   s0   yt | t|ƒdd�S  ttfk
r*   dS X dS )zt
    Given a list of dicts, return that list sorted in reverse order by the
    property given in the argument.
    T)r”   Úreverser;   N)r•   r“   rH   r"   )r5   rU   r.   r.   r/   Údictsortreversedò  s    r˜   c             C   s"   y| d S  t k
r   dS X dS )z Return the first item in a list.r   r;   N)Ú
IndexError)r5   r.   r.   r/   Úfirstþ  s    rš   c             C   sB   |rdd„ | D ƒ} yt |ƒ | ¡}W n tk
r8   | S X t|ƒS )z<Join a list with a string, like Python's ``str.join(list)``.c             S   s   g | ]}t |ƒ‘qS r.   )r   )r?   Úvr.   r.   r/   rA     s    zjoin.<locals>.<listcomp>)r   rS   ÚAttributeErrorr   )r5   rU   rc   Údatar.   r.   r/   rS     s    rS   c             C   s"   y| d S  t k
r   dS X dS )zReturn the last item in a list.r:   r;   N)r™   )r5   r.   r.   r/   Úlast  s    rž   c          	   C   s&   yt | ƒS  ttfk
r    dS X dS )z2Return the length of the value - useful for lists.r   N)rN   rG   rH   )r5   r.   r.   r/   rv     s    rv   c          	   C   s.   yt | ƒt|ƒkS  ttfk
r(   dS X dS )z?Return a boolean of whether the value's length is the argument.r;   N)rN   rI   rG   rH   )r5   rU   r.   r.   r/   Ú	length_is%  s    rŸ   c             C   s
   t  | ¡S )z#Return a random item from the list.)Úrandom_moduleÚchoice)r5   r.   r.   r/   Úrandom.  s    r¢   Úslicec          	   C   sh   yJg }x8|  d¡D ]*}t|ƒdkr.| d¡ q| t|ƒ¡ qW | t|Ž  S  ttfk
rb   | S X dS )zT
    Return a slice of the list using the same syntax as Python's list slicing.
    ú:r   N)ra   rN   rQ   rI   r£   rG   rH   )r5   rU   ÚbitsÚxr.   r.   r/   Úslice_filter4  s    r§   c                s8   |r
t ‰ ndd„ ‰ dd„ ‰d‡ ‡‡fdd„	‰tˆ| ƒƒS )	aN  
    Recursively take a self-nested list and return an HTML unordered list --
    WITHOUT opening and closing <ul> tags.

    Assume the list is in the proper format. For example, if ``var`` contains:
    ``['States', ['Kansas', ['Lawrence', 'Topeka'], 'Illinois']]``, then
    ``{{ var|unordered_list }}`` returns::

        <li>States
        <ul>
                <li>Kansas
                <ul>
                        <li>Lawrence</li>
                        <li>Topeka</li>
                </ul>
                </li>
                <li>Illinois</li>
        </ul>
        </li>
    c             S   s   | S )Nr.   )r¦   r.   r.   r/   Úescaper_  s    zunordered_list.<locals>.escaperc             s   s¸   t | ƒ}y–t|ƒ}xˆyt|ƒ}W n  tk
r@   |d fV  P Y nX t|tttjfƒrŠyt |ƒ W n tk
rt   Y nX ||fV  t|ƒ}q|d fV  |}qW W n tk
r²   Y nX d S )N)	ÚiterÚnextÚStopIterationr'   r%   rm   ÚtypesÚGeneratorTyperH   )Ú	item_listZitem_iteratorÚitemZ	next_itemr.   r.   r/   Ú
walk_itemsb  s*    


z"unordered_list.<locals>.walk_itemsr    c                sf   d| }g }xNˆ| ƒD ]B\}}d}|r@d|ˆ||d ƒ||f }|  d|ˆ |ƒ|f ¡ qW d |¡S )Nú	r;   z
%s<ul>
%s
%s</ul>
%sr    z%s<li>%s%s</li>r`   )rQ   rS   )r®   ÚtabsÚindentÚoutputr¯   ÚchildrenZsublist)r¨   Úlist_formatterr°   r.   r/   r¶   z  s    z&unordered_list.<locals>.list_formatter)r    )r   r   )r5   rc   r.   )r¨   r¶   r°   r/   Úunordered_listF  s    r·   c             C   sL   yt | ƒt |ƒ S  ttfk
rF   y| | S  tk
r@   dS X Y nX dS )zAdd the arg to the value.r;   N)rI   rG   rH   Ú	Exception)r5   rU   r.   r.   r/   Úadd�  s    r¹   c             C   sb   yt |ƒ}t | ƒ} W n tk
r(   | S X |dk r6| S yt t| ƒ|  ƒS  tk
r\   dS X dS )a2  
    Given a whole number, return the requested digit of it, where 1 is the
    right-most digit, 2 is the second-right-most digit, etc. Return the
    original value for invalid input (if input or argument is not an integer,
    or if argument is less than 1). Otherwise, output is always an integer.
    r    r   N)rI   rG   r&   r™   )r5   rU   r.   r.   r/   Ú	get_digit™  s    rº   )Zexpects_localtimer$   c             C   sR   | dkrdS yt  | |¡S  tk
rL   y
t| |ƒS  tk
rF   dS X Y nX dS )z,Format a date according to the given format.)Nr;   r;   N)r
   Zdate_formatrœ   r   )r5   rU   r.   r.   r/   Údate²  s    
r»   c             C   sZ   | dkrdS yt  | |¡S  ttfk
rT   y
t| |ƒS  ttfk
rN   dS X Y nX dS )z,Format a time according to the given format.)Nr;   r;   N)r
   r   rœ   rH   )r5   rU   r.   r.   r/   ÚtimeÀ  s    
r¼   r   c          	   C   s<   | sdS y|rt | |ƒS t | ƒS  ttfk
r6   dS X dS )zCFormat a date as the time since that date (i.e. "4 days, 6 hours").r;   N)r   rG   rH   )r5   rU   r.   r.   r/   Útimesince_filterÎ  s    
r½   r   c          	   C   s0   | sdS y
t | |ƒS  ttfk
r*   dS X dS )zCFormat a date as the time until that date (i.e. "4 days, 6 hours").r;   N)r   rG   rH   )r5   rU   r.   r.   r/   Útimeuntil_filterÛ  s    
r¾   c             C   s   | p|S )z+If value is unavailable, use given default.r.   )r5   rU   r.   r.   r/   Údefaultê  s    r¿   c             C   s   | dkr|S | S )z$If value is None, use given default.Nr.   )r5   rU   r.   r.   r/   Údefault_if_noneð  s    rÀ   c             C   s   t | ƒt |ƒ dkS )z6Return True if the value is divisible by the argument.r   )rI   )r5   rU   r.   r.   r/   Údivisiblebyø  s    rÁ   c             C   s‚   |dkrt dƒ}| d¡}t|ƒdk r*| S y|\}}}W n0 tk
rh   |d |d |d   }}}Y nX | dkrv|S | r~|S |S )a½  
    Given a string mapping values for true, false, and (optionally) None,
    return one of those strings according to the value:

    ==========  ======================  ==================================
    Value       Argument                Outputs
    ==========  ======================  ==================================
    ``True``    ``"yeah,no,maybe"``     ``yeah``
    ``False``   ``"yeah,no,maybe"``     ``no``
    ``None``    ``"yeah,no,maybe"``     ``maybe``
    ``None``    ``"yeah,no"``           ``"no"`` (converts None to False
                                        if no mapping for None is given.
    ==========  ======================  ==================================
    Nzyes,no,maybeú,r=   r   r    )r   ra   rN   rG   )r5   rU   r¥   ÚyesÚnoÚmayber.   r.   r/   Úyesnoþ  s    
"rÆ   c       	   
   C   s0  yt | ƒ} W n2 tttfk
r>   tdddƒddi }t|ƒS X dd„ }d}d}d	}d
}d}| dk }|rn|  } | |k rŒtdd| ƒd| i }nŽ| |k rªtdƒ|| | ƒ }np| |k rÈtdƒ|| | ƒ }nR| |k ræt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  t| dƒd¡S )Nr    )r
   rK   Úround)r5   r.   r.   r/   Úfilesize_number_format/  s    z.filesizeformat.<locals>.filesize_number_formati   i   i   @l        l           z%s KBz%s MBz%s GBz%s TBz%s PBz-%s)rF   rH   rG   ÚUnicodeDecodeErrorr   r   r   )	Úbytes_r5   rÉ   ZKBZMBZGBZTBZPBÚnegativer.   r.   r/   Úfilesizeformat#  s8    

rÍ   Úsc             C   s¤   d|krd| }|  d¡}t|ƒdkr*dS |dd… \}}yt| ƒdkrL|S W nP tk
rb   Y n> tk
rž   yt| ƒdkr‚|S W n tk
r˜   Y nX Y nX |S )a¸  
    Return a plural suffix if the value is not 1. By default, use 's' as the
    suffix:

    * If value is 0, vote{{ value|pluralize }} display "0 votes".
    * If value is 1, vote{{ value|pluralize }} display "1 vote".
    * If value is 2, vote{{ value|pluralize }} display "2 votes".

    If an argument is provided, use that string instead:

    * If value is 0, class{{ value|pluralize:"es" }} display "0 classes".
    * If value is 1, class{{ value|pluralize:"es" }} display "1 class".
    * If value is 2, class{{ value|pluralize:"es" }} display "2 classes".

    If the provided argument contains a comma, use the text before the comma
    for the singular case and the text after the comma for the plural case:

    * If value is 0, cand{{ value|pluralize:"y,ies" }} display "0 candies".
    * If value is 1, cand{{ value|pluralize:"y,ies" }} display "1 candy".
    * If value is 2, cand{{ value|pluralize:"y,ies" }} display "2 candies".
    rÂ   r=   r;   Nr    )ra   rN   rF   rG   rH   )r5   rU   r¥   Zsingular_suffixZplural_suffixr.   r.   r/   Ú	pluralizeN  s$    
rÏ   r   c             C   s   t | ƒS )zCTake a phone number and converts it in to its numerical equivalent.)r   )r5   r.   r.   r/   Úphone2numeric_filterz  s    rÐ   c          
   C   s<   yt | ƒS  tk
r6 } zd|jj|f S d}~X Y nX dS )z8A wrapper around pprint.pprint -- for debugging, really.zError in formatting: %s: %sN)r   r¸   Ú	__class__Ú__name__)r5   Úer.   r.   r/   Úpprint€  s    rÔ   )r:   )T)N)T)T)T)T)T)T)N)N)N)N)N)rÎ   )oÚ__doc__r¢   r    rq   r¬   Údecimalr   r   r   r   Ú	functoolsr   Úoperatorr   rÔ   r   Úurllib.parser	   Zdjango.utilsr
   Zdjango.utils.dateformatr   r   Zdjango.utils.encodingr   Zdjango.utils.htmlr   r   r   r   r   r   r   r�   Zdjango.utils.safestringr   r   Zdjango.utils.textr   r   r   r   rk   r   Zdjango.utils.timesincer   r   Zdjango.utils.translationr   r   Úbaser!   r"   Zlibraryr#   Úregisterr0   Úfilterr6   r8   r9   r^   r_   rh   ri   rj   rn   rs   rw   ry   r|   r}   r7   r   rƒ   r„   r…   r†   r‡   rˆ   rŠ   r‹   rŒ   r�   rŽ   r~   r�   r‘   r“   r–   r˜   rš   rS   rž   rv   rŸ   r§   r·   r¹   rº   r»   r¼   r½   r¾   r¿   rÀ   rÁ   rÆ   rÍ   rÏ   rÐ   r.   r.   r.   r/   Ú<module>   sò   $



J

























				F
$+
+