<s> from . cassette import Cassette <EOL> def validate_record ( record ) : <EOL> return record in [ '<STR_LIT:all>' , '<STR_LIT>' , '<STR_LIT:none>' , '<STR_LIT>' ] <EOL> def validate_matchers ( matchers ) : <EOL> from betamax . matchers import matcher_registry <EOL> available_matchers = list ( matcher_registry . keys ( ) ) <EOL> return all ( m in available_matchers for m in matchers ) <EOL> def validate_serializer ( serializer ) : <EOL> from betamax . serializers import serializer_registry <EOL> return serializer in list ( serializer_registry . keys ( ) ) <EOL> def validate_placeholders ( placeholders ) : <EOL> """<STR_LIT>""" <EOL> keys = [ '<STR_LIT>' , '<STR_LIT:replace>' ] <EOL> return all ( <EOL> sorted ( list ( p . keys ( ) ) ) == keys for p in placeholders <EOL> ) <EOL> def translate_cassette_options ( ) : <EOL> for ( k , v ) in Cassette . default_cassette_options . items ( ) : <EOL> yield ( k , v ) if k != '<STR_LIT>' else ( '<STR_LIT>' , v ) <EOL> def isboolean ( value ) : <EOL> return value in [ True , False ] <EOL> class Options ( object ) : <EOL> valid_options = { <EOL> '<STR_LIT>' : validate_matchers , <EOL> '<STR_LIT>' : lambda x : x is None or x > <NUM_LIT:0> , <EOL> '<STR_LIT>' : validate_record , <EOL> '<STR_LIT>' : validate_serializer , <EOL> '<STR_LIT>' : validate_serializer , <EOL> '<STR_LIT>' : isboolean , <EOL> '<STR_LIT>' : validate_placeholders , <EOL> '<STR_LIT>' : isboolean , <EOL> } <EOL> defaults = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : False , <EOL> } <EOL> def __init__ ( self , data = None ) : <EOL> self . data = data or { } <EOL> self . validate ( ) <EOL> self . defaults = Options . defaults . copy ( ) <EOL> self . defaults . update ( translate_cassette_options ( ) ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . data <EOL> def __getitem__ ( self , key ) : <EOL> return self . data . get ( key , self . defaults . get ( key ) ) <EOL> def __setitem__ ( self , key , value ) : <EOL> self . data [ key ] = value <EOL> return value <EOL> def __delitem__ ( self , key ) : <EOL> del self . data [ key ] <EOL> def __contains__ ( self , key ) : <EOL> return key in self . data <EOL> def items ( self ) : <EOL> return self . data . items ( ) <EOL> def validate ( self ) : <EOL> for key , value in list ( self . data . items ( ) ) : <EOL> if key not in Options . valid_options : <EOL> del self [ key ] <EOL> else : <EOL> is_valid = Options . valid_options [ key ] <EOL> if not is_valid ( value ) : <EOL> del self [ key ] </s>
