<s> import calendar <EOL> import re <EOL> import datetime <EOL> class InvalidCard ( Exception ) : <EOL> pass <EOL> class CardNotSupported ( Exception ) : <EOL> pass <EOL> class CreditCard ( object ) : <EOL> regexp = None <EOL> card_type = None <EOL> card_name = None <EOL> def __init__ ( self , ** kwargs ) : <EOL> if ( "<STR_LIT>" not in kwargs <EOL> or "<STR_LIT>" not in kwargs ) and "<STR_LIT>" not in kwargs : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> self . first_name = kwargs . get ( "<STR_LIT>" , None ) <EOL> self . last_name = kwargs . get ( "<STR_LIT>" , None ) <EOL> self . cardholders_name = kwargs . get ( "<STR_LIT>" , None ) <EOL> self . month = int ( kwargs [ "<STR_LIT>" ] ) <EOL> self . year = int ( kwargs [ "<STR_LIT>" ] ) <EOL> self . number = kwargs [ "<STR_LIT>" ] <EOL> self . verification_value = kwargs [ "<STR_LIT>" ] <EOL> def is_luhn_valid ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> num = [ int ( x ) for x in str ( self . number ) ] <EOL> except ValueError : <EOL> return False <EOL> return not sum ( num [ : : - <NUM_LIT:2> ] + [ sum ( divmod ( d * <NUM_LIT:2> , <NUM_LIT:10> ) ) for d in num [ - <NUM_LIT:2> : : - <NUM_LIT:2> ] ] ) % <NUM_LIT:10> <EOL> def is_expired ( self ) : <EOL> """<STR_LIT>""" <EOL> return datetime . date . today ( ) > datetime . date ( self . year , self . month , calendar . monthrange ( self . year , self . month ) [ <NUM_LIT:1> ] ) <EOL> def valid_essential_attributes ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( ( ( self . first_name and <EOL> self . last_name ) or <EOL> self . cardholders_name ) <EOL> and self . month <EOL> and self . year <EOL> and self . number <EOL> and self . verification_value ) <EOL> def is_valid ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . is_luhn_valid ( ) and not self . is_expired ( ) and self . valid_essential_attributes ( ) <EOL> @ property <EOL> def expire_date ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % ( self . month , self . year ) <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % ( self . first_name , self . last_name ) <EOL> class Visa ( CreditCard ) : <EOL> card_name = "<STR_LIT>" <EOL> regexp = re . compile ( '<STR_LIT>' ) <EOL> class MasterCard ( CreditCard ) : <EOL> card_name = "<STR_LIT>" <EOL> regexp = re . compile ( '<STR_LIT>' ) <EOL> class Discover ( CreditCard ) : <EOL> card_name = "<STR_LIT>" <EOL> regexp = re . compile ( '<STR_LIT>' ) <EOL> class AmericanExpress ( CreditCard ) : <EOL> card_name = "<STR_LIT>" <EOL> regexp = re . compile ( '<STR_LIT>' ) <EOL> class DinersClub ( CreditCard ) : <EOL> card_name = "<STR_LIT>" <EOL> regexp = re . compile ( '<STR_LIT>' ) <EOL> class JCB ( CreditCard ) : <EOL> card_name = "<STR_LIT>" <EOL> regexp = re . compile ( '<STR_LIT>' ) <EOL> class Switch ( CreditCard ) : <EOL> card_name = "<STR_LIT>" <EOL> regexp = re . compile ( '<STR_LIT>' ) <EOL> class Solo ( CreditCard ) : <EOL> card_name = "<STR_LIT>" <EOL> regexp = re . compile ( '<STR_LIT>' ) <EOL> class Dankort ( CreditCard ) : <EOL> card_name = "<STR_LIT>" <EOL> regexp = re . compile ( '<STR_LIT>' ) <EOL> class Maestro ( CreditCard ) : <EOL> card_name = "<STR_LIT>" <EOL> regexp = re . compile ( '<STR_LIT>' ) <EOL> class Forbrugsforeningen ( CreditCard ) : <EOL> card_name = "<STR_LIT>" <EOL> regexp = re . compile ( '<STR_LIT>' ) <EOL> class Laser ( CreditCard ) : <EOL> card_name = "<STR_LIT>" <EOL> regexp = re . compile ( '<STR_LIT>' ) <EOL> all_credit_cards = [ Visa , MasterCard , Discover , AmericanExpress , <EOL> DinersClub , JCB ] <EOL> all_debit_cards = [ Switch , Solo , Dankort , Maestro , <EOL> Forbrugsforeningen , Laser ] <EOL> all_cards = all_credit_cards + all_debit_cards </s>
