<s> import re <EOL> import urllib <EOL> from email . Utils import formatdate <EOL> from django . utils . encoding import smart_str , force_unicode <EOL> from django . utils . functional import allow_lazy <EOL> ETAG_MATCH = re . compile ( r'<STR_LIT>' ) <EOL> def urlquote ( url , safe = '<STR_LIT:/>' ) : <EOL> """<STR_LIT>""" <EOL> return force_unicode ( urllib . quote ( smart_str ( url ) , safe ) ) <EOL> urlquote = allow_lazy ( urlquote , unicode ) <EOL> def urlquote_plus ( url , safe = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> return force_unicode ( urllib . quote_plus ( smart_str ( url ) , safe ) ) <EOL> urlquote_plus = allow_lazy ( urlquote_plus , unicode ) <EOL> def urlencode ( query , doseq = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( query , '<STR_LIT>' ) : <EOL> query = query . items ( ) <EOL> return urllib . urlencode ( <EOL> [ ( smart_str ( k ) , <EOL> isinstance ( v , ( list , tuple ) ) and [ smart_str ( i ) for i in v ] or smart_str ( v ) ) <EOL> for k , v in query ] , <EOL> doseq ) <EOL> def cookie_date ( epoch_seconds = None ) : <EOL> """<STR_LIT>""" <EOL> rfcdate = formatdate ( epoch_seconds ) <EOL> return '<STR_LIT>' % ( rfcdate [ : <NUM_LIT:7> ] , rfcdate [ <NUM_LIT:8> : <NUM_LIT:11> ] , rfcdate [ <NUM_LIT:12> : <NUM_LIT> ] ) <EOL> def http_date ( epoch_seconds = None ) : <EOL> """<STR_LIT>""" <EOL> rfcdate = formatdate ( epoch_seconds ) <EOL> return '<STR_LIT>' % rfcdate [ : <NUM_LIT> ] <EOL> def base36_to_int ( s ) : <EOL> """<STR_LIT>""" <EOL> return int ( s , <NUM_LIT> ) <EOL> def int_to_base36 ( i ) : <EOL> """<STR_LIT>""" <EOL> digits = "<STR_LIT>" <EOL> factor = <NUM_LIT:0> <EOL> while True : <EOL> factor += <NUM_LIT:1> <EOL> if i < <NUM_LIT> ** factor : <EOL> factor -= <NUM_LIT:1> <EOL> break <EOL> base36 = [ ] <EOL> while factor >= <NUM_LIT:0> : <EOL> j = <NUM_LIT> ** factor <EOL> base36 . append ( digits [ i / j ] ) <EOL> i = i % j <EOL> factor -= <NUM_LIT:1> <EOL> return '<STR_LIT>' . join ( base36 ) <EOL> def parse_etags ( etag_str ) : <EOL> """<STR_LIT>""" <EOL> etags = ETAG_MATCH . findall ( etag_str ) <EOL> if not etags : <EOL> return [ etag_str ] <EOL> etags = [ e . decode ( '<STR_LIT>' ) for e in etags ] <EOL> return etags <EOL> def quote_etag ( etag ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % etag . replace ( '<STR_LIT:\\>' , '<STR_LIT>' ) . replace ( '<STR_LIT:">' , '<STR_LIT>' ) </s>
