<s> """<STR_LIT>""" <EOL> import re <EOL> import codecs <EOL> import mimetypes <EOL> from werkzeug . _internal import _proxy_repr , _missing , _empty_stream <EOL> _locale_delim_re = re . compile ( r'<STR_LIT>' ) <EOL> def is_immutable ( self ) : <EOL> raise TypeError ( '<STR_LIT>' % self . __class__ . __name__ ) <EOL> def iter_multi_items ( mapping ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( mapping , MultiDict ) : <EOL> for item in mapping . iteritems ( multi = True ) : <EOL> yield item <EOL> elif isinstance ( mapping , dict ) : <EOL> for key , value in mapping . iteritems ( ) : <EOL> if isinstance ( value , ( tuple , list ) ) : <EOL> for value in value : <EOL> yield key , value <EOL> else : <EOL> yield key , value <EOL> else : <EOL> for item in mapping : <EOL> yield item <EOL> class ImmutableListMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def __reduce_ex__ ( self , protocol ) : <EOL> return type ( self ) , ( list ( self ) , ) <EOL> def __delitem__ ( self , key ) : <EOL> is_immutable ( self ) <EOL> def __delslice__ ( self , i , j ) : <EOL> is_immutable ( self ) <EOL> def __iadd__ ( self , other ) : <EOL> is_immutable ( self ) <EOL> __imul__ = __iadd__ <EOL> def __setitem__ ( self , key , value ) : <EOL> is_immutable ( self ) <EOL> def __setslice__ ( self , i , j , value ) : <EOL> is_immutable ( self ) <EOL> def append ( self , item ) : <EOL> is_immutable ( self ) <EOL> remove = append <EOL> def extend ( self , iterable ) : <EOL> is_immutable ( self ) <EOL> def insert ( self , pos , value ) : <EOL> is_immutable ( self ) <EOL> def pop ( self , index = - <NUM_LIT:1> ) : <EOL> is_immutable ( self ) <EOL> def reverse ( self ) : <EOL> is_immutable ( self ) <EOL> def sort ( self , cmp = None , key = None , reverse = None ) : <EOL> is_immutable ( self ) <EOL> class ImmutableList ( ImmutableListMixin , list ) : <EOL> """<STR_LIT>""" <EOL> __repr__ = _proxy_repr ( list ) <EOL> class ImmutableDictMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def __reduce_ex__ ( self , protocol ) : <EOL> return type ( self ) , ( dict ( self ) , ) <EOL> def setdefault ( self , key , default = None ) : <EOL> is_immutable ( self ) <EOL> def update ( self , * args , ** kwargs ) : <EOL> is_immutable ( self ) <EOL> def pop ( self , key , default = None ) : <EOL> is_immutable ( self ) <EOL> def popitem ( self ) : <EOL> is_immutable ( self ) <EOL> def __setitem__ ( self , key , value ) : <EOL> is_immutable ( self ) <EOL> def __delitem__ ( self , key ) : <EOL> is_immutable ( self ) <EOL> def clear ( self ) : <EOL> is_immutable ( self ) <EOL> class ImmutableMultiDictMixin ( ImmutableDictMixin ) : <EOL> """<STR_LIT>""" <EOL> def __reduce_ex__ ( self , protocol ) : <EOL> return type ( self ) , ( self . items ( multi = True ) , ) <EOL> def add ( self , key , value ) : <EOL> is_immutable ( self ) <EOL> def popitemlist ( self ) : <EOL> is_immutable ( self ) <EOL> def poplist ( self , key ) : <EOL> is_immutable ( self ) <EOL> def setlist ( self , key , new_list ) : <EOL> is_immutable ( self ) <EOL> def setlistdefault ( self , key , default_list = None ) : <EOL> is_immutable ( self ) <EOL> class UpdateDictMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> on_update = None <EOL> def calls_update ( name ) : <EOL> def oncall ( self , * args , ** kw ) : <EOL> rv = getattr ( super ( UpdateDictMixin , self ) , name ) ( * args , ** kw ) <EOL> if self . on_update is not None : <EOL> self . on_update ( self ) <EOL> return rv <EOL> oncall . __name__ = name <EOL> return oncall <EOL> __setitem__ = calls_update ( '<STR_LIT>' ) <EOL> __delitem__ = calls_update ( '<STR_LIT>' ) <EOL> clear = calls_update ( '<STR_LIT>' ) <EOL> pop = calls_update ( '<STR_LIT>' ) <EOL> popitem = calls_update ( '<STR_LIT>' ) <EOL> setdefault = calls_update ( '<STR_LIT>' ) <EOL> update = calls_update ( '<STR_LIT>' ) <EOL> del calls_update <EOL> class TypeConversionDict ( dict ) : <EOL> """<STR_LIT>""" <EOL> def get ( self , key , default = None , type = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> rv = self [ key ] <EOL> if type is not None : <EOL> rv = type ( rv ) <EOL> except ( KeyError , ValueError ) : <EOL> rv = default <EOL> return rv <EOL> class ImmutableTypeConversionDict ( ImmutableDictMixin , TypeConversionDict ) : <EOL> """<STR_LIT>""" <EOL> def copy ( self ) : <EOL> """<STR_LIT>""" <EOL> return TypeConversionDict ( self ) <EOL> def __copy__ ( self ) : <EOL> return self <EOL> class MultiDict ( TypeConversionDict ) : <EOL> """<STR_LIT>""" <EOL> KeyError = None <EOL> def __init__ ( self , mapping = None ) : <EOL> if isinstance ( mapping , MultiDict ) : <EOL> dict . __init__ ( self , ( ( k , l [ : ] ) for k , l in mapping . iterlists ( ) ) ) <EOL> elif isinstance ( mapping , dict ) : <EOL> tmp = { } <EOL> for key , value in mapping . iteritems ( ) : <EOL> if isinstance ( value , ( tuple , list ) ) : <EOL> value = list ( value ) <EOL> else : <EOL> value = [ value ] <EOL> tmp [ key ] = value <EOL> dict . __init__ ( self , tmp ) <EOL> else : <EOL> tmp = { } <EOL> for key , value in mapping or ( ) : <EOL> tmp . setdefault ( key , [ ] ) . append ( value ) <EOL> dict . __init__ ( self , tmp ) <EOL> def __getstate__ ( self ) : <EOL> return dict ( self . lists ( ) ) <EOL> def __setstate__ ( self , value ) : <EOL> dict . clear ( self ) <EOL> dict . update ( self , value ) <EOL> def __iter__ ( self ) : <EOL> return self . iterkeys ( ) <EOL> def __getitem__ ( self , key ) : <EOL> """<STR_LIT>""" <EOL> if key in self : <EOL> return dict . __getitem__ ( self , key ) [ <NUM_LIT:0> ] <EOL> raise self . KeyError ( key ) <EOL> def __setitem__ ( self , key , value ) : <EOL> """<STR_LIT>""" <EOL> dict . __setitem__ ( self , key , [ value ] ) <EOL> def add ( self , key , value ) : <EOL> """<STR_LIT>""" <EOL> dict . setdefault ( self , key , [ ] ) . append ( value ) <EOL> def getlist ( self , key , type = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> rv = dict . __getitem__ ( self , key ) <EOL> except KeyError : <EOL> return [ ] <EOL> if type is None : <EOL> return list ( rv ) <EOL> result = [ ] <EOL> for item in rv : <EOL> try : <EOL> result . append ( type ( item ) ) <EOL> except ValueError : <EOL> pass <EOL> return result <EOL> def setlist ( self , key , new_list ) : <EOL> """<STR_LIT>""" <EOL> dict . __setitem__ ( self , key , list ( new_list ) ) <EOL> def setdefault ( self , key , default = None ) : <EOL> """<STR_LIT>""" <EOL> if key not in self : <EOL> self [ key ] = default <EOL> else : <EOL> default = self [ key ] <EOL> return default <EOL> def setlistdefault ( self , key , default_list = None ) : <EOL> """<STR_LIT>""" <EOL> if key not in self : <EOL> default_list = list ( default_list or ( ) ) <EOL> dict . __setitem__ ( self , key , default_list ) <EOL> else : <EOL> default_list = dict . __getitem__ ( self , key ) <EOL> return default_list <EOL> def items ( self , multi = False ) : <EOL> """<STR_LIT>""" <EOL> return list ( self . iteritems ( multi ) ) <EOL> def lists ( self ) : <EOL> """<STR_LIT>""" <EOL> return list ( self . iterlists ( ) ) <EOL> def values ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ self [ key ] for key in self . iterkeys ( ) ] <EOL> def listvalues ( self ) : <EOL> """<STR_LIT>""" <EOL> return list ( self . iterlistvalues ( ) ) <EOL> def iteritems ( self , multi = False ) : <EOL> """<STR_LIT>""" <EOL> for key , values in dict . iteritems ( self ) : <EOL> if multi : <EOL> for value in values : <EOL> yield key , value <EOL> else : <EOL> yield key , values [ <NUM_LIT:0> ] <EOL> def iterlists ( self ) : <EOL> """<STR_LIT>""" <EOL> for key , values in dict . iteritems ( self ) : <EOL> yield key , list ( values ) <EOL> def itervalues ( self ) : <EOL> """<STR_LIT>""" <EOL> for values in dict . itervalues ( self ) : <EOL> yield values [ <NUM_LIT:0> ] <EOL> def iterlistvalues ( self ) : <EOL> """<STR_LIT>""" <EOL> for values in dict . itervalues ( self ) : <EOL> yield list ( values ) <EOL> def copy ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __class__ ( self ) <EOL> def to_dict ( self , flat = True ) : <EOL> """<STR_LIT>""" <EOL> if flat : <EOL> return dict ( self . iteritems ( ) ) <EOL> return dict ( self . lists ( ) ) <EOL> def update ( self , other_dict ) : <EOL> """<STR_LIT>""" <EOL> for key , value in iter_multi_items ( other_dict ) : <EOL> MultiDict . add ( self , key , value ) <EOL> def pop ( self , key , default = _missing ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return dict . pop ( self , key ) [ <NUM_LIT:0> ] <EOL> except KeyError , e : <EOL> if default is not _missing : <EOL> return default <EOL> raise self . KeyError ( str ( e ) ) <EOL> def popitem ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> item = dict . popitem ( self ) <EOL> return ( item [ <NUM_LIT:0> ] , item [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) <EOL> except KeyError , e : <EOL> raise self . KeyError ( str ( e ) ) <EOL> def poplist ( self , key ) : <EOL> """<STR_LIT>""" <EOL> return dict . pop ( self , key , [ ] ) <EOL> def popitemlist ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return dict . popitem ( self ) <EOL> except KeyError , e : <EOL> raise self . KeyError ( str ( e ) ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . items ( multi = True ) ) <EOL> class _omd_bucket ( object ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = ( '<STR_LIT>' , '<STR_LIT:key>' , '<STR_LIT:value>' , '<STR_LIT>' ) <EOL> def __init__ ( self , omd , key , value ) : <EOL> self . prev = omd . _last_bucket <EOL> self . key = key <EOL> self . value = value <EOL> self . next = None <EOL> if omd . _first_bucket is None : <EOL> omd . _first_bucket = self <EOL> if omd . _last_bucket is not None : <EOL> omd . _last_bucket . next = self <EOL> omd . _last_bucket = self <EOL> def unlink ( self , omd ) : <EOL> if self . prev : <EOL> self . prev . next = self . next <EOL> if self . next : <EOL> self . next . prev = self . prev <EOL> if omd . _first_bucket is self : <EOL> omd . _first_bucket = self . next <EOL> if omd . _last_bucket is self : <EOL> omd . _last_bucket = self . prev <EOL> class OrderedMultiDict ( MultiDict ) : <EOL> """<STR_LIT>""" <EOL> KeyError = None <EOL> def __init__ ( self , mapping = None ) : <EOL> dict . __init__ ( self ) <EOL> self . _first_bucket = self . _last_bucket = None <EOL> if mapping is not None : <EOL> OrderedMultiDict . update ( self , mapping ) <EOL> def __eq__ ( self , other ) : <EOL> if not isinstance ( other , MultiDict ) : <EOL> return NotImplemented <EOL> if isinstance ( other , OrderedMultiDict ) : <EOL> iter1 = self . iteritems ( multi = True ) <EOL> iter2 = other . iteritems ( multi = True ) <EOL> try : <EOL> for k1 , v1 in iter1 : <EOL> k2 , v2 = iter2 . next ( ) <EOL> if k1 != k2 or v1 != v2 : <EOL> return False <EOL> except StopIteration : <EOL> return False <EOL> try : <EOL> iter2 . next ( ) <EOL> except StopIteration : <EOL> return True <EOL> return False <EOL> if len ( self ) != len ( other ) : <EOL> return False <EOL> for key , values in self . iterlists ( ) : <EOL> if other . getlist ( key ) != values : <EOL> return False <EOL> return True <EOL> def __ne__ ( self , other ) : <EOL> return not self . __eq__ ( other ) <EOL> def __reduce_ex__ ( self , protocol ) : <EOL> return type ( self ) , ( self . items ( multi = True ) , ) <EOL> def __getstate__ ( self ) : <EOL> return self . items ( multi = True ) <EOL> def __setstate__ ( self , values ) : <EOL> dict . clear ( self ) <EOL> for key , value in values : <EOL> self . add ( key , value ) <EOL> def __getitem__ ( self , key ) : <EOL> if key in self : <EOL> return dict . __getitem__ ( self , key ) [ <NUM_LIT:0> ] . value <EOL> raise self . KeyError ( key ) <EOL> def __setitem__ ( self , key , value ) : <EOL> self . poplist ( key ) <EOL> self . add ( key , value ) <EOL> def __delitem__ ( self , key ) : <EOL> self . pop ( key ) <EOL> def iterkeys ( self ) : <EOL> return ( key for key , value in self . iteritems ( ) ) <EOL> def itervalues ( self ) : <EOL> return ( value for key , value in self . iteritems ( ) ) <EOL> def iteritems ( self , multi = False ) : <EOL> ptr = self . _first_bucket <EOL> if multi : <EOL> while ptr is not None : <EOL> yield ptr . key , ptr . value <EOL> ptr = ptr . next <EOL> else : <EOL> returned_keys = set ( ) <EOL> while ptr is not None : <EOL> if ptr . key not in returned_keys : <EOL> returned_keys . add ( ptr . key ) <EOL> yield ptr . key , ptr . value <EOL> ptr = ptr . next <EOL> def iterlists ( self ) : <EOL> returned_keys = set ( ) <EOL> ptr = self . _first_bucket <EOL> while ptr is not None : <EOL> if ptr . key not in returned_keys : <EOL> yield ptr . key , self . getlist ( ptr . key ) <EOL> returned_keys . add ( ptr . key ) <EOL> ptr = ptr . next <EOL> def iterlistvalues ( self ) : <EOL> for key , values in self . iterlists ( ) : <EOL> yield values <EOL> def add ( self , key , value ) : <EOL> dict . setdefault ( self , key , [ ] ) . append ( _omd_bucket ( self , key , value ) ) <EOL> def getlist ( self , key , type = None ) : <EOL> try : <EOL> rv = dict . __getitem__ ( self , key ) <EOL> except KeyError : <EOL> return [ ] <EOL> if type is None : <EOL> return [ x . value for x in rv ] <EOL> result = [ ] <EOL> for item in rv : <EOL> try : <EOL> result . append ( type ( item . value ) ) <EOL> except ValueError : <EOL> pass <EOL> return result <EOL> def setlist ( self , key , new_list ) : <EOL> self . poplist ( key ) <EOL> for value in new_list : <EOL> self . add ( key , value ) <EOL> def setlistdefault ( self , key , default_list = None ) : <EOL> raise TypeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def update ( self , mapping ) : <EOL> for key , value in iter_multi_items ( mapping ) : <EOL> OrderedMultiDict . add ( self , key , value ) <EOL> def poplist ( self , key ) : <EOL> buckets = dict . pop ( self , key , ( ) ) <EOL> for bucket in buckets : <EOL> bucket . unlink ( self ) <EOL> return [ x . value for x in buckets ] <EOL> def pop ( self , key , default = _missing ) : <EOL> try : <EOL> buckets = dict . pop ( self , key ) <EOL> except KeyError , e : <EOL> if default is not _missing : <EOL> return default <EOL> raise self . KeyError ( str ( e ) ) <EOL> for bucket in buckets : <EOL> bucket . unlink ( self ) <EOL> return buckets [ <NUM_LIT:0> ] . value <EOL> def popitem ( self ) : <EOL> try : <EOL> key , buckets = dict . popitem ( self ) <EOL> except KeyError , e : <EOL> raise self . KeyError ( str ( e ) ) <EOL> for bucket in buckets : <EOL> bucket . unlink ( self ) <EOL> return key , buckets [ <NUM_LIT:0> ] . value <EOL> def popitemlist ( self ) : <EOL> try : <EOL> key , buckets = dict . popitem ( self ) <EOL> except KeyError , e : <EOL> raise self . KeyError ( str ( e ) ) <EOL> for bucket in buckets : <EOL> bucket . unlink ( self ) <EOL> return key , [ x . value for x in buckets ] <EOL> def _options_header_vkw ( value , kw ) : <EOL> if not kw : <EOL> return value <EOL> return dump_options_header ( value , dict ( ( k . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) , v ) <EOL> for k , v in kw . items ( ) ) ) <EOL> class Headers ( object ) : <EOL> """<STR_LIT>""" <EOL> KeyError = None <EOL> def __init__ ( self , defaults = None , _list = None ) : <EOL> if _list is None : <EOL> _list = [ ] <EOL> self . _list = _list <EOL> if defaults is not None : <EOL> if isinstance ( defaults , ( list , Headers ) ) : <EOL> self . _list . extend ( defaults ) <EOL> else : <EOL> self . extend ( defaults ) <EOL> @ classmethod <EOL> def linked ( cls , headerlist ) : <EOL> """<STR_LIT>""" <EOL> return cls ( _list = headerlist ) <EOL> def __getitem__ ( self , key , _index_operation = True ) : <EOL> if _index_operation : <EOL> if isinstance ( key , ( int , long ) ) : <EOL> return self . _list [ key ] <EOL> elif isinstance ( key , slice ) : <EOL> return self . __class__ ( self . _list [ key ] ) <EOL> ikey = key . lower ( ) <EOL> for k , v in self . _list : <EOL> if k . lower ( ) == ikey : <EOL> return v <EOL> raise self . KeyError ( key ) <EOL> def __eq__ ( self , other ) : <EOL> return other . __class__ is self . __class__ and set ( other . _list ) == set ( self . _list ) <EOL> def __ne__ ( self , other ) : <EOL> return not self . __eq__ ( other ) <EOL> def get ( self , key , default = None , type = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> rv = self . __getitem__ ( key , _index_operation = False ) <EOL> except KeyError : <EOL> return default <EOL> if type is None : <EOL> return rv <EOL> try : <EOL> return type ( rv ) <EOL> except ValueError : <EOL> return default <EOL> def getlist ( self , key , type = None ) : <EOL> """<STR_LIT>""" <EOL> ikey = key . lower ( ) <EOL> result = [ ] <EOL> for k , v in self : <EOL> if k . lower ( ) == ikey : <EOL> if type is not None : <EOL> try : <EOL> v = type ( v ) <EOL> except ValueError : <EOL> continue <EOL> result . append ( v ) <EOL> return result <EOL> def get_all ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return self . getlist ( name ) <EOL> def iteritems ( self , lower = False ) : <EOL> for key , value in self : <EOL> if lower : <EOL> key = key . lower ( ) <EOL> yield key , value <EOL> def iterkeys ( self , lower = False ) : <EOL> for key , _ in self . iteritems ( lower ) : <EOL> yield key <EOL> def itervalues ( self ) : <EOL> for _ , value in self . iteritems ( ) : <EOL> yield value <EOL> def keys ( self , lower = False ) : <EOL> return list ( self . iterkeys ( lower ) ) <EOL> def values ( self ) : <EOL> return list ( self . itervalues ( ) ) <EOL> def items ( self , lower = False ) : <EOL> return list ( self . iteritems ( lower ) ) <EOL> def extend ( self , iterable ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( iterable , dict ) : <EOL> for key , value in iterable . iteritems ( ) : <EOL> if isinstance ( value , ( tuple , list ) ) : <EOL> for v in value : <EOL> self . add ( key , v ) <EOL> else : <EOL> self . add ( key , value ) <EOL> else : <EOL> for key , value in iterable : <EOL> self . add ( key , value ) <EOL> def __delitem__ ( self , key , _index_operation = True ) : <EOL> if _index_operation and isinstance ( key , ( int , long , slice ) ) : <EOL> del self . _list [ key ] <EOL> return <EOL> key = key . lower ( ) <EOL> new = [ ] <EOL> for k , v in self . _list : <EOL> if k . lower ( ) != key : <EOL> new . append ( ( k , v ) ) <EOL> self . _list [ : ] = new <EOL> def remove ( self , key ) : <EOL> """<STR_LIT>""" <EOL> return self . __delitem__ ( key , _index_operation = False ) <EOL> def pop ( self , key = None , default = _missing ) : <EOL> """<STR_LIT>""" <EOL> if key is None : <EOL> return self . _list . pop ( ) <EOL> if isinstance ( key , ( int , long ) ) : <EOL> return self . _list . pop ( key ) <EOL> try : <EOL> rv = self [ key ] <EOL> self . remove ( key ) <EOL> except KeyError : <EOL> if default is not _missing : <EOL> return default <EOL> raise <EOL> return rv <EOL> def popitem ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . pop ( ) <EOL> def __contains__ ( self , key ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . __getitem__ ( key , _index_operation = False ) <EOL> except KeyError : <EOL> return False <EOL> return True <EOL> has_key = __contains__ <EOL> def __iter__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return iter ( self . _list ) <EOL> def __len__ ( self ) : <EOL> return len ( self . _list ) <EOL> def add ( self , _key , _value , ** kw ) : <EOL> """<STR_LIT>""" <EOL> self . _list . append ( ( _key , _options_header_vkw ( _value , kw ) ) ) <EOL> def add_header ( self , _key , _value , ** _kw ) : <EOL> """<STR_LIT>""" <EOL> self . add ( _key , _value , ** _kw ) <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> del self . _list [ : ] <EOL> def set ( self , _key , _value , ** kw ) : <EOL> """<STR_LIT>""" <EOL> lc_key = _key . lower ( ) <EOL> _value = _options_header_vkw ( _value , kw ) <EOL> for idx , ( old_key , old_value ) in enumerate ( self . _list ) : <EOL> if old_key . lower ( ) == lc_key : <EOL> self . _list [ idx ] = ( _key , _value ) <EOL> break <EOL> else : <EOL> return self . add ( _key , _value ) <EOL> self . _list [ idx + <NUM_LIT:1> : ] = [ ( k , v ) for k , v in self . _list [ idx + <NUM_LIT:1> : ] <EOL> if k . lower ( ) != lc_key ] <EOL> def setdefault ( self , key , value ) : <EOL> """<STR_LIT>""" <EOL> if key in self : <EOL> return self [ key ] <EOL> self . set ( key , value ) <EOL> return value <EOL> def __setitem__ ( self , key , value ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( key , ( slice , int , long ) ) : <EOL> self . _list [ key ] = value <EOL> else : <EOL> self . set ( key , value ) <EOL> def to_list ( self , charset = '<STR_LIT:utf-8>' ) : <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> for k , v in self : <EOL> if isinstance ( v , unicode ) : <EOL> v = v . encode ( charset ) <EOL> else : <EOL> v = str ( v ) <EOL> result . append ( ( k , v ) ) <EOL> return result <EOL> def copy ( self ) : <EOL> return self . __class__ ( self . _list ) <EOL> def __copy__ ( self ) : <EOL> return self . copy ( ) <EOL> def __str__ ( self , charset = '<STR_LIT:utf-8>' ) : <EOL> """<STR_LIT>""" <EOL> strs = [ ] <EOL> for key , value in self . to_list ( charset ) : <EOL> strs . append ( '<STR_LIT>' % ( key , value ) ) <EOL> strs . append ( '<STR_LIT:\r\n>' ) <EOL> return '<STR_LIT:\r\n>' . join ( strs ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , <EOL> list ( self ) <EOL> ) <EOL> class ImmutableHeadersMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def __delitem__ ( self , key ) : <EOL> is_immutable ( self ) <EOL> def __setitem__ ( self , key , value ) : <EOL> is_immutable ( self ) <EOL> set = __setitem__ <EOL> def add ( self , item ) : <EOL> is_immutable ( self ) <EOL> remove = add_header = add <EOL> def extend ( self , iterable ) : <EOL> is_immutable ( self ) <EOL> def insert ( self , pos , value ) : <EOL> is_immutable ( self ) <EOL> def pop ( self , index = - <NUM_LIT:1> ) : <EOL> is_immutable ( self ) <EOL> def popitem ( self ) : <EOL> is_immutable ( self ) <EOL> def setdefault ( self , key , default ) : <EOL> is_immutable ( self ) <EOL> class EnvironHeaders ( ImmutableHeadersMixin , Headers ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , environ ) : <EOL> self . environ = environ <EOL> @ classmethod <EOL> def linked ( cls , environ ) : <EOL> raise TypeError ( '<STR_LIT>' <EOL> '<STR_LIT>' % cls . __name__ ) <EOL> def __eq__ ( self , other ) : <EOL> return self . environ is other . environ <EOL> def __getitem__ ( self , key , _index_operation = False ) : <EOL> key = key . upper ( ) . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) <EOL> if key in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return self . environ [ key ] <EOL> return self . environ [ '<STR_LIT>' + key ] <EOL> def __len__ ( self ) : <EOL> return len ( list ( iter ( self ) ) ) <EOL> def __iter__ ( self ) : <EOL> for key , value in self . environ . iteritems ( ) : <EOL> if key . startswith ( '<STR_LIT>' ) and key not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> yield key [ <NUM_LIT:5> : ] . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) . title ( ) , value <EOL> elif key in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> yield key . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) . title ( ) , value <EOL> def copy ( self ) : <EOL> raise TypeError ( '<STR_LIT>' % self . __class__ . __name__ ) <EOL> class CombinedMultiDict ( ImmutableMultiDictMixin , MultiDict ) : <EOL> """<STR_LIT>""" <EOL> def __reduce_ex__ ( self , protocol ) : <EOL> return type ( self ) , ( self . dicts , ) <EOL> def __init__ ( self , dicts = None ) : <EOL> self . dicts = dicts or [ ] <EOL> @ classmethod <EOL> def fromkeys ( cls ) : <EOL> raise TypeError ( '<STR_LIT>' % <EOL> cls . __name__ ) <EOL> def __getitem__ ( self , key ) : <EOL> for d in self . dicts : <EOL> if key in d : <EOL> return d [ key ] <EOL> raise self . KeyError ( key ) <EOL> def get ( self , key , default = None , type = None ) : <EOL> for d in self . dicts : <EOL> if key in d : <EOL> if type is not None : <EOL> try : <EOL> return type ( d [ key ] ) <EOL> except ValueError : <EOL> continue <EOL> return d [ key ] <EOL> return default <EOL> def getlist ( self , key , type = None ) : <EOL> rv = [ ] <EOL> for d in self . dicts : <EOL> rv . extend ( d . getlist ( key , type ) ) <EOL> return rv <EOL> def keys ( self ) : <EOL> rv = set ( ) <EOL> for d in self . dicts : <EOL> rv . update ( d . keys ( ) ) <EOL> return list ( rv ) <EOL> def iteritems ( self , multi = False ) : <EOL> found = set ( ) <EOL> for d in self . dicts : <EOL> for key , value in d . iteritems ( multi ) : <EOL> if multi : <EOL> yield key , value <EOL> elif key not in found : <EOL> found . add ( key ) <EOL> yield key , value <EOL> def itervalues ( self ) : <EOL> for key , value in self . iteritems ( ) : <EOL> yield value <EOL> def values ( self ) : <EOL> return list ( self . itervalues ( ) ) <EOL> def items ( self , multi = False ) : <EOL> return list ( self . iteritems ( multi ) ) <EOL> def iterlists ( self ) : <EOL> rv = { } <EOL> for d in self . dicts : <EOL> for key , values in d . iterlists ( ) : <EOL> rv . setdefault ( key , [ ] ) . extend ( values ) <EOL> return rv . iteritems ( ) <EOL> def lists ( self ) : <EOL> return list ( self . iterlists ( ) ) <EOL> def iterlistvalues ( self ) : <EOL> return ( x [ <NUM_LIT:0> ] for x in self . lists ( ) ) <EOL> def listvalues ( self ) : <EOL> return list ( self . iterlistvalues ( ) ) <EOL> def iterkeys ( self ) : <EOL> return iter ( self . keys ( ) ) <EOL> __iter__ = iterkeys <EOL> def copy ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __class__ ( self . dicts [ : ] ) <EOL> def to_dict ( self , flat = True ) : <EOL> """<STR_LIT>""" <EOL> rv = { } <EOL> for d in reversed ( self . dicts ) : <EOL> rv . update ( d . to_dict ( flat ) ) <EOL> return rv <EOL> def __len__ ( self ) : <EOL> return len ( self . keys ( ) ) <EOL> def __contains__ ( self , key ) : <EOL> for d in self . dicts : <EOL> if key in d : <EOL> return True <EOL> return False <EOL> has_key = __contains__ <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . dicts ) <EOL> class FileMultiDict ( MultiDict ) : <EOL> """<STR_LIT>""" <EOL> def add_file ( self , name , file , filename = None , content_type = None ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( file , FileStorage ) : <EOL> self [ name ] = file <EOL> return <EOL> if isinstance ( file , basestring ) : <EOL> if filename is None : <EOL> filename = file <EOL> file = open ( file , '<STR_LIT:rb>' ) <EOL> if filename and content_type is None : <EOL> content_type = mimetypes . guess_type ( filename ) [ <NUM_LIT:0> ] or '<STR_LIT>' <EOL> self [ name ] = FileStorage ( file , filename , name , content_type ) <EOL> class ImmutableDict ( ImmutableDictMixin , dict ) : <EOL> """<STR_LIT>""" <EOL> __repr__ = _proxy_repr ( dict ) <EOL> def copy ( self ) : <EOL> """<STR_LIT>""" <EOL> return dict ( self ) <EOL> def __copy__ ( self ) : <EOL> return self <EOL> class ImmutableMultiDict ( ImmutableMultiDictMixin , MultiDict ) : <EOL> """<STR_LIT>""" <EOL> def copy ( self ) : <EOL> """<STR_LIT>""" <EOL> return MultiDict ( self ) <EOL> def __copy__ ( self ) : <EOL> return self <EOL> class ImmutableOrderedMultiDict ( ImmutableMultiDictMixin , OrderedMultiDict ) : <EOL> """<STR_LIT>""" <EOL> def copy ( self ) : <EOL> """<STR_LIT>""" <EOL> return OrderedMultiDict ( self ) <EOL> def __copy__ ( self ) : <EOL> return self <EOL> class Accept ( ImmutableList ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , values = ( ) ) : <EOL> if values is None : <EOL> list . __init__ ( self ) <EOL> self . provided = False <EOL> elif isinstance ( values , Accept ) : <EOL> self . provided = values . provided <EOL> list . __init__ ( self , values ) <EOL> else : <EOL> self . provided = True <EOL> values = [ ( a , b ) for b , a in values ] <EOL> values . sort ( ) <EOL> values . reverse ( ) <EOL> list . __init__ ( self , [ ( a , b ) for b , a in values ] ) <EOL> def _value_matches ( self , value , item ) : <EOL> """<STR_LIT>""" <EOL> return item == '<STR_LIT:*>' or item . lower ( ) == value . lower ( ) <EOL> def __getitem__ ( self , key ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( key , basestring ) : <EOL> return self . quality ( key ) <EOL> return list . __getitem__ ( self , key ) <EOL> def quality ( self , key ) : <EOL> """<STR_LIT>""" <EOL> for item , quality in self : <EOL> if self . _value_matches ( key , item ) : <EOL> return quality <EOL> return <NUM_LIT:0> <EOL> def __contains__ ( self , value ) : <EOL> for item , quality in self : <EOL> if self . _value_matches ( value , item ) : <EOL> return True <EOL> return False <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , <EOL> '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' % ( x , y ) for x , y in self ) <EOL> ) <EOL> def index ( self , key ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( key , basestring ) : <EOL> for idx , ( item , quality ) in enumerate ( self ) : <EOL> if self . _value_matches ( key , item ) : <EOL> return idx <EOL> raise ValueError ( key ) <EOL> return list . index ( self , key ) <EOL> def find ( self , key ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . index ( key ) <EOL> except ValueError : <EOL> return - <NUM_LIT:1> <EOL> def values ( self ) : <EOL> """<STR_LIT>""" <EOL> return list ( self . itervalues ( ) ) <EOL> def itervalues ( self ) : <EOL> """<STR_LIT>""" <EOL> for item in self : <EOL> yield item [ <NUM_LIT:0> ] <EOL> def to_header ( self ) : <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> for value , quality in self : <EOL> if quality != <NUM_LIT:1> : <EOL> value = '<STR_LIT>' % ( value , quality ) <EOL> result . append ( value ) <EOL> return '<STR_LIT:U+002C>' . join ( result ) <EOL> def __str__ ( self ) : <EOL> return self . to_header ( ) <EOL> def best_match ( self , matches , default = None ) : <EOL> """<STR_LIT>""" <EOL> best_quality = - <NUM_LIT:1> <EOL> result = default <EOL> for server_item in matches : <EOL> for client_item , quality in self : <EOL> if quality <= best_quality : <EOL> break <EOL> if self . _value_matches ( client_item , server_item ) : <EOL> best_quality = quality <EOL> result = server_item <EOL> return result <EOL> @ property <EOL> def best ( self ) : <EOL> """<STR_LIT>""" <EOL> if self : <EOL> return self [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> class MIMEAccept ( Accept ) : <EOL> """<STR_LIT>""" <EOL> def _value_matches ( self , value , item ) : <EOL> def _normalize ( x ) : <EOL> x = x . lower ( ) <EOL> return x == '<STR_LIT:*>' and ( '<STR_LIT:*>' , '<STR_LIT:*>' ) or x . split ( '<STR_LIT:/>' , <NUM_LIT:1> ) <EOL> if '<STR_LIT:/>' not in value : <EOL> raise ValueError ( '<STR_LIT>' % value ) <EOL> value_type , value_subtype = _normalize ( value ) <EOL> if value_type == '<STR_LIT:*>' and value_subtype != '<STR_LIT:*>' : <EOL> raise ValueError ( '<STR_LIT>' % value ) <EOL> if '<STR_LIT:/>' not in item : <EOL> return False <EOL> item_type , item_subtype = _normalize ( item ) <EOL> if item_type == '<STR_LIT:*>' and item_subtype != '<STR_LIT:*>' : <EOL> return False <EOL> return ( <EOL> ( item_type == item_subtype == '<STR_LIT:*>' or <EOL> value_type == value_subtype == '<STR_LIT:*>' ) or <EOL> ( item_type == value_type and ( item_subtype == '<STR_LIT:*>' or <EOL> value_subtype == '<STR_LIT:*>' or <EOL> item_subtype == value_subtype ) ) <EOL> ) <EOL> @ property <EOL> def accept_html ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( <EOL> '<STR_LIT>' in self or <EOL> '<STR_LIT>' in self or <EOL> self . accept_xhtml <EOL> ) <EOL> @ property <EOL> def accept_xhtml ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( <EOL> '<STR_LIT>' in self or <EOL> '<STR_LIT>' in self <EOL> ) <EOL> class LanguageAccept ( Accept ) : <EOL> """<STR_LIT>""" <EOL> def _value_matches ( self , value , item ) : <EOL> def _normalize ( language ) : <EOL> return _locale_delim_re . split ( language . lower ( ) ) <EOL> return item == '<STR_LIT:*>' or _normalize ( value ) == _normalize ( item ) <EOL> class CharsetAccept ( Accept ) : <EOL> """<STR_LIT>""" <EOL> def _value_matches ( self , value , item ) : <EOL> def _normalize ( name ) : <EOL> try : <EOL> return codecs . lookup ( name ) . name <EOL> except LookupError : <EOL> return name . lower ( ) <EOL> return item == '<STR_LIT:*>' or _normalize ( value ) == _normalize ( item ) <EOL> def cache_property ( key , empty , type ) : <EOL> """<STR_LIT>""" <EOL> return property ( lambda x : x . _get_cache_value ( key , empty , type ) , <EOL> lambda x , v : x . _set_cache_value ( key , v , type ) , <EOL> lambda x : x . _del_cache_value ( key ) , <EOL> '<STR_LIT>' % key ) <EOL> class _CacheControl ( UpdateDictMixin , dict ) : <EOL> """<STR_LIT>""" <EOL> no_cache = cache_property ( '<STR_LIT>' , '<STR_LIT:*>' , None ) <EOL> no_store = cache_property ( '<STR_LIT>' , None , bool ) <EOL> max_age = cache_property ( '<STR_LIT>' , - <NUM_LIT:1> , int ) <EOL> no_transform = cache_property ( '<STR_LIT>' , None , None ) <EOL> def __init__ ( self , values = ( ) , on_update = None ) : <EOL> dict . __init__ ( self , values or ( ) ) <EOL> self . on_update = on_update <EOL> self . provided = values is not None <EOL> def _get_cache_value ( self , key , empty , type ) : <EOL> """<STR_LIT>""" <EOL> if type is bool : <EOL> return key in self <EOL> if key in self : <EOL> value = self [ key ] <EOL> if value is None : <EOL> return empty <EOL> elif type is not None : <EOL> try : <EOL> value = type ( value ) <EOL> except ValueError : <EOL> pass <EOL> return value <EOL> def _set_cache_value ( self , key , value , type ) : <EOL> """<STR_LIT>""" <EOL> if type is bool : <EOL> if value : <EOL> self [ key ] = None <EOL> else : <EOL> self . pop ( key , None ) <EOL> else : <EOL> if value is None : <EOL> self . pop ( key ) <EOL> elif value is True : <EOL> self [ key ] = None <EOL> else : <EOL> self [ key ] = value <EOL> def _del_cache_value ( self , key ) : <EOL> """<STR_LIT>""" <EOL> if key in self : <EOL> del self [ key ] <EOL> def to_header ( self ) : <EOL> """<STR_LIT>""" <EOL> return dump_header ( self ) <EOL> def __str__ ( self ) : <EOL> return self . to_header ( ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , <EOL> self . to_header ( ) <EOL> ) <EOL> class RequestCacheControl ( ImmutableDictMixin , _CacheControl ) : <EOL> """<STR_LIT>""" <EOL> max_stale = cache_property ( '<STR_LIT>' , '<STR_LIT:*>' , int ) <EOL> min_fresh = cache_property ( '<STR_LIT>' , '<STR_LIT:*>' , int ) <EOL> no_transform = cache_property ( '<STR_LIT>' , None , None ) <EOL> only_if_cached = cache_property ( '<STR_LIT>' , None , bool ) <EOL> class ResponseCacheControl ( _CacheControl ) : <EOL> """<STR_LIT>""" <EOL> public = cache_property ( '<STR_LIT>' , None , bool ) <EOL> private = cache_property ( '<STR_LIT>' , '<STR_LIT:*>' , None ) <EOL> must_revalidate = cache_property ( '<STR_LIT>' , None , bool ) <EOL> proxy_revalidate = cache_property ( '<STR_LIT>' , None , bool ) <EOL> s_maxage = cache_property ( '<STR_LIT>' , None , None ) <EOL> _CacheControl . cache_property = staticmethod ( cache_property ) <EOL> class CallbackDict ( UpdateDictMixin , dict ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , initial = None , on_update = None ) : <EOL> dict . __init__ ( self , initial or ( ) ) <EOL> self . on_update = on_update <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , <EOL> dict . __repr__ ( self ) <EOL> ) <EOL> class HeaderSet ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , headers = None , on_update = None ) : <EOL> self . _headers = list ( headers or ( ) ) <EOL> self . _set = set ( [ x . lower ( ) for x in self . _headers ] ) <EOL> self . on_update = on_update <EOL> def add ( self , header ) : <EOL> """<STR_LIT>""" <EOL> self . update ( ( header , ) ) <EOL> def remove ( self , header ) : <EOL> """<STR_LIT>""" <EOL> key = header . lower ( ) <EOL> if key not in self . _set : <EOL> raise KeyError ( header ) <EOL> self . _set . remove ( key ) <EOL> for idx , key in enumerate ( self . _headers ) : <EOL> if key . lower ( ) == header : <EOL> del self . _headers [ idx ] <EOL> break <EOL> if self . on_update is not None : <EOL> self . on_update ( self ) <EOL> def update ( self , iterable ) : <EOL> """<STR_LIT>""" <EOL> inserted_any = False <EOL> for header in iterable : <EOL> key = header . lower ( ) <EOL> if key not in self . _set : <EOL> self . _headers . append ( header ) <EOL> self . _set . add ( key ) <EOL> inserted_any = True <EOL> if inserted_any and self . on_update is not None : <EOL> self . on_update ( self ) <EOL> def discard ( self , header ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . remove ( header ) <EOL> except KeyError : <EOL> pass <EOL> def find ( self , header ) : <EOL> """<STR_LIT>""" <EOL> header = header . lower ( ) <EOL> for idx , item in enumerate ( self . _headers ) : <EOL> if item . lower ( ) == header : <EOL> return idx <EOL> return - <NUM_LIT:1> <EOL> def index ( self , header ) : <EOL> """<STR_LIT>""" <EOL> rv = self . find ( header ) <EOL> if rv < <NUM_LIT:0> : <EOL> raise IndexError ( header ) <EOL> return rv <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _set . clear ( ) <EOL> del self . _headers [ : ] <EOL> if self . on_update is not None : <EOL> self . on_update ( self ) <EOL> def as_set ( self , preserve_casing = False ) : <EOL> """<STR_LIT>""" <EOL> if preserve_casing : <EOL> return set ( self . _headers ) <EOL> return set ( self . _set ) <EOL> def to_header ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT:U+002CU+0020>' . join ( map ( quote_header_value , self . _headers ) ) <EOL> def __getitem__ ( self , idx ) : <EOL> return self . _headers [ idx ] <EOL> def __delitem__ ( self , idx ) : <EOL> rv = self . _headers . pop ( idx ) <EOL> self . _set . remove ( rv . lower ( ) ) <EOL> if self . on_update is not None : <EOL> self . on_update ( self ) <EOL> def __setitem__ ( self , idx , value ) : <EOL> old = self . _headers [ idx ] <EOL> self . _set . remove ( old . lower ( ) ) <EOL> self . _headers [ idx ] = value <EOL> self . _set . add ( value . lower ( ) ) <EOL> if self . on_update is not None : <EOL> self . on_update ( self ) <EOL> def __contains__ ( self , header ) : <EOL> return header . lower ( ) in self . _set <EOL> def __len__ ( self ) : <EOL> return len ( self . _set ) <EOL> def __iter__ ( self ) : <EOL> return iter ( self . _headers ) <EOL> def __nonzero__ ( self ) : <EOL> return bool ( self . _set ) <EOL> def __str__ ( self ) : <EOL> return self . to_header ( ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , <EOL> self . _headers <EOL> ) <EOL> class ETags ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , strong_etags = None , weak_etags = None , star_tag = False ) : <EOL> self . _strong = frozenset ( not star_tag and strong_etags or ( ) ) <EOL> self . _weak = frozenset ( weak_etags or ( ) ) <EOL> self . star_tag = star_tag <EOL> def as_set ( self , include_weak = False ) : <EOL> """<STR_LIT>""" <EOL> rv = set ( self . _strong ) <EOL> if include_weak : <EOL> rv . update ( self . _weak ) <EOL> return rv <EOL> def is_weak ( self , etag ) : <EOL> """<STR_LIT>""" <EOL> return etag in self . _weak <EOL> def contains_weak ( self , etag ) : <EOL> """<STR_LIT>""" <EOL> return self . is_weak ( etag ) or self . contains ( etag ) <EOL> def contains ( self , etag ) : <EOL> """<STR_LIT>""" <EOL> if self . star_tag : <EOL> return True <EOL> return etag in self . _strong <EOL> def contains_raw ( self , etag ) : <EOL> """<STR_LIT>""" <EOL> etag , weak = unquote_etag ( etag ) <EOL> if weak : <EOL> return self . contains_weak ( etag ) <EOL> return self . contains ( etag ) <EOL> def to_header ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . star_tag : <EOL> return '<STR_LIT:*>' <EOL> return '<STR_LIT:U+002CU+0020>' . join ( <EOL> [ '<STR_LIT>' % x for x in self . _strong ] + <EOL> [ '<STR_LIT>' % x for x in self . _weak ] <EOL> ) <EOL> def __call__ ( self , etag = None , data = None , include_weak = False ) : <EOL> if [ etag , data ] . count ( None ) != <NUM_LIT:1> : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> if etag is None : <EOL> etag = generate_etag ( data ) <EOL> if include_weak : <EOL> if etag in self . _weak : <EOL> return True <EOL> return etag in self . _strong <EOL> def __nonzero__ ( self ) : <EOL> return bool ( self . star_tag or self . _strong ) <EOL> def __str__ ( self ) : <EOL> return self . to_header ( ) <EOL> def __iter__ ( self ) : <EOL> return iter ( self . _strong ) <EOL> def __contains__ ( self , etag ) : <EOL> return self . contains ( etag ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , str ( self ) ) <EOL> class Authorization ( ImmutableDictMixin , dict ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , auth_type , data = None ) : <EOL> dict . __init__ ( self , data or { } ) <EOL> self . type = auth_type <EOL> username = property ( lambda x : x . get ( '<STR_LIT:username>' ) , doc = '''<STR_LIT>''' ) <EOL> password = property ( lambda x : x . get ( '<STR_LIT:password>' ) , doc = '''<STR_LIT>''' ) <EOL> realm = property ( lambda x : x . get ( '<STR_LIT>' ) , doc = '''<STR_LIT>''' ) <EOL> nonce = property ( lambda x : x . get ( '<STR_LIT>' ) , doc = '''<STR_LIT>''' ) <EOL> uri = property ( lambda x : x . get ( '<STR_LIT>' ) , doc = '''<STR_LIT>''' ) <EOL> nc = property ( lambda x : x . get ( '<STR_LIT>' ) , doc = '''<STR_LIT>''' ) <EOL> cnonce = property ( lambda x : x . get ( '<STR_LIT>' ) , doc = '''<STR_LIT>''' ) <EOL> response = property ( lambda x : x . get ( '<STR_LIT>' ) , doc = '''<STR_LIT>''' ) <EOL> opaque = property ( lambda x : x . get ( '<STR_LIT>' ) , doc = '''<STR_LIT>''' ) <EOL> @ property <EOL> def qop ( self ) : <EOL> """<STR_LIT>""" <EOL> def on_update ( header_set ) : <EOL> if not header_set and '<STR_LIT>' in self : <EOL> del self [ '<STR_LIT>' ] <EOL> elif header_set : <EOL> self [ '<STR_LIT>' ] = header_set . to_header ( ) <EOL> return parse_set_header ( self . get ( '<STR_LIT>' ) , on_update ) <EOL> class WWWAuthenticate ( UpdateDictMixin , dict ) : <EOL> """<STR_LIT>""" <EOL> _require_quoting = frozenset ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def __init__ ( self , auth_type = None , values = None , on_update = None ) : <EOL> dict . __init__ ( self , values or ( ) ) <EOL> if auth_type : <EOL> self [ '<STR_LIT>' ] = auth_type <EOL> self . on_update = on_update <EOL> def set_basic ( self , realm = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> dict . clear ( self ) <EOL> dict . update ( self , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : realm } ) <EOL> if self . on_update : <EOL> self . on_update ( self ) <EOL> def set_digest ( self , realm , nonce , qop = ( '<STR_LIT>' , ) , opaque = None , <EOL> algorithm = None , stale = False ) : <EOL> """<STR_LIT>""" <EOL> d = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : realm , <EOL> '<STR_LIT>' : nonce , <EOL> '<STR_LIT>' : dump_header ( qop ) <EOL> } <EOL> if stale : <EOL> d [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if opaque is not None : <EOL> d [ '<STR_LIT>' ] = opaque <EOL> if algorithm is not None : <EOL> d [ '<STR_LIT>' ] = algorithm <EOL> dict . clear ( self ) <EOL> dict . update ( self , d ) <EOL> if self . on_update : <EOL> self . on_update ( self ) <EOL> def to_header ( self ) : <EOL> """<STR_LIT>""" <EOL> d = dict ( self ) <EOL> auth_type = d . pop ( '<STR_LIT>' , None ) or '<STR_LIT>' <EOL> return '<STR_LIT>' % ( auth_type . title ( ) , '<STR_LIT:U+002CU+0020>' . join ( [ <EOL> '<STR_LIT>' % ( key , quote_header_value ( value , <EOL> allow_token = key not in self . _require_quoting ) ) <EOL> for key , value in d . iteritems ( ) <EOL> ] ) ) <EOL> def __str__ ( self ) : <EOL> return self . to_header ( ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , <EOL> self . to_header ( ) <EOL> ) <EOL> def auth_property ( name , doc = None ) : <EOL> """<STR_LIT>""" <EOL> def _set_value ( self , value ) : <EOL> if value is None : <EOL> self . pop ( name , None ) <EOL> else : <EOL> self [ name ] = str ( value ) <EOL> return property ( lambda x : x . get ( name ) , _set_value , doc = doc ) <EOL> def _set_property ( name , doc = None ) : <EOL> def fget ( self ) : <EOL> def on_update ( header_set ) : <EOL> if not header_set and name in self : <EOL> del self [ name ] <EOL> elif header_set : <EOL> self [ name ] = header_set . to_header ( ) <EOL> return parse_set_header ( self . get ( name ) , on_update ) <EOL> return property ( fget , doc = doc ) <EOL> type = auth_property ( '<STR_LIT>' , doc = '''<STR_LIT>''' ) <EOL> realm = auth_property ( '<STR_LIT>' , doc = '''<STR_LIT>''' ) <EOL> domain = _set_property ( '<STR_LIT>' , doc = '''<STR_LIT>''' ) <EOL> nonce = auth_property ( '<STR_LIT>' , doc = '''<STR_LIT>''' ) <EOL> opaque = auth_property ( '<STR_LIT>' , doc = '''<STR_LIT>''' ) <EOL> algorithm = auth_property ( '<STR_LIT>' , doc = '''<STR_LIT>''' ) <EOL> qop = _set_property ( '<STR_LIT>' , doc = '''<STR_LIT>''' ) <EOL> def _get_stale ( self ) : <EOL> val = self . get ( '<STR_LIT>' ) <EOL> if val is not None : <EOL> return val . lower ( ) == '<STR_LIT:true>' <EOL> def _set_stale ( self , value ) : <EOL> if value is None : <EOL> self . pop ( '<STR_LIT>' , None ) <EOL> else : <EOL> self [ '<STR_LIT>' ] = value and '<STR_LIT>' or '<STR_LIT>' <EOL> stale = property ( _get_stale , _set_stale , doc = '''<STR_LIT>''' ) <EOL> del _get_stale , _set_stale <EOL> auth_property = staticmethod ( auth_property ) <EOL> del _set_property <EOL> class FileStorage ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , stream = None , filename = None , name = None , <EOL> content_type = '<STR_LIT>' , content_length = - <NUM_LIT:1> , <EOL> headers = None ) : <EOL> self . name = name <EOL> self . stream = stream or _empty_stream <EOL> self . filename = filename or getattr ( stream , '<STR_LIT:name>' , None ) <EOL> self . content_type = content_type <EOL> self . content_length = content_length <EOL> if headers is None : <EOL> headers = Headers ( ) <EOL> self . headers = headers <EOL> def save ( self , dst , buffer_size = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> from shutil import copyfileobj <EOL> close_dst = False <EOL> if isinstance ( dst , basestring ) : <EOL> dst = file ( dst , '<STR_LIT:wb>' ) <EOL> close_dst = True <EOL> try : <EOL> copyfileobj ( self . stream , dst , buffer_size ) <EOL> finally : <EOL> if close_dst : <EOL> dst . close ( ) <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . stream . close ( ) <EOL> except : <EOL> pass <EOL> def __nonzero__ ( self ) : <EOL> return bool ( self . filename ) <EOL> def __getattr__ ( self , name ) : <EOL> return getattr ( self . stream , name ) <EOL> def __iter__ ( self ) : <EOL> return iter ( self . readline , '<STR_LIT>' ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , <EOL> self . filename , <EOL> self . content_type <EOL> ) <EOL> from werkzeug . http import dump_options_header , dump_header , generate_etag , quote_header_value , parse_set_header , unquote_etag <EOL> from werkzeug . exceptions import BadRequest <EOL> for _cls in MultiDict , OrderedMultiDict , CombinedMultiDict , Headers , EnvironHeaders : <EOL> _cls . KeyError = BadRequest . wrap ( KeyError , _cls . __name__ + '<STR_LIT>' ) <EOL> del _cls </s>
