<s> """<STR_LIT>""" <EOL> import sys <EOL> sys . path . append ( '<STR_LIT:..>' ) <EOL> import wikipedia <EOL> from wikipedia import output <EOL> import family_check <EOL> import re <EOL> r_namespace_section_main = r'<STR_LIT>' <EOL> r_namespace_section_sub = r'<STR_LIT>' <EOL> r_namespace_section_once = r'<STR_LIT>' <EOL> r_string = '<STR_LIT>' <EOL> r_list = '<STR_LIT>' <EOL> r_namespace_def = re . compile ( r'<STR_LIT>' % ( r_string , r_list ) ) <EOL> def update_family ( family , changes ) : <EOL> global namespace_section_text , namespace_defs , new_defs <EOL> if family : <EOL> output ( u'<STR_LIT>' % family . name ) <EOL> family_file_name = '<STR_LIT>' % family . name <EOL> r_namespace_section = r_namespace_section_sub <EOL> base_indent = <NUM_LIT:8> <EOL> else : <EOL> output ( u'<STR_LIT>' ) <EOL> family_file_name = '<STR_LIT>' <EOL> r_namespace_section = r_namespace_section_main <EOL> base_indent = <NUM_LIT:12> <EOL> family_file = open ( family_file_name , '<STR_LIT:r>' ) <EOL> old_family_text = family_text = family_file . read ( ) <EOL> family_file . close ( ) <EOL> for lang , namespaces in changes . iteritems ( ) : <EOL> for namespace_id , namespace_name , predefined_namespace in namespaces : <EOL> output ( u'<STR_LIT>' % ( namespace_id , lang , namespace_name ) ) <EOL> namespace_section = re . search ( r_namespace_section % namespace_id , family_text ) <EOL> if not namespace_section : <EOL> continue <EOL> namespace_section_text = namespace_section . group ( <NUM_LIT:1> ) <EOL> namespace_defs = dict ( [ ( match . group ( <NUM_LIT:1> ) , match . group ( <NUM_LIT:2> ) ) <EOL> for match in r_namespace_def . finditer ( namespace_section_text ) ] ) <EOL> if not namespace_defs . get ( lang , '<STR_LIT>' ) . startswith ( '<STR_LIT:[>' ) : <EOL> output ( u'<STR_LIT>' % ( namespace_id , namespace_name ) ) <EOL> namespace_defs [ lang ] = escape_string ( namespace_name . encode ( '<STR_LIT:utf-8>' ) ) <EOL> else : <EOL> output ( u'<STR_LIT>' % namespace_id ) <EOL> new_defs = namespace_defs . items ( ) <EOL> new_defs . sort ( key = lambda x : x [ <NUM_LIT:0> ] ) <EOL> new_text = '<STR_LIT:\n>' + '<STR_LIT>' . join ( [ ( base_indent + <NUM_LIT:4> ) * '<STR_LIT:U+0020>' + "<STR_LIT>" % i for i in new_defs ] ) + '<STR_LIT:U+0020>' * base_indent <EOL> family_text = family_text . replace ( namespace_section . group ( <NUM_LIT:1> ) , new_text ) <EOL> if family_text == old_family_text : <EOL> output ( u'<STR_LIT>' ) <EOL> elif test_data ( family_text ) : <EOL> output ( u'<STR_LIT>' ) <EOL> family_file = open ( family_file_name , '<STR_LIT:w>' ) <EOL> family_file . write ( family_text ) <EOL> family_file . close ( ) <EOL> else : <EOL> output ( u'<STR_LIT>' ) <EOL> output ( family_text . decode ( '<STR_LIT:utf-8>' ) ) <EOL> def escape_string ( string ) : <EOL> return "<STR_LIT>" % string . replace ( '<STR_LIT:\\>' , '<STR_LIT>' ) . replace ( "<STR_LIT:'>" , "<STR_LIT>" ) <EOL> def test_data ( _test_data ) : <EOL> try : <EOL> exec _test_data <EOL> except SyntaxError : <EOL> return False <EOL> except : <EOL> return True <EOL> return True <EOL> def check_and_update ( families , update_main = False ) : <EOL> for family in families : <EOL> family = wikipedia . Family ( family ) <EOL> result = family_check . check_family ( family ) <EOL> update_family ( family , result ) <EOL> if update_main : <EOL> update_family ( None , result ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> try : <EOL> update_main_family = False <EOL> update_wikimedia = False <EOL> for arg in wikipedia . handleArgs ( ) : <EOL> if arg == '<STR_LIT>' : <EOL> update_main_family = True <EOL> elif arg == '<STR_LIT>' : <EOL> update_wikimedia = True <EOL> if update_wikimedia : <EOL> check_and_update ( [ '<STR_LIT>' ] , True ) <EOL> families = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:test>' <EOL> ] <EOL> update_main_family = False <EOL> else : <EOL> families = [ wikipedia . default_family ] <EOL> check_and_update ( families , update_main_family ) <EOL> finally : <EOL> wikipedia . stopme ( ) </s>
