
TRNc           @   s
  d  Z  d d l Z d d l m Z m Z m Z d d l Z y d d l m	 Z	 Wn! e
 k
 rq d d l m	 Z	 n Xd d l m Z m Z d d l m Z d d l m Z d d l m Z m Z d d	 l m Z m Z d d
 l m Z m Z e   Z d   Z d   Z e e _  e e  Z d   Z! e e! _  e e!  Z! da db dc dd de df dg dh di dj dk f Z" e" e# g  e$ d$  D] Z% d% e% d& e% f ^ qr Z& d'   Z' e e'  Z' d(   Z( e e( _  e e(  Z( dl Z) dm Z* dn do Z+ e, e)  e, e*  e, e+  g Z- d d+  Z. e e. _  d,   Z/ e e/ _  e e/  Z/ d d-  Z1 e e1 _  e e1 _2 e e1  Z1 d.   Z3 e e3 _  e e3  Z3 d/   Z4 e5 e4 _  e e4  Z4 d0   Z6 e e6 _  e e6  Z6 d1   Z7 e e7 _  d2   Z8 e e8 _  e e8  Z8 d3   Z9 e e9 _  e e9  Z9 d4   Z: e e: _  e e:  Z: d5   Z; e5 e; _  e e;  Z; d6   Z< e5 e< _  e e<  Z< d d7  Z= e e= _  e e= _2 e e=  Z= d d8  Z> e e> _  e e> _2 e e>  Z> d9   Z? e5 e? _  e e?  Z? d:   Z@ e e@ _  e e@  Z@ d;   ZA e eA _  e eA  ZA d<   ZB e eB _  e eB  ZB d=   ZC e eC _  e eC  ZC d>   ZD e eD  ZD d?   ZE e eE _  e eE  ZE d@   ZF e eF  ZF e eF _  d dA  ZG e eG _  e eG _2 e eG  ZG d dB  ZH e eH _  e eH _2 e eH  ZH dC   ZI e eI _  e eI  ZI dD   ZJ e eJ _  dE   ZK e eK _  e eK  ZK dF   ZL e eL _  e eL  ZL dG   ZM e5 eM _  dH   ZN e5 eN _  dI   ZO e5 eO _  d dJ  ZP e eP _  e eP _2 dK   ZQ e eQ _  dL   ZR e eR _  dM   ZS e5 eS _  dN   Z e e _  dO   ZT e eT _  d dP  ZU e eU _  e eU _2 dQ   ZV e5 eV _  dR   ZW e5 eW _  d dS  ZX e5 eX _  d dT  ZY e5 eY _  d dU  ZZ e5 eZ _  d dV  Z[ e5 e[ _  dW   Z\ e5 e\ _  dX   Z] e5 e] _  dY   Z^ e5 e^ _  d dZ  Z_ e5 e_ _  d[   Z` e e` _  d\ d]  Za e5 ea _  d^   Zb e eb _  d_   Zc e ec _  e jd eV  e jd e  e jd e!  e jd eC  e jd eD  e jd eX  e jd e\  e jd e]  e jd eM  e jd eN  e jd e^  e jd eE  e jd e'  e jd e`  e jd eO  e jd e(  e jd e.  e jd eF  e jd eW  e jd e/  e jd eP  e jd eQ  e jd eR  e jd eS  e jd eG  e jd eH  e jd e1  e jd eA  e jd e3  e jd e4  e jd eb  e jd ea  e jd ec  e jd eK  e jd e  e jd eB  e jd eI  e jd eJ  e jd d` eT  e jd e6  e jd e7  e jd eL  e jd eY  e jd eZ  e jd e[  e jd e8  e jd e9  e jd e:  e jd eU  e jd e;  e jd e<  e jd e=  e jd e>  e jd e?  e jd e@  e jd e_  d S(p   s   Default variable filters.iN(   t   Decimalt   InvalidOperationt   ROUND_HALF_UP(   t   wraps(   t   Variablet   Library(   t   settings(   t   formats(   t   ugettextt	   ungettext(   t   force_unicodet
   iri_to_uri(   t	   mark_safet   SafeDatac            sp     f d   } t    d    | _ x9 d D]1 } t   |  r+ t | | t    |   q+ q+ Wt    |  S(   s   
    Decorator for filters which should only receive unicode objects. The object
    passed as the first positional argument will be converted to a unicode
    object.
    c             sn   |  ra t  |   }  t |  d  |  d <t |  d t  ra t   d t  ra t   |  |    Sn    |  |   S(   Ni    t   is_safe(   t   listR
   t
   isinstanceR   t   getattrt   FalseR   (   t   argst   kwargs(   t   func(    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   _dec   s    %t   _decorated_functionR   t   needs_autoescape(   s   is_safes   needs_autoescape(   R   R   t   hasattrt   setattrR   (   R   R   t   attr(    (   R   sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   stringfilter   s    
 c         C   s(   |  j  d d  j  d d  j  d d  S(   s   
    Adds slashes before quotes. Useful for escaping strings in CSV, for
    example. Less useful for escaping JavaScript; use the ``escapejs``
    filter instead.
    s   \s   \\t   "s   \"t   's   \'(   t   replace(   t   value(    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt
   addslashes2   s    c         C   s   |  o |  d j    |  d S(   s-   Capitalizes the first character of the value.i    i   (   t   upper(   R    (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   capfirst<   s    s   \s   \u005Cs   's   \u0027R   s   \u0022t   >s   \u003Et   <s   \u003Ct   &s   \u0026t   =s   \u003Dt   -s   \u002Dt   ;s   \u003Bu    s   \u2028u    s   \u2029i    s   %cs   \u%04Xc         C   s-   x& t  D] \ } } |  j | |  }  q W|  S(   s5   Hex encodes characters for use in JavaScript strings.(   t   _js_escapesR   (   R    t   badt   good(    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   escapejsT   s    c         C   s   d d l  m } | |   S(   s,   Replaces ampersands with ``&amp;`` entities.i(   t   fix_ampersands(   t   django.utils.htmlR.   (   R    R.   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyR.   [   s    gZbtigZbtc         C   s  y t  |   } t |  } Wno t k
 r0 d St k
 r | t k rM | Sy t t  t |     } Wq t t t t f k
 r d SXn Xy t |  } Wn t k
 r | SXy t |  | } Wn t t	 t f k
 r | SX| r| d k  rt
 t j d t |  d   S| d k r3t d  } n  t d  t d  t |  } y6 t
 t j d t | j | t   t |    SWn t k
 r| SXd S(	   s*  
    Displays a float to a specified number of decimal places.

    If called without an argument, it displays 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, it will 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, it will 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, the (platform-dependent) string
    representation of that value will be displayed.
    u    i    u   %di   s   1.0i
   u   %sN(   R
   R    t   UnicodeEncodeErrorR   t   special_floatst   floatt
   ValueErrort	   TypeErrort   intt   OverflowErrorR   R   t   number_formatt   abst   strt   quantizeR   (   t   textt   argt	   input_valt   dt   pt   mt   exp(    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   floatformatn   s:     	  6c         C   s   t  t |    S(   s&   Escapes an IRI value for use in a URL.(   R
   R   (   R    (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt	   iriencode   s    c         C   s   d d l  m } |  j d  } t t t t |     } | sS t |  t  r x t |  D], \ } } d | d | d | f | | <q` WnC x@ t |  D]2 \ } } d | d | d | |  f | | <q Wt d j	 |   S(   s    Displays text with line numbers.i(   t   escapeu   
u   %0u   d. %si   (
   R/   RD   t   splitt   unicodet   lenR   R   t	   enumerateR   t   join(   R    t
   autoescapeRD   t   linest   widtht   it   line(    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   linenumbers   s    '*c         C   s
   |  j    S(   s%   Converts a string into all lowercase.(   t   lower(   R    (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyRP      s    c         C   s
   t  |   S(   s   
    Returns 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   (   R    (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt	   make_list   s    c         C   sj   d d l  } | j d |   j d d  }  t t j d d |   j   j    }  t t j d d	 |    S(
   su   
    Normalizes string, converts to lowercase, removes non-alpha characters,
    and converts spaces to hyphens.
    iNt   NFKDt   asciit   ignores   [^\w\s-]t    s   [-\s]+R(   (	   t   unicodedatat	   normalizet   encodeRF   t   ret   subt   stripRP   R   (   R    RV   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   slugify   s    'c         C   s5   y d t  |  |  SWn t t f k
 r0 d SXd S(   s0  
    Formats 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 http://docs.python.org/lib/typesseq-strings.html for documentation
    of Python string formatting
    u   %u    N(   RF   R3   R4   (   R    R<   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   stringformat   s    
c         C   s4   t  j d d   |  j    } t  j d d   |  S(   s!   Converts a string into titlecase.s   ([a-z])'([A-Z])c         S   s   |  j  d  j   S(   Ni    (   t   groupRP   (   R@   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   <lambda>   s    s	   \d([A-Z])c         S   s   |  j  d  j   S(   Ni    (   R^   RP   (   R@   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyR_      s    (   RY   RZ   t   title(   R    t   t(    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyR`      s    c         C   sB   d d l  m } y t |  } Wn t k
 r4 |  SX| |  |  S(   so   
    Truncates a string after a certain number of words.

    Argument: Number of words to truncate after.
    i(   t   truncate_words(   t   django.utils.textRb   R5   R3   (   R    R<   Rb   t   length(    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   truncatewords   s    c         C   sB   d d l  m } y t |  } Wn t k
 r4 |  SX| |  |  S(   sk   
    Truncates HTML after a certain number of words.

    Argument: Number of words to truncate after.
    i(   t   truncate_html_words(   Rc   Rf   R5   R3   (   R    R<   Rf   Rd   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   truncatewords_html  s    c         C   s
   |  j    S(   s%   Converts a string into all uppercase.(   R"   (   R    (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyR"     s    c         C   s   d d l  m } | |   S(   s!   Escapes a value for use in a URL.i(   t   urlquote(   t   django.utils.httpRh   (   R    Rh   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt	   urlencode!  s    c         C   s,   d d l  m } t | |  d t d |  S(   s1   Converts URLs in plain text into clickable links.i(   t   urlizet   nofollowRJ   (   R/   Rk   R   t   True(   R    RJ   Rk   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyRk   (  s    c      	   C   s8   d d l  m } t | |  d t |  d t d |  S(   s   
    Converts 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.
    i(   Rk   t   trim_url_limitRl   RJ   (   R/   Rk   R   R5   Rm   (   R    t   limitRJ   Rk   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   urlizetrunc0  s    c         C   s   t  |  j    S(   s   Returns the number of words.(   RG   RE   (   R    (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt	   wordcount>  s    c         C   s#   d d l  m } | |  t |   S(   sh   
    Wraps words at specified line length.

    Argument: number of characters to wrap the text at.
    i(   t   wrap(   Rc   Rr   R5   (   R    R<   Rr   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   wordwrapD  s    c         C   s   |  j  t |   S(   sW   
    Left-aligns the value in a field of a given width.

    Argument: field size.
    (   t   ljustR5   (   R    R<   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyRt   O  s    c         C   s   |  j  t |   S(   sX   
    Right-aligns the value in a field of a given width.

    Argument: field size.
    (   t   rjustR5   (   R    R<   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyRu   Y  s    c         C   s   |  j  t |   S(   s.   Centers the value in a field of a given width.(   t   centerR5   (   R    R<   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyRv   c  s    c         C   sA   t  |  t  } |  j | d  }  | r= | d k r= t |   S|  S(   s:   
    Removes all values of arg from the given string.
    u    R)   (   R   R   R   R   (   R    R<   t   safe(    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   cuti  s
    
c         C   s   d d l  m } | |   S(   sF   
    Marks the value as a string that should not be auto-escaped.
    i(   t   mark_for_escaping(   t   django.utils.safestringRy   (   R    Ry   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyRD   x  s    c         C   s    d d l  m } t | |    S(   s   
    Escapes a string's HTML. This returns a new string containing the escaped
    characters (as opposed to "escape", which marks the content for later
    possible escaping).
    i(   RD   (   R/   RD   R   (   R    RD   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   force_escape  s    c         C   s9   d d l  m } | o# t |  t  } t | |  |   S(   s   
    Replaces 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>``).
    i(   t
   linebreaks(   R/   R|   R   R   R   (   R    RJ   R|   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyR|     s    c         C   sK   | r5 t  |  t  r5 d d l m } | |   }  n  t |  j d d   S(   s^   
    Converts all newlines in a piece of plain text to HTML line breaks
    (``<br />``).
    i(   RD   s   
s   <br />(   R   R   R/   RD   R   R   (   R    RJ   RD   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   linebreaksbr  s    c         C   s
   t  |   S(   sF   
    Marks the value as a string that should not be auto-escaped.
    (   R   (   R    (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyRw     s    c         C   s#   g  |  D] } t  t |   ^ q S(   s   
    A "safe" filter for sequences. Marks each element in the sequence,
    individually, as safe, after converting them to unicode. Returns a list
    with the results.
    (   R   R
   (   R    t   obj(    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   safeseq  s    c         C   s   g  | j    D] } t j |  ^ q } d d j |  } t j d | t j  } t j d |  } | j d |   }  | j d |   }  |  S(   s?   Removes a space separated list of [X]HTML tags from the output.u   (%s)u   |u   <%s(/?>|(\s+[^>]*>))u   </%s>u    (   RE   RY   RD   RI   t   compilet   URZ   (   R    t   tagst   tagt   tags_ret   starttag_ret	   endtag_re(    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt
   removetags  s    (c         C   s   d d l  m } | |   S(   s   Strips all [X]HTML tags.i(   t
   strip_tags(   R/   R   (   R    R   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt	   striptags  s    c         C   sY   t  |  j } g  |  D] } | |  | f ^ q } | j   g  | D] } | d ^ qE S(   sd   
    Takes a list of dicts, returns that list sorted by the property given in
    the argument.
    i   (   R   t   resolvet   sort(   R    R<   t   var_resolvet   itemt	   decorated(    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   dictsort  s    %
c         C   sc   t  |  j } g  |  D] } | |  | f ^ q } | j   | j   g  | D] } | d ^ qO S(   su   
    Takes a list of dicts, returns that list sorted in reverse order by the
    property given in the argument.
    i   (   R   R   R   t   reverse(   R    R<   R   R   R   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   dictsortreversed  s
    %

c         C   s%   y |  d SWn t  k
 r  d SXd S(   s!   Returns the first item in a list.i    u    N(   t
   IndexError(   R    (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   first  s    c         C   sy   t  t |   }  | rG d d l m } g  |  D] } | |  ^ q, }  n  y | j |   } Wn t k
 rn |  SXt |  S(   sG   
    Joins a list with a string, like Python's ``str.join(list)``.
    i(   t   conditional_escape(   t   mapR
   R/   R   RI   t   AttributeErrorR   (   R    R<   RJ   R   t   vt   data(    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyRI     s    "c         C   s%   y |  d SWn t  k
 r  d SXd S(   s   Returns the last item in a listiu    N(   R   (   R    (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   last  s    c         C   s-   y t  |   SWn t t f k
 r( d SXd S(   s3   Returns the length of the value - useful for lists.RU   N(   RG   R3   R4   (   R    (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyRd     s    c         C   s9   y t  |   t |  k SWn t t f k
 r4 d SXd S(   s@   Returns a boolean of whether the value's length is the argument.RU   N(   RG   R5   R3   R4   (   R    R<   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt	   length_is  s    c         C   s   t  j |   S(   s$   Returns a random item from the list.(   t   random_modulet   choice(   R    (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   random  s    c         C   s   yg g  } xL | j  d  D]; } t |  d k rA | j d  q | j t |   q W|  t |   SWn t t f k
 r |  SXd S(   s   
    Returns a slice of the list.

    Uses the same syntax as Python's list slicing; see
    http://diveintopython.org/native_data_types/lists.html#odbchelper.list.slice
    for an introduction.
    u   :i    N(   RE   RG   t   appendt   NoneR5   t   sliceR3   R4   (   R    R<   t   bitst   x(    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   slice_  s    c            sn   | r d d l  m } |  n	 d     f d    d    f d     |   \ }  } t   |    S(   s\  
    Recursively takes a self-nested list and returns an HTML unordered list --
    WITHOUT opening and closing <ul> tags.

    The list is assumed to be in the proper format. For example, if ``var``
    contains: ``['States', ['Kansas', ['Lawrence', 'Topeka'], 'Illinois']]``,
    then ``{{ var|unordered_list }}`` would return::

        <li>States
        <ul>
                <li>Kansas
                <ul>
                        <li>Lawrence</li>
                        <li>Topeka</li>
                </ul>
                </li>
                <li>Illinois</li>
        </ul>
        </li>
    i(   R   c         S   s   |  S(   N(    (   R   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyR_   H  s    c            s   t  |  t t f  s( t |   d k r2 |  t f S|  \ } } | g  k rW | g t f St } g  } x7 | D]/ }   |  \ } } | s Pn  | j |  qj W| r | } n  | | g | f S(   s	  
        Converts old style lists to the new easier to understand format.

        The old list format looked like:
            ['Item 1', [['Item 1.1', []], ['Item 1.2', []]]

        And it is converted to:
            ['Item 1', ['Item 1.1', 'Item 1.2]]
        i   (   R   t   tupleR   RG   R   Rm   t   extend(   t   list_t
   first_itemt   second_itemt   old_style_listt   new_second_itemt   sublistR   (   t   convert_old_style_list(    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyR   I  s    
(
	i   c   
         s-  d | } g  } t  |   } d } x | | k  r|  | } d } d  } t | t t f  rk | } d } nO | | d k  r |  | d }	 |	 r t |	 t t f  r |	 } | d 7} q n  | r   | | d  } d | | | | f } n  | j d |  t |   | f  | d 7} q% Wd j |  S(   Nu   	i    RU   i   s   
%s<ul>
%s
%s</ul>
%ss   %s<li>%s%s</li>s   
(   RG   R   R   R   R   R   R
   RI   (
   R   t   tabst   indentt   outputt   list_lengthRM   R`   R   t   sublist_itemt	   next_item(   t   _helpert   escaper(    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyR   b  s0    

		(   R/   R   R   (   R    RJ   R   t	   converted(    (   R   R   R   sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   unordered_list/  s    		c         C   sM   y t  |   t  |  SWn. t t f k
 rH y |  | SWqI |  SXn Xd S(   s   Adds the arg to the value.N(   R5   R3   R4   (   R    R<   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   add  s    c         C   ss   y t  |  } t  |   }  Wn t k
 r0 |  SX| d k  rA |  Sy t  t |   |  SWn t k
 rn d SXd S(   s4  
    Given a whole number, returns the requested digit of it, where 1 is the
    right-most digit, 2 is the second-right-most digit, etc. Returns 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.
    i   i    N(   R5   R3   R9   R   (   R    R<   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt	   get_digit  s    c         C   s   d d l  m } |  s d S| d k r2 t j } n  y t j |  |  SWn7 t k
 r y | |  |  SWq t k
 r{ d SXn Xd S(   s-   Formats a date according to the given format.i(   t   formatu    RU   N(   t   django.utils.dateformatR   R   R   t   DATE_FORMATR   t   date_formatR   (   R    R<   R   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   date  s    c         C   s   d d l  m } |  d k r  d S| d k r8 t j } n  y t j |  |  SWn: t k
 r y | j |  |  SWq t k
 r d SXn Xd S(   s-   Formats a time according to the given format.i(   t
   dateformatu    RU   N(   Nu    (   t   django.utilsR   R   R   t   TIME_FORMATR   t   time_formatR   (   R    R<   R   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   time  s    c         C   sZ   d d l  m } |  s d Sy! | r0 | |  |  S| |   SWn t t f k
 rU d SXd S(   sD   Formats a date as the time since that date (i.e. "4 days, 6 hours").i(   t	   timesinceu    N(   t   django.utils.timesinceR   R3   R4   (   R    R<   R   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyR     s    c         C   sZ   d d l  m } d d l m } |  s* d Sy | |  |  SWn t t f k
 rU d SXd S(   sD   Formats a date as the time until that date (i.e. "4 days, 6 hours").i(   t	   timeuntil(   t   datetimeu    N(   R   R   R   R3   R4   (   R    R<   R   R   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyR     s    c         C   s
   |  p	 | S(   s+   If value is unavailable, use given default.(    (   R    R<   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   default  s    c         C   s   |  d k r | S|  S(   s$   If value is None, use given default.N(   R   (   R    R<   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   default_if_none  s    c         C   s   t  |   t  |  d k S(   s7   Returns True if the value is devisible by the argument.i    (   R5   (   R    R<   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   divisibleby  s    c         C   s   | d k r t d  } n  | j d  } t |  d k  r@ |  Sy | \ } } } Wn1 t k
 r | d | d | d } } } n X|  d k r | S|  r | S| S(   s  
    Given a string mapping values for true, false and (optionally) None,
    returns one of those strings accoding 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.
    ==========  ======================  ==================================
    s   yes,no,maybeu   ,i   i    i   N(   R   R   RE   RG   R3   (   R    R<   R   t   yest   not   maybe(    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   yesno  s    $c         C   s   y t  |   }  Wn t t t f k
 r- d SX|  d k  rU t d d |   i |  d 6S|  d	 k  rs t d  |  d S|  d k  r t d  |  d St d  |  d S(   sg   
    Formats the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB,
    102 bytes, etc).
    u   0 bytesi   s   %(size)d bytes   %(size)d bytest   sizes   %.1f KBs   %.1f MBs   %.1f GBi   i   i   @i   i   i   @(   R2   R4   R3   t   UnicodeDecodeErrorR	   R   (   t   bytes(    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   filesizeformat  s    u   sc         C   s   d | k r d | } n  | j  d  } t |  d k r> d S| d  \ } } y t |   d k rg | SWnO t k
 r{ n? t k
 r y t |   d k r | SWq t k
 r q Xn X| S(   s  
    Returns a plural suffix if the value is not 1. By default, 's' is used as
    the suffix:

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

    If an argument is provided, that string is used instead:

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

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

    * If value is 0, cand{{ value|pluralize:"y,ies" }} displays "0 candies".
    * If value is 1, cand{{ value|pluralize:"y,ies" }} displays "1 candy".
    * If value is 2, cand{{ value|pluralize:"y,ies" }} displays "2 candies".
    u   ,i   u    i   (   RE   RG   R5   R3   R4   (   R    R<   R   t   singular_suffixt   plural_suffix(    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt	   pluralize/  s$    c         C   s   d d l  m } | |   S(   sD   Takes a phone number and converts it in to its numerical equivalent.i(   t   phone2numeric(   Rc   R   (   R    R   (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyR   [  s    c         C   sI   d d l  m } y | |   SWn$ t k
 rD } d t | d d SXd S(   s8   A wrapper around pprint.pprint -- for debugging, really.i(   t   pformatu   Error in formatting: %st   errorsR   N(   t   pprintR   t	   ExceptionR
   (   R    R   t   e(    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyR   a  s
    R   (   s   \s   \u005C(   s   's   \u0027(   R   s   \u0022(   R$   s   \u003E(   R%   s   \u003C(   R&   s   \u0026(   R'   s   \u003D(   R(   s   \u002D(   R)   s   \u003B(   u    s   \u2028(   u    s   \u2029g      g      g      g      (e   t   __doc__RY   t   decimalR    R   R   R   R   t	   functoolsR   t   ImportErrort   django.utils.functionalt   django.templateR   R   t   django.confR   R   R   t   django.utils.translationR   R	   t   django.utils.encodingR
   R   Rz   R   R   t   registerR   R!   Rm   R   R#   t   _base_js_escapesR   t   ranget   zR*   R-   R.   t   pos_inft   neg_inft   nanR9   R1   RB   RC   R   RO   R   RP   RQ   R   R\   R]   R`   Re   Rg   R"   Rj   Rk   Rp   Rq   Rs   Rt   Ru   Rv   Rx   RD   R{   R|   R}   Rw   R   R   R   R   R   R   RI   R   Rd   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   filter(    (    (    sK   /home/panlixing/Python_Projects/gaeseries/django/template/defaultfilters.pyt   <module>   s  							4				
!A																										
																																					
															Q										
										*					