<s> import re <EOL> from re_constants import DISALLOWED_PATTERNS , DISALLOWED_CHARS , VALID_SEQUENCE_NUMBER_PATTERNS <EOL> def re_regex_is_valid ( regex_str = False ) : <EOL> """<STR_LIT>""" <EOL> if not regex_str : <EOL> return False <EOL> print '<STR_LIT:1>' <EOL> if re_has_disallowed_patterns ( regex_str ) : <EOL> return False <EOL> print '<STR_LIT:2>' <EOL> if not re_has_scopes ( regex_str ) : <EOL> return False <EOL> print '<STR_LIT:3>' <EOL> if not re_equal_scopes ( regex_str ) : <EOL> return False <EOL> print '<STR_LIT:4>' <EOL> if not re_has_one_pattern ( regex_str ) : <EOL> return False <EOL> print '<STR_LIT:5>' <EOL> return True <EOL> def re_has_disallowed_patterns ( regex_str ) : <EOL> for wrong_pattern in DISALLOWED_PATTERNS : <EOL> try : <EOL> if re . search ( wrong_pattern , regex_str ) : <EOL> return True <EOL> except : <EOL> pass <EOL> for char in DISALLOWED_CHARS : <EOL> if char in regex_str : <EOL> return True <EOL> return False <EOL> def re_equal_scopes ( regex_str ) : <EOL> a = b = c = d = <NUM_LIT:0> <EOL> for reg_char in regex_str : <EOL> if reg_char [ regex_str ] == '<STR_LIT:[>' : a += <NUM_LIT:1> <EOL> if reg_char [ regex_str ] == '<STR_LIT:]>' : b += <NUM_LIT:1> <EOL> if reg_char [ regex_str ] == '<STR_LIT:{>' : c += <NUM_LIT:1> <EOL> if reg_char [ regex_str ] == '<STR_LIT:}>' : d += <NUM_LIT:1> <EOL> if a == b and c == d : <EOL> return True <EOL> else : <EOL> return False <EOL> def re_has_one_pattern ( regex_str ) : <EOL> return re . search ( '<STR_LIT>' , regex_str ) <EOL> def re_has_scopes ( regex_str ) : <EOL> if not '<STR_LIT:[>' or not '<STR_LIT:]>' in regex_str : <EOL> return False <EOL> if not '<STR_LIT:[>' and not '<STR_LIT:]>' in regex_str : <EOL> return False <EOL> return True </s>
