<s> import abc <EOL> import six <EOL> NOTSET = object ( ) <EOL> @ six . add_metaclass ( abc . ABCMeta ) <EOL> class BaseCache ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parsed_url , options = None ) : <EOL> self . _parsed_url = parsed_url <EOL> self . _options = options or { } <EOL> self . _default_ttl = int ( self . _options . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> @ abc . abstractmethod <EOL> def _set ( self , key , value , ttl , not_exists = False ) : <EOL> """<STR_LIT>""" <EOL> def set ( self , key , value , ttl , not_exists = False ) : <EOL> """<STR_LIT>""" <EOL> if ttl is None : <EOL> ttl = self . _default_ttl <EOL> return self . _set ( key , value , ttl , not_exists ) <EOL> def __setitem__ ( self , key , value ) : <EOL> self . set ( key , value , self . _default_ttl ) <EOL> def setdefault ( self , key , value ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self [ key ] <EOL> except KeyError : <EOL> self [ key ] = value <EOL> return value <EOL> @ abc . abstractmethod <EOL> def _get ( self , key , default ) : <EOL> """<STR_LIT>""" <EOL> def get ( self , key , default = None ) : <EOL> """<STR_LIT>""" <EOL> return self . _get ( key , default ) <EOL> def __getitem__ ( self , key ) : <EOL> value = self . get ( key , NOTSET ) <EOL> if value is NOTSET : <EOL> raise KeyError <EOL> return value <EOL> @ abc . abstractmethod <EOL> def __delitem__ ( self , key ) : <EOL> """<STR_LIT>""" <EOL> @ abc . abstractmethod <EOL> def _clear ( self ) : <EOL> """<STR_LIT>""" <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _clear ( ) <EOL> @ abc . abstractmethod <EOL> def _incr ( self , key , delta ) : <EOL> """<STR_LIT>""" <EOL> def incr ( self , key , delta = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> return self . _incr ( key , delta ) <EOL> @ abc . abstractmethod <EOL> def _append_tail ( self , key , tail ) : <EOL> """<STR_LIT>""" <EOL> def append_tail ( self , key , tail ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( tail , "<STR_LIT>" ) : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> if not isinstance ( tail , list ) : <EOL> tail = list ( tail ) <EOL> return self . _append_tail ( key , tail ) <EOL> def append ( self , key , value ) : <EOL> """<STR_LIT>""" <EOL> return self . append_tail ( key , [ value ] ) <EOL> @ abc . abstractmethod <EOL> def __contains__ ( self , key ) : <EOL> """<STR_LIT>""" <EOL> @ abc . abstractmethod <EOL> def _get_many ( self , keys , default ) : <EOL> """<STR_LIT>""" <EOL> return ( ( k , self . get ( k , default = default ) ) for k in keys ) <EOL> def get_many ( self , keys , default = NOTSET ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_many ( keys , default ) <EOL> @ abc . abstractmethod <EOL> def _set_many ( self , data , ttl ) : <EOL> """<STR_LIT>""" <EOL> for key , value in data . items ( ) : <EOL> self . set ( key , value , ttl = ttl ) <EOL> def set_many ( self , data , ttl = None ) : <EOL> """<STR_LIT>""" <EOL> if ttl is None : <EOL> ttl = self . _default_ttl <EOL> self . _set_many ( data , ttl ) <EOL> def update ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . set_many ( kwargs , ttl = self . _default_ttl ) <EOL> @ abc . abstractmethod <EOL> def _unset_many ( self , keys ) : <EOL> """<STR_LIT>""" <EOL> for key in keys : <EOL> del self [ key ] <EOL> def unset_many ( self , keys ) : <EOL> """<STR_LIT>""" <EOL> self . _unset_many ( keys ) </s>
