<s> import abc <EOL> from python_toolbox import abc_tools <EOL> from python_toolbox import sequence_tools <EOL> from python_toolbox import string_tools <EOL> from python_toolbox . misc_tools import name_mangling <EOL> class CaseStyleType ( abc . ABCMeta ) : <EOL> '''<STR_LIT>''' <EOL> class BaseCaseStyle ( object ) : <EOL> '''<STR_LIT>''' <EOL> __metaclass__ = CaseStyleType <EOL> @ abc_tools . AbstractStaticMethod <EOL> def parse ( name ) : <EOL> '''<STR_LIT>''' <EOL> class LowerCase ( BaseCaseStyle ) : <EOL> '''<STR_LIT>''' <EOL> @ staticmethod <EOL> def parse ( name ) : <EOL> '''<STR_LIT>''' <EOL> if not name . startswith ( '<STR_LIT>' ) : <EOL> return None <EOL> cleaned_name = name [ <NUM_LIT:3> : ] <EOL> words = tuple ( cleaned_name . split ( '<STR_LIT>' ) ) <EOL> return words <EOL> class CamelCase ( BaseCaseStyle ) : <EOL> '''<STR_LIT>''' <EOL> @ staticmethod <EOL> def parse ( name ) : <EOL> '''<STR_LIT>''' <EOL> if not name . startswith ( '<STR_LIT>' ) : <EOL> return None <EOL> cleaned_name = name [ <NUM_LIT:2> : ] <EOL> words = tuple ( cleaned_name . split ( '<STR_LIT:_>' ) ) <EOL> return words <EOL> class NameParser ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , case_style_possibilites = ( LowerCase , ) , <EOL> n_preceding_underscores_possibilities = ( <NUM_LIT:1> , ) ) : <EOL> '''<STR_LIT>''' <EOL> self . case_style_possibilites = sequence_tools . to_tuple ( <EOL> case_style_possibilites , <EOL> item_type = CaseStyleType <EOL> ) <EOL> '''<STR_LIT>''' <EOL> self . n_preceding_underscores_possibilities = sequence_tools . to_tuple ( <EOL> n_preceding_underscores_possibilities <EOL> ) <EOL> '''<STR_LIT>''' <EOL> assert all ( isinstance ( case_style , CaseStyleType ) for case_style in <EOL> self . case_style_possibilites ) <EOL> assert all ( isinstance ( n_preceding_underscores , int ) for <EOL> n_preceding_underscores in <EOL> self . n_preceding_underscores_possibilities ) <EOL> def parse ( self , name , class_name ) : <EOL> '''<STR_LIT>''' <EOL> unmangled_name = name_mangling . unmangle_attribute_name_if_needed ( <EOL> name , <EOL> class_name <EOL> ) <EOL> n_preceding_underscores = string_tools . get_n_identical_edge_characters ( <EOL> unmangled_name , <EOL> character = '<STR_LIT:_>' , <EOL> head = True <EOL> ) <EOL> if n_preceding_underscores not in self . n_preceding_underscores_possibilities : <EOL> return None <EOL> cleaned_name = unmangled_name [ n_preceding_underscores : ] <EOL> for case_style in self . case_style_possibilites : <EOL> result = case_style . parse ( cleaned_name ) <EOL> if result is not None : <EOL> return result <EOL> else : <EOL> return None <EOL> def match ( self , name , class_name ) : <EOL> '''<STR_LIT>''' <EOL> return ( self . parse ( name , class_name ) is not None ) </s>
