<s> """<STR_LIT>""" <EOL> from django . utils import six <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> LUHN_ODD_LOOKUP = ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> , <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:7> , <NUM_LIT:9> ) <EOL> EAN_LOOKUP = ( <NUM_LIT:3> , <NUM_LIT:1> ) <EOL> def luhn ( candidate ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( candidate , six . string_types ) : <EOL> candidate = str ( candidate ) <EOL> try : <EOL> evens = sum ( int ( c ) for c in candidate [ - <NUM_LIT:1> : : - <NUM_LIT:2> ] ) <EOL> odds = sum ( LUHN_ODD_LOOKUP [ int ( c ) ] for c in candidate [ - <NUM_LIT:2> : : - <NUM_LIT:2> ] ) <EOL> return ( ( evens + odds ) % <NUM_LIT:10> == <NUM_LIT:0> ) <EOL> except ValueError : <EOL> return False <EOL> def ean ( candidate ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( candidate , six . string_types ) : <EOL> candidate = str ( candidate ) <EOL> if len ( candidate ) <= <NUM_LIT:1> : <EOL> return False <EOL> given_number , given_checksum = candidate [ : - <NUM_LIT:1> ] , candidate [ - <NUM_LIT:1> ] <EOL> try : <EOL> calculated_checksum = sum ( <EOL> int ( digit ) * EAN_LOOKUP [ i % <NUM_LIT:2> ] for i , digit in enumerate ( reversed ( given_number ) ) ) <EOL> calculated_checksum = <NUM_LIT:10> - ( calculated_checksum % <NUM_LIT:10> ) <EOL> return str ( calculated_checksum ) == given_checksum <EOL> except ValueError : <EOL> return False </s>
