<s> """<STR_LIT>""" <EOL> from webob . datetime_utils import * <EOL> from webob . util import header_docstring , warn_deprecation <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def etag_property ( key , default , rfc_section ) : <EOL> doc = header_docstring ( key , rfc_section ) <EOL> doc += "<STR_LIT>" <EOL> def fget ( req ) : <EOL> value = req . environ . get ( key ) <EOL> if not value : <EOL> return default <EOL> elif value == '<STR_LIT:*>' : <EOL> return AnyETag <EOL> else : <EOL> return ETagMatcher . parse ( value ) <EOL> def fset ( req , val ) : <EOL> if val is None : <EOL> req . environ [ key ] = None <EOL> else : <EOL> req . environ [ key ] = str ( val ) <EOL> def fdel ( req ) : <EOL> del req . environ [ key ] <EOL> return property ( fget , fset , fdel , doc = doc ) <EOL> def _warn_weak_match_deprecated ( ) : <EOL> warn_deprecation ( "<STR_LIT>" , '<STR_LIT>' , <NUM_LIT:3> ) <EOL> class _AnyETag ( object ) : <EOL> """<STR_LIT>""" <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' <EOL> def __nonzero__ ( self ) : <EOL> return False <EOL> def __contains__ ( self , other ) : <EOL> return True <EOL> def weak_match ( self , other ) : <EOL> _warn_weak_match_deprecated ( ) <EOL> return True <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT:*>' <EOL> AnyETag = _AnyETag ( ) <EOL> class _NoETag ( object ) : <EOL> """<STR_LIT>""" <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' <EOL> def __nonzero__ ( self ) : <EOL> return False <EOL> def __contains__ ( self , other ) : <EOL> return False <EOL> def weak_match ( self , other ) : <EOL> _warn_weak_match_deprecated ( ) <EOL> return False <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' <EOL> NoETag = _NoETag ( ) <EOL> class ETagMatcher ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , etags , weak_etags = ( ) ) : <EOL> self . etags = etags <EOL> self . weak_etags = weak_etags <EOL> def __contains__ ( self , other ) : <EOL> return other in self . etags or other in self . weak_etags <EOL> def weak_match ( self , other ) : <EOL> _warn_weak_match_deprecated ( ) <EOL> if other . lower ( ) . startswith ( '<STR_LIT>' ) : <EOL> other = other [ <NUM_LIT:2> : ] <EOL> return other in self . etags or other in self . weak_etags <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> '<STR_LIT>' . join ( self . etags ) ) <EOL> @ classmethod <EOL> def parse ( cls , value ) : <EOL> """<STR_LIT>""" <EOL> results = [ ] <EOL> weak_results = [ ] <EOL> while value : <EOL> if value . lower ( ) . startswith ( '<STR_LIT>' ) : <EOL> weak = True <EOL> value = value [ <NUM_LIT:2> : ] <EOL> else : <EOL> weak = False <EOL> if value . startswith ( '<STR_LIT:">' ) : <EOL> try : <EOL> etag , rest = value [ <NUM_LIT:1> : ] . split ( '<STR_LIT:">' , <NUM_LIT:1> ) <EOL> except ValueError : <EOL> etag = value . strip ( '<STR_LIT>' ) <EOL> rest = '<STR_LIT>' <EOL> else : <EOL> rest = rest . strip ( '<STR_LIT:U+002CU+0020>' ) <EOL> else : <EOL> if '<STR_LIT:U+002C>' in value : <EOL> etag , rest = value . split ( '<STR_LIT:U+002C>' , <NUM_LIT:1> ) <EOL> rest = rest . strip ( ) <EOL> else : <EOL> etag = value <EOL> rest = '<STR_LIT>' <EOL> if etag == '<STR_LIT:*>' : <EOL> return AnyETag <EOL> if etag : <EOL> if weak : <EOL> weak_results . append ( etag ) <EOL> else : <EOL> results . append ( etag ) <EOL> value = rest <EOL> return cls ( results , weak_results ) <EOL> def __str__ ( self ) : <EOL> items = map ( '<STR_LIT>' . __mod__ , self . etags ) <EOL> for weak in self . weak_etags : <EOL> items . append ( '<STR_LIT>' % weak ) <EOL> return '<STR_LIT:U+002CU+0020>' . join ( items ) <EOL> class IfRange ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , etag = None , date = None ) : <EOL> self . etag = etag <EOL> self . date = date <EOL> def __repr__ ( self ) : <EOL> if self . etag is None : <EOL> etag = '<STR_LIT:*>' <EOL> else : <EOL> etag = str ( self . etag ) <EOL> if self . date is None : <EOL> date = '<STR_LIT:*>' <EOL> else : <EOL> date = serialize_date ( self . date ) <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , <EOL> etag , date ) <EOL> def __str__ ( self ) : <EOL> if self . etag is not None : <EOL> return str ( self . etag ) <EOL> elif self . date : <EOL> return serialize_date ( self . date ) <EOL> else : <EOL> return '<STR_LIT>' <EOL> def match ( self , etag = None , last_modified = None ) : <EOL> """<STR_LIT>""" <EOL> if self . date is not None : <EOL> if last_modified is None : <EOL> return False <EOL> return last_modified <= self . date <EOL> elif self . etag is not None : <EOL> if not etag : <EOL> return False <EOL> return etag in self . etag <EOL> return True <EOL> def match_response ( self , response ) : <EOL> """<STR_LIT>""" <EOL> return self . match ( etag = response . etag , last_modified = response . last_modified ) <EOL> @ classmethod <EOL> def parse ( cls , value ) : <EOL> """<STR_LIT>""" <EOL> date = etag = None <EOL> if not value : <EOL> etag = NoETag ( ) <EOL> elif value and value . endswith ( '<STR_LIT>' ) : <EOL> date = parse_date ( value ) <EOL> else : <EOL> etag = ETagMatcher . parse ( value ) <EOL> return cls ( etag = etag , date = date ) <EOL> class _NoIfRange ( object ) : <EOL> """<STR_LIT>""" <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' <EOL> def __nonzero__ ( self ) : <EOL> return False <EOL> def match ( self , etag = None , last_modified = None ) : <EOL> return True <EOL> def match_response ( self , response ) : <EOL> return True <EOL> NoIfRange = _NoIfRange ( ) </s>
