<s> """<STR_LIT>""" <EOL> import re <EOL> import random as random_module <EOL> import unicodedata <EOL> from decimal import Decimal , InvalidOperation , Context , ROUND_HALF_UP <EOL> from functools import wraps <EOL> from pprint import pformat <EOL> from django . template . base import Variable , Library , VariableDoesNotExist <EOL> from django . conf import settings <EOL> from django . utils import formats <EOL> from django . utils . dateformat import format , time_format <EOL> from django . utils . encoding import force_unicode , iri_to_uri <EOL> from django . utils . html import ( conditional_escape , escapejs , fix_ampersands , <EOL> escape , urlize as urlize_impl , linebreaks , strip_tags ) <EOL> from django . utils . http import urlquote <EOL> from django . utils . text import Truncator , wrap , phone2numeric <EOL> from django . utils . safestring import mark_safe , SafeData , mark_for_escaping <EOL> from django . utils . timesince import timesince , timeuntil <EOL> from django . utils . translation import ugettext , ungettext <EOL> from django . utils . text import normalize_newlines <EOL> register = Library ( ) <EOL> def stringfilter ( func ) : <EOL> """<STR_LIT>""" <EOL> def _dec ( * args , ** kwargs ) : <EOL> if args : <EOL> args = list ( args ) <EOL> args [ <NUM_LIT:0> ] = force_unicode ( args [ <NUM_LIT:0> ] ) <EOL> if ( isinstance ( args [ <NUM_LIT:0> ] , SafeData ) and <EOL> getattr ( _dec . _decorated_function , '<STR_LIT>' , False ) ) : <EOL> return mark_safe ( func ( * args , ** kwargs ) ) <EOL> return func ( * args , ** kwargs ) <EOL> _dec . _decorated_function = getattr ( func , '<STR_LIT>' , func ) <EOL> for attr in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if hasattr ( func , attr ) : <EOL> import warnings <EOL> warnings . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( attr , attr , getattr ( func , attr ) ) , <EOL> PendingDeprecationWarning ) <EOL> setattr ( _dec , attr , getattr ( func , attr ) ) <EOL> return wraps ( func ) ( _dec ) <EOL> @ register . filter ( is_safe = True ) <EOL> @ stringfilter <EOL> def addslashes ( value ) : <EOL> """<STR_LIT>""" <EOL> return value . replace ( '<STR_LIT:\\>' , '<STR_LIT>' ) . replace ( '<STR_LIT:">' , '<STR_LIT>' ) . replace ( "<STR_LIT:'>" , "<STR_LIT>" ) <EOL> @ register . filter ( is_safe = True ) <EOL> @ stringfilter <EOL> def capfirst ( value ) : <EOL> """<STR_LIT>""" <EOL> return value and value [ <NUM_LIT:0> ] . upper ( ) + value [ <NUM_LIT:1> : ] <EOL> @ register . filter ( "<STR_LIT>" ) <EOL> @ stringfilter <EOL> def escapejs_filter ( value ) : <EOL> """<STR_LIT>""" <EOL> return escapejs ( value ) <EOL> @ register . filter ( "<STR_LIT>" , is_safe = True ) <EOL> @ stringfilter <EOL> def fix_ampersands_filter ( value ) : <EOL> """<STR_LIT>""" <EOL> return fix_ampersands ( value ) <EOL> pos_inf = <NUM_LIT> * <NUM_LIT> <EOL> neg_inf = - <NUM_LIT> * <NUM_LIT> <EOL> nan = ( <NUM_LIT> * <NUM_LIT> ) // ( <NUM_LIT> * <NUM_LIT> ) <EOL> special_floats = [ str ( pos_inf ) , str ( neg_inf ) , str ( nan ) ] <EOL> @ register . filter ( is_safe = True ) <EOL> def floatformat ( text , arg = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> input_val = force_unicode ( text ) <EOL> d = Decimal ( input_val ) <EOL> except UnicodeEncodeError : <EOL> return u'<STR_LIT>' <EOL> except InvalidOperation : <EOL> if input_val in special_floats : <EOL> return input_val <EOL> try : <EOL> d = Decimal ( force_unicode ( float ( text ) ) ) <EOL> except ( ValueError , InvalidOperation , TypeError , UnicodeEncodeError ) : <EOL> return u'<STR_LIT>' <EOL> try : <EOL> p = int ( arg ) <EOL> except ValueError : <EOL> return input_val <EOL> try : <EOL> m = int ( d ) - d <EOL> except ( ValueError , OverflowError , InvalidOperation ) : <EOL> return input_val <EOL> if not m and p < <NUM_LIT:0> : <EOL> return mark_safe ( formats . number_format ( u'<STR_LIT>' % ( int ( d ) ) , <NUM_LIT:0> ) ) <EOL> if p == <NUM_LIT:0> : <EOL> exp = Decimal ( <NUM_LIT:1> ) <EOL> else : <EOL> exp = Decimal ( u'<STR_LIT:1.0>' ) / ( Decimal ( <NUM_LIT:10> ) ** abs ( p ) ) <EOL> try : <EOL> tupl = d . as_tuple ( ) <EOL> units = len ( tupl [ <NUM_LIT:1> ] ) - tupl [ <NUM_LIT:2> ] <EOL> prec = abs ( p ) + units + <NUM_LIT:1> <EOL> sign , digits , exponent = d . quantize ( exp , ROUND_HALF_UP , <EOL> Context ( prec = prec ) ) . as_tuple ( ) <EOL> digits = [ unicode ( digit ) for digit in reversed ( digits ) ] <EOL> while len ( digits ) <= abs ( exponent ) : <EOL> digits . append ( u'<STR_LIT:0>' ) <EOL> digits . insert ( - exponent , u'<STR_LIT:.>' ) <EOL> if sign : <EOL> digits . append ( u'<STR_LIT:->' ) <EOL> number = u'<STR_LIT>' . join ( reversed ( digits ) ) <EOL> return mark_safe ( formats . number_format ( number , abs ( p ) ) ) <EOL> except InvalidOperation : <EOL> return input_val <EOL> @ register . filter ( is_safe = True ) <EOL> @ stringfilter <EOL> def iriencode ( value ) : <EOL> """<STR_LIT>""" <EOL> return force_unicode ( iri_to_uri ( value ) ) <EOL> @ register . filter ( is_safe = True , needs_autoescape = True ) <EOL> @ stringfilter <EOL> def linenumbers ( value , autoescape = None ) : <EOL> """<STR_LIT>""" <EOL> lines = value . split ( u'<STR_LIT:\n>' ) <EOL> width = unicode ( len ( unicode ( len ( lines ) ) ) ) <EOL> if not autoescape or isinstance ( value , SafeData ) : <EOL> for i , line in enumerate ( lines ) : <EOL> lines [ i ] = ( u"<STR_LIT>" + width + u"<STR_LIT>" ) % ( i + <NUM_LIT:1> , line ) <EOL> else : <EOL> for i , line in enumerate ( lines ) : <EOL> lines [ i ] = ( u"<STR_LIT>" + width + u"<STR_LIT>" ) % ( i + <NUM_LIT:1> , escape ( line ) ) <EOL> return mark_safe ( u'<STR_LIT:\n>' . join ( lines ) ) <EOL> @ register . filter ( is_safe = True ) <EOL> @ stringfilter <EOL> def lower ( value ) : <EOL> """<STR_LIT>""" <EOL> return value . lower ( ) <EOL> @ register . filter ( is_safe = False ) <EOL> @ stringfilter <EOL> def make_list ( value ) : <EOL> """<STR_LIT>""" <EOL> return list ( value ) <EOL> @ register . filter ( is_safe = True ) <EOL> @ stringfilter <EOL> def slugify ( value ) : <EOL> """<STR_LIT>""" <EOL> value = unicodedata . normalize ( '<STR_LIT>' , value ) . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) <EOL> value = unicode ( re . sub ( '<STR_LIT>' , '<STR_LIT>' , value ) . strip ( ) . lower ( ) ) <EOL> return mark_safe ( re . sub ( '<STR_LIT>' , '<STR_LIT:->' , value ) ) <EOL> @ register . filter ( is_safe = True ) <EOL> def stringformat ( value , arg ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return ( u"<STR_LIT:%>" + unicode ( arg ) ) % value <EOL> except ( ValueError , TypeError ) : <EOL> return u"<STR_LIT>" <EOL> @ register . filter ( is_safe = True ) <EOL> @ stringfilter <EOL> def title ( value ) : <EOL> """<STR_LIT>""" <EOL> t = re . sub ( "<STR_LIT>" , lambda m : m . group ( <NUM_LIT:0> ) . lower ( ) , value . title ( ) ) <EOL> return re . sub ( "<STR_LIT>" , lambda m : m . group ( <NUM_LIT:0> ) . lower ( ) , t ) <EOL> @ register . filter ( is_safe = True ) <EOL> @ stringfilter <EOL> def truncatechars ( value , arg ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> length = int ( arg ) <EOL> except ValueError : <EOL> return value <EOL> return Truncator ( value ) . chars ( length ) <EOL> @ register . filter ( is_safe = True ) <EOL> @ stringfilter <EOL> def truncatewords ( value , arg ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> length = int ( arg ) <EOL> except ValueError : <EOL> return value <EOL> return Truncator ( value ) . words ( length , truncate = '<STR_LIT>' ) <EOL> @ register . filter ( is_safe = True ) <EOL> @ stringfilter <EOL> def truncatewords_html ( value , arg ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> length = int ( arg ) <EOL> except ValueError : <EOL> return value <EOL> return Truncator ( value ) . words ( length , html = True , truncate = '<STR_LIT>' ) <EOL> @ register . filter ( is_safe = False ) <EOL> @ stringfilter <EOL> def upper ( value ) : <EOL> """<STR_LIT>""" <EOL> return value . upper ( ) <EOL> @ register . filter ( is_safe = False ) <EOL> @ stringfilter <EOL> def urlencode ( value , safe = None ) : <EOL> """<STR_LIT>""" <EOL> kwargs = { } <EOL> if safe is not None : <EOL> kwargs [ '<STR_LIT>' ] = safe <EOL> return urlquote ( value , ** kwargs ) <EOL> @ register . filter ( is_safe = True , needs_autoescape = True ) <EOL> @ stringfilter <EOL> def urlize ( value , autoescape = None ) : <EOL> """<STR_LIT>""" <EOL> return mark_safe ( urlize_impl ( value , nofollow = True , autoescape = autoescape ) ) <EOL> @ register . filter ( is_safe = True , needs_autoescape = True ) <EOL> @ stringfilter <EOL> def urlizetrunc ( value , limit , autoescape = None ) : <EOL> """<STR_LIT>""" <EOL> return mark_safe ( urlize_impl ( value , trim_url_limit = int ( limit ) , nofollow = True , <EOL> autoescape = autoescape ) ) <EOL> @ register . filter ( is_safe = False ) <EOL> @ stringfilter <EOL> def wordcount ( value ) : <EOL> """<STR_LIT>""" <EOL> return len ( value . split ( ) ) <EOL> @ register . filter ( is_safe = True ) <EOL> @ stringfilter <EOL> def wordwrap ( value , arg ) : <EOL> """<STR_LIT>""" <EOL> return wrap ( value , int ( arg ) ) <EOL> @ register . filter ( is_safe = True ) <EOL> @ stringfilter <EOL> def ljust ( value , arg ) : <EOL> """<STR_LIT>""" <EOL> return value . ljust ( int ( arg ) ) <EOL> @ register . filter ( is_safe = True ) <EOL> @ stringfilter <EOL> def rjust ( value , arg ) : <EOL> """<STR_LIT>""" <EOL> return value . rjust ( int ( arg ) ) <EOL> @ register . filter ( is_safe = True ) <EOL> @ stringfilter <EOL> def center ( value , arg ) : <EOL> """<STR_LIT>""" <EOL> return value . center ( int ( arg ) ) <EOL> @ register . filter <EOL> @ stringfilter <EOL> def cut ( value , arg ) : <EOL> """<STR_LIT>""" <EOL> safe = isinstance ( value , SafeData ) <EOL> value = value . replace ( arg , u'<STR_LIT>' ) <EOL> if safe and arg != '<STR_LIT:;>' : <EOL> return mark_safe ( value ) <EOL> return value <EOL> @ register . filter ( "<STR_LIT>" , is_safe = True ) <EOL> @ stringfilter <EOL> def escape_filter ( value ) : <EOL> """<STR_LIT>""" <EOL> return mark_for_escaping ( value ) <EOL> @ register . filter ( is_safe = True ) <EOL> @ stringfilter <EOL> def force_escape ( value ) : <EOL> """<STR_LIT>""" <EOL> return mark_safe ( escape ( value ) ) <EOL> @ register . filter ( "<STR_LIT>" , is_safe = True , needs_autoescape = True ) <EOL> @ stringfilter <EOL> def linebreaks_filter ( value , autoescape = None ) : <EOL> """<STR_LIT>""" <EOL> autoescape = autoescape and not isinstance ( value , SafeData ) <EOL> return mark_safe ( linebreaks ( value , autoescape ) ) <EOL> @ register . filter ( is_safe = True , needs_autoescape = True ) <EOL> @ stringfilter <EOL> def linebreaksbr ( value , autoescape = None ) : <EOL> """<STR_LIT>""" <EOL> autoescape = autoescape and not isinstance ( value , SafeData ) <EOL> value = normalize_newlines ( value ) <EOL> if autoescape : <EOL> value = escape ( value ) <EOL> return mark_safe ( value . replace ( '<STR_LIT:\n>' , '<STR_LIT>' ) ) <EOL> @ register . filter ( is_safe = True ) <EOL> @ stringfilter <EOL> def safe ( value ) : <EOL> """<STR_LIT>""" <EOL> return mark_safe ( value ) <EOL> @ register . filter ( is_safe = True ) <EOL> def safeseq ( value ) : <EOL> """<STR_LIT>""" <EOL> return [ mark_safe ( force_unicode ( obj ) ) for obj in value ] <EOL> @ register . filter ( is_safe = True ) <EOL> @ stringfilter <EOL> def removetags ( value , tags ) : <EOL> """<STR_LIT>""" <EOL> tags = [ re . escape ( tag ) for tag in tags . split ( ) ] <EOL> tags_re = u'<STR_LIT>' % u'<STR_LIT:|>' . join ( tags ) <EOL> starttag_re = re . compile ( ur '<STR_LIT>' % tags_re , re . U ) <EOL> endtag_re = re . compile ( u'<STR_LIT>' % tags_re ) <EOL> value = starttag_re . sub ( u'<STR_LIT>' , value ) <EOL> value = endtag_re . sub ( u'<STR_LIT>' , value ) <EOL> return value <EOL> @ register . filter ( is_safe = True ) <EOL> @ stringfilter <EOL> def striptags ( value ) : <EOL> """<STR_LIT>""" <EOL> return strip_tags ( value ) <EOL> @ register . filter ( is_safe = False ) <EOL> def dictsort ( value , arg ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return sorted ( value , key = Variable ( arg ) . resolve ) <EOL> except ( TypeError , VariableDoesNotExist ) : <EOL> return u'<STR_LIT>' <EOL> @ register . filter ( is_safe = False ) <EOL> def dictsortreversed ( value , arg ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return sorted ( value , key = Variable ( arg ) . resolve , reverse = True ) <EOL> except ( TypeError , VariableDoesNotExist ) : <EOL> return u'<STR_LIT>' <EOL> @ register . filter ( is_safe = False ) <EOL> def first ( value ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return value [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> return u'<STR_LIT>' <EOL> @ register . filter ( is_safe = True , needs_autoescape = True ) <EOL> def join ( value , arg , autoescape = None ) : <EOL> """<STR_LIT>""" <EOL> value = map ( force_unicode , value ) <EOL> if autoescape : <EOL> value = [ conditional_escape ( v ) for v in value ] <EOL> try : <EOL> data = conditional_escape ( arg ) . join ( value ) <EOL> except AttributeError : <EOL> return value <EOL> return mark_safe ( data ) <EOL> @ register . filter ( is_safe = True ) <EOL> def last ( value ) : <EOL> "<STR_LIT>" <EOL> try : <EOL> return value [ - <NUM_LIT:1> ] <EOL> except IndexError : <EOL> return u'<STR_LIT>' <EOL> @ register . filter ( is_safe = True ) <EOL> def length ( value ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return len ( value ) <EOL> except ( ValueError , TypeError ) : <EOL> return '<STR_LIT>' <EOL> @ register . filter ( is_safe = False ) <EOL> def length_is ( value , arg ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return len ( value ) == int ( arg ) <EOL> except ( ValueError , TypeError ) : <EOL> return '<STR_LIT>' <EOL> @ register . filter ( is_safe = True ) <EOL> def random ( value ) : <EOL> """<STR_LIT>""" <EOL> return random_module . choice ( value ) <EOL> @ register . filter ( "<STR_LIT>" , is_safe = True ) <EOL> def slice_filter ( value , arg ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> bits = [ ] <EOL> for x in arg . split ( u'<STR_LIT::>' ) : <EOL> if len ( x ) == <NUM_LIT:0> : <EOL> bits . append ( None ) <EOL> else : <EOL> bits . append ( int ( x ) ) <EOL> return value [ slice ( * bits ) ] <EOL> except ( ValueError , TypeError ) : <EOL> return value <EOL> @ register . filter ( is_safe = True , needs_autoescape = True ) <EOL> def unordered_list ( value , autoescape = None ) : <EOL> """<STR_LIT>""" <EOL> if autoescape : <EOL> escaper = conditional_escape <EOL> else : <EOL> escaper = lambda x : x <EOL> def convert_old_style_list ( list_ ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( list_ , ( tuple , list ) ) or len ( list_ ) != <NUM_LIT:2> : <EOL> return list_ , False <EOL> first_item , second_item = list_ <EOL> if second_item == [ ] : <EOL> return [ first_item ] , True <EOL> try : <EOL> iter ( second_item ) <EOL> except TypeError : <EOL> return list_ , False <EOL> old_style_list = True <EOL> new_second_item = [ ] <EOL> for sublist in second_item : <EOL> item , old_style_list = convert_old_style_list ( sublist ) <EOL> if not old_style_list : <EOL> break <EOL> new_second_item . extend ( item ) <EOL> if old_style_list : <EOL> second_item = new_second_item <EOL> return [ first_item , second_item ] , old_style_list <EOL> def _helper ( list_ , tabs = <NUM_LIT:1> ) : <EOL> indent = u'<STR_LIT:\t>' * tabs <EOL> output = [ ] <EOL> list_length = len ( list_ ) <EOL> i = <NUM_LIT:0> <EOL> while i < list_length : <EOL> title = list_ [ i ] <EOL> sublist = '<STR_LIT>' <EOL> sublist_item = None <EOL> if isinstance ( title , ( list , tuple ) ) : <EOL> sublist_item = title <EOL> title = '<STR_LIT>' <EOL> elif i < list_length - <NUM_LIT:1> : <EOL> next_item = list_ [ i + <NUM_LIT:1> ] <EOL> if next_item and isinstance ( next_item , ( list , tuple ) ) : <EOL> sublist_item = next_item <EOL> i += <NUM_LIT:1> <EOL> if sublist_item : <EOL> sublist = _helper ( sublist_item , tabs + <NUM_LIT:1> ) <EOL> sublist = '<STR_LIT>' % ( indent , sublist , <EOL> indent , indent ) <EOL> output . append ( '<STR_LIT>' % ( indent , <EOL> escaper ( force_unicode ( title ) ) , sublist ) ) <EOL> i += <NUM_LIT:1> <EOL> return '<STR_LIT:\n>' . join ( output ) <EOL> value , converted = convert_old_style_list ( value ) <EOL> return mark_safe ( _helper ( value ) ) <EOL> @ register . filter ( is_safe = False ) <EOL> def add ( value , arg ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return int ( value ) + int ( arg ) <EOL> except ( ValueError , TypeError ) : <EOL> try : <EOL> return value + arg <EOL> except Exception : <EOL> return '<STR_LIT>' <EOL> @ register . filter ( is_safe = False ) <EOL> def get_digit ( value , arg ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> arg = int ( arg ) <EOL> value = int ( value ) <EOL> except ValueError : <EOL> return value <EOL> if arg < <NUM_LIT:1> : <EOL> return value <EOL> try : <EOL> return int ( str ( value ) [ - arg ] ) <EOL> except IndexError : <EOL> return <NUM_LIT:0> <EOL> @ register . filter ( expects_localtime = True , is_safe = False ) <EOL> def date ( value , arg = None ) : <EOL> """<STR_LIT>""" <EOL> if not value : <EOL> return u'<STR_LIT>' <EOL> if arg is None : <EOL> arg = settings . DATE_FORMAT <EOL> try : <EOL> return formats . date_format ( value , arg ) <EOL> except AttributeError : <EOL> try : <EOL> return format ( value , arg ) <EOL> except AttributeError : <EOL> return '<STR_LIT>' <EOL> @ register . filter ( expects_localtime = True , is_safe = False ) <EOL> def time ( value , arg = None ) : <EOL> """<STR_LIT>""" <EOL> if value in ( None , u'<STR_LIT>' ) : <EOL> return u'<STR_LIT>' <EOL> if arg is None : <EOL> arg = settings . TIME_FORMAT <EOL> try : <EOL> return formats . time_format ( value , arg ) <EOL> except AttributeError : <EOL> try : <EOL> return time_format ( value , arg ) <EOL> except AttributeError : <EOL> return '<STR_LIT>' <EOL> @ register . filter ( "<STR_LIT>" , is_safe = False ) <EOL> def timesince_filter ( value , arg = None ) : <EOL> """<STR_LIT>""" <EOL> if not value : <EOL> return u'<STR_LIT>' <EOL> try : <EOL> if arg : <EOL> return timesince ( value , arg ) <EOL> return timesince ( value ) <EOL> except ( ValueError , TypeError ) : <EOL> return u'<STR_LIT>' <EOL> @ register . filter ( "<STR_LIT>" , is_safe = False ) <EOL> def timeuntil_filter ( value , arg = None ) : <EOL> """<STR_LIT>""" <EOL> if not value : <EOL> return u'<STR_LIT>' <EOL> try : <EOL> return timeuntil ( value , arg ) <EOL> except ( ValueError , TypeError ) : <EOL> return u'<STR_LIT>' <EOL> @ register . filter ( is_safe = False ) <EOL> def default ( value , arg ) : <EOL> """<STR_LIT>""" <EOL> return value or arg <EOL> @ register . filter ( is_safe = False ) <EOL> def default_if_none ( value , arg ) : <EOL> """<STR_LIT>""" <EOL> if value is None : <EOL> return arg <EOL> return value <EOL> @ register . filter ( is_safe = False ) <EOL> def divisibleby ( value , arg ) : <EOL> """<STR_LIT>""" <EOL> return int ( value ) % int ( arg ) == <NUM_LIT:0> <EOL> @ register . filter ( is_safe = False ) <EOL> def yesno ( value , arg = None ) : <EOL> """<STR_LIT>""" <EOL> if arg is None : <EOL> arg = ugettext ( '<STR_LIT>' ) <EOL> bits = arg . split ( u'<STR_LIT:U+002C>' ) <EOL> if len ( bits ) < <NUM_LIT:2> : <EOL> return value <EOL> try : <EOL> yes , no , maybe = bits <EOL> except ValueError : <EOL> yes , no , maybe = bits [ <NUM_LIT:0> ] , bits [ <NUM_LIT:1> ] , bits [ <NUM_LIT:1> ] <EOL> if value is None : <EOL> return maybe <EOL> if value : <EOL> return yes <EOL> return no <EOL> @ register . filter ( is_safe = True ) <EOL> def filesizeformat ( bytes ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> bytes = float ( bytes ) <EOL> except ( TypeError , ValueError , UnicodeDecodeError ) : <EOL> return ungettext ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:0> ) % { '<STR_LIT:size>' : <NUM_LIT:0> } <EOL> filesize_number_format = lambda value : formats . number_format ( round ( value , <NUM_LIT:1> ) , <NUM_LIT:1> ) <EOL> if bytes < <NUM_LIT> : <EOL> return ungettext ( "<STR_LIT>" , "<STR_LIT>" , bytes ) % { '<STR_LIT:size>' : bytes } <EOL> if bytes < <NUM_LIT> * <NUM_LIT> : <EOL> return ugettext ( "<STR_LIT>" ) % filesize_number_format ( bytes / <NUM_LIT> ) <EOL> if bytes < <NUM_LIT> * <NUM_LIT> * <NUM_LIT> : <EOL> return ugettext ( "<STR_LIT>" ) % filesize_number_format ( bytes / ( <NUM_LIT> * <NUM_LIT> ) ) <EOL> if bytes < <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> : <EOL> return ugettext ( "<STR_LIT>" ) % filesize_number_format ( bytes / ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) ) <EOL> if bytes < <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> : <EOL> return ugettext ( "<STR_LIT>" ) % filesize_number_format ( bytes / ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) ) <EOL> return ugettext ( "<STR_LIT>" ) % filesize_number_format ( bytes / ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) ) <EOL> @ register . filter ( is_safe = False ) <EOL> def pluralize ( value , arg = u'<STR_LIT:s>' ) : <EOL> """<STR_LIT>""" <EOL> if not u'<STR_LIT:U+002C>' in arg : <EOL> arg = u'<STR_LIT:U+002C>' + arg <EOL> bits = arg . split ( u'<STR_LIT:U+002C>' ) <EOL> if len ( bits ) > <NUM_LIT:2> : <EOL> return u'<STR_LIT>' <EOL> singular_suffix , plural_suffix = bits [ : <NUM_LIT:2> ] <EOL> try : <EOL> if int ( value ) != <NUM_LIT:1> : <EOL> return plural_suffix <EOL> except ValueError : <EOL> pass <EOL> except TypeError : <EOL> try : <EOL> if len ( value ) != <NUM_LIT:1> : <EOL> return plural_suffix <EOL> except TypeError : <EOL> pass <EOL> return singular_suffix <EOL> @ register . filter ( "<STR_LIT>" , is_safe = True ) <EOL> def phone2numeric_filter ( value ) : <EOL> """<STR_LIT>""" <EOL> return phone2numeric ( value ) <EOL> @ register . filter ( is_safe = True ) <EOL> def pprint ( value ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return pformat ( value ) <EOL> except Exception , e : <EOL> return u"<STR_LIT>" % force_unicode ( e , errors = "<STR_LIT:replace>" ) </s>
