<s> import cPickle as pickle <EOL> from optparse import OptionParser <EOL> import os <EOL> import re <EOL> import sys <EOL> try : <EOL> from xml . etree . ElementTree import parse <EOL> except ImportError : <EOL> from elementtree . ElementTree import parse <EOL> sys . path . insert ( <NUM_LIT:0> , os . path . join ( os . path . dirname ( sys . argv [ <NUM_LIT:0> ] ) , '<STR_LIT:..>' ) ) <EOL> from babel import dates , numbers <EOL> from babel . plural import PluralRule <EOL> from babel . localedata import Alias <EOL> weekdays = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : <NUM_LIT:4> , '<STR_LIT>' : <NUM_LIT:5> , <EOL> '<STR_LIT>' : <NUM_LIT:6> } <EOL> try : <EOL> any <EOL> except NameError : <EOL> def any ( iterable ) : <EOL> return filter ( None , list ( iterable ) ) <EOL> def _text ( elem ) : <EOL> buf = [ elem . text or '<STR_LIT>' ] <EOL> for child in elem : <EOL> buf . append ( _text ( child ) ) <EOL> buf . append ( elem . tail or '<STR_LIT>' ) <EOL> return u'<STR_LIT>' . join ( filter ( None , buf ) ) . strip ( ) <EOL> NAME_RE = re . compile ( r"<STR_LIT>" ) <EOL> TYPE_ATTR_RE = re . compile ( r"<STR_LIT>" ) <EOL> NAME_MAP = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> def _translate_alias ( ctxt , path ) : <EOL> parts = path . split ( '<STR_LIT:/>' ) <EOL> keys = ctxt [ : ] <EOL> for part in parts : <EOL> if part == '<STR_LIT:..>' : <EOL> keys . pop ( ) <EOL> else : <EOL> match = TYPE_ATTR_RE . match ( part ) <EOL> if match : <EOL> keys . append ( match . group ( <NUM_LIT:1> ) ) <EOL> else : <EOL> assert NAME_RE . match ( part ) <EOL> keys . append ( NAME_MAP . get ( part , part ) ) <EOL> return keys <EOL> def main ( ) : <EOL> parser = OptionParser ( usage = '<STR_LIT>' ) <EOL> options , args = parser . parse_args ( ) <EOL> if len ( args ) != <NUM_LIT:1> : <EOL> parser . error ( '<STR_LIT>' ) <EOL> srcdir = args [ <NUM_LIT:0> ] <EOL> destdir = os . path . join ( os . path . dirname ( os . path . abspath ( sys . argv [ <NUM_LIT:0> ] ) ) , <EOL> '<STR_LIT:..>' , '<STR_LIT>' ) <EOL> sup = parse ( os . path . join ( srcdir , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> global_data = { } <EOL> territory_zones = global_data . setdefault ( '<STR_LIT>' , { } ) <EOL> zone_aliases = global_data . setdefault ( '<STR_LIT>' , { } ) <EOL> zone_territories = global_data . setdefault ( '<STR_LIT>' , { } ) <EOL> for elem in sup . findall ( '<STR_LIT>' ) : <EOL> tzid = elem . attrib [ '<STR_LIT:type>' ] <EOL> territory_zones . setdefault ( elem . attrib [ '<STR_LIT>' ] , [ ] ) . append ( tzid ) <EOL> zone_territories [ tzid ] = elem . attrib [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in elem . attrib : <EOL> for alias in elem . attrib [ '<STR_LIT>' ] . split ( ) : <EOL> zone_aliases [ alias ] = tzid <EOL> meta_zones = global_data . setdefault ( '<STR_LIT>' , { } ) <EOL> tzsup = parse ( os . path . join ( srcdir , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> for elem in tzsup . findall ( '<STR_LIT>' ) : <EOL> for child in elem . findall ( '<STR_LIT>' ) : <EOL> if '<STR_LIT:to>' not in child . attrib : <EOL> meta_zones [ elem . attrib [ '<STR_LIT:type>' ] ] = child . attrib [ '<STR_LIT>' ] <EOL> outfile = open ( os . path . join ( destdir , '<STR_LIT>' ) , '<STR_LIT:wb>' ) <EOL> try : <EOL> pickle . dump ( global_data , outfile , <NUM_LIT:2> ) <EOL> finally : <EOL> outfile . close ( ) <EOL> regions = { } <EOL> for elem in sup . findall ( '<STR_LIT>' ) : <EOL> regions [ elem . attrib [ '<STR_LIT:type>' ] ] = elem . attrib [ '<STR_LIT>' ] . split ( ) <EOL> territory_containment = { } <EOL> region_items = regions . items ( ) <EOL> region_items . sort ( ) <EOL> for group , territory_list in region_items : <EOL> for territory in territory_list : <EOL> containers = territory_containment . setdefault ( territory , set ( [ ] ) ) <EOL> if group in territory_containment : <EOL> containers |= territory_containment [ group ] <EOL> containers . add ( group ) <EOL> plural_rules = { } <EOL> prsup = parse ( os . path . join ( srcdir , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> for elem in prsup . findall ( '<STR_LIT>' ) : <EOL> rules = [ ] <EOL> for rule in elem . findall ( '<STR_LIT>' ) : <EOL> rules . append ( ( rule . attrib [ '<STR_LIT:count>' ] , unicode ( rule . text ) ) ) <EOL> pr = PluralRule ( rules ) <EOL> for locale in elem . attrib [ '<STR_LIT>' ] . split ( ) : <EOL> plural_rules [ locale ] = pr <EOL> filenames = os . listdir ( os . path . join ( srcdir , '<STR_LIT>' ) ) <EOL> filenames . remove ( '<STR_LIT>' ) <EOL> filenames . sort ( lambda a , b : len ( a ) - len ( b ) ) <EOL> filenames . insert ( <NUM_LIT:0> , '<STR_LIT>' ) <EOL> for filename in filenames : <EOL> stem , ext = os . path . splitext ( filename ) <EOL> if ext != '<STR_LIT>' : <EOL> continue <EOL> print >> sys . stderr , '<STR_LIT>' % filename <EOL> tree = parse ( os . path . join ( srcdir , '<STR_LIT>' , filename ) ) <EOL> data = { } <EOL> language = None <EOL> elem = tree . find ( '<STR_LIT>' ) <EOL> if elem is not None : <EOL> language = elem . attrib [ '<STR_LIT:type>' ] <EOL> print >> sys . stderr , '<STR_LIT>' % language <EOL> territory = None <EOL> elem = tree . find ( '<STR_LIT>' ) <EOL> if elem is not None : <EOL> territory = elem . attrib [ '<STR_LIT:type>' ] <EOL> else : <EOL> territory = '<STR_LIT>' <EOL> print >> sys . stderr , '<STR_LIT>' % territory <EOL> regions = territory_containment . get ( territory , [ ] ) <EOL> print >> sys . stderr , '<STR_LIT>' % regions <EOL> locale_id = '<STR_LIT:_>' . join ( filter ( None , [ <EOL> language , <EOL> territory != '<STR_LIT>' and territory or None <EOL> ] ) ) <EOL> if locale_id in plural_rules : <EOL> data [ '<STR_LIT>' ] = plural_rules [ locale_id ] <EOL> territories = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for elem in tree . findall ( '<STR_LIT>' ) : <EOL> if ( '<STR_LIT>' in elem . attrib or '<STR_LIT>' in elem . attrib ) and elem . attrib [ '<STR_LIT:type>' ] in territories : <EOL> continue <EOL> territories [ elem . attrib [ '<STR_LIT:type>' ] ] = _text ( elem ) <EOL> languages = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for elem in tree . findall ( '<STR_LIT>' ) : <EOL> if ( '<STR_LIT>' in elem . attrib or '<STR_LIT>' in elem . attrib ) and elem . attrib [ '<STR_LIT:type>' ] in languages : <EOL> continue <EOL> languages [ elem . attrib [ '<STR_LIT:type>' ] ] = _text ( elem ) <EOL> variants = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for elem in tree . findall ( '<STR_LIT>' ) : <EOL> if ( '<STR_LIT>' in elem . attrib or '<STR_LIT>' in elem . attrib ) and elem . attrib [ '<STR_LIT:type>' ] in variants : <EOL> continue <EOL> variants [ elem . attrib [ '<STR_LIT:type>' ] ] = _text ( elem ) <EOL> scripts = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for elem in tree . findall ( '<STR_LIT>' ) : <EOL> if ( '<STR_LIT>' in elem . attrib or '<STR_LIT>' in elem . attrib ) and elem . attrib [ '<STR_LIT:type>' ] in scripts : <EOL> continue <EOL> scripts [ elem . attrib [ '<STR_LIT:type>' ] ] = _text ( elem ) <EOL> week_data = data . setdefault ( '<STR_LIT>' , { } ) <EOL> supelem = sup . find ( '<STR_LIT>' ) <EOL> for elem in supelem . findall ( '<STR_LIT>' ) : <EOL> territories = elem . attrib [ '<STR_LIT>' ] . split ( ) <EOL> if territory in territories or any ( [ r in territories for r in regions ] ) : <EOL> week_data [ '<STR_LIT>' ] = int ( elem . attrib [ '<STR_LIT:count>' ] ) <EOL> for elem in supelem . findall ( '<STR_LIT>' ) : <EOL> territories = elem . attrib [ '<STR_LIT>' ] . split ( ) <EOL> if territory in territories or any ( [ r in territories for r in regions ] ) : <EOL> week_data [ '<STR_LIT>' ] = weekdays [ elem . attrib [ '<STR_LIT>' ] ] <EOL> for elem in supelem . findall ( '<STR_LIT>' ) : <EOL> territories = elem . attrib [ '<STR_LIT>' ] . split ( ) <EOL> if territory in territories or any ( [ r in territories for r in regions ] ) : <EOL> week_data [ '<STR_LIT>' ] = weekdays [ elem . attrib [ '<STR_LIT>' ] ] <EOL> for elem in supelem . findall ( '<STR_LIT>' ) : <EOL> territories = elem . attrib [ '<STR_LIT>' ] . split ( ) <EOL> if territory in territories or any ( [ r in territories for r in regions ] ) : <EOL> week_data [ '<STR_LIT>' ] = weekdays [ elem . attrib [ '<STR_LIT>' ] ] <EOL> zone_formats = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for elem in tree . findall ( '<STR_LIT>' ) : <EOL> if '<STR_LIT>' not in elem . attrib and '<STR_LIT>' not in elem . attrib : <EOL> zone_formats [ '<STR_LIT>' ] = unicode ( elem . text ) . replace ( '<STR_LIT>' , '<STR_LIT:%s>' ) <EOL> break <EOL> for elem in tree . findall ( '<STR_LIT>' ) : <EOL> if '<STR_LIT>' not in elem . attrib and '<STR_LIT>' not in elem . attrib : <EOL> zone_formats [ '<STR_LIT>' ] = unicode ( elem . text ) . replace ( '<STR_LIT>' , '<STR_LIT:%s>' ) <EOL> break <EOL> for elem in tree . findall ( '<STR_LIT>' ) : <EOL> if '<STR_LIT>' not in elem . attrib and '<STR_LIT>' not in elem . attrib : <EOL> zone_formats [ '<STR_LIT>' ] = unicode ( elem . text ) . replace ( '<STR_LIT>' , '<STR_LIT>' ) . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> break <EOL> time_zones = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for elem in tree . findall ( '<STR_LIT>' ) : <EOL> info = { } <EOL> city = elem . findtext ( '<STR_LIT>' ) <EOL> if city : <EOL> info [ '<STR_LIT>' ] = unicode ( city ) <EOL> for child in elem . findall ( '<STR_LIT>' ) : <EOL> info . setdefault ( '<STR_LIT>' , { } ) [ child . tag ] = unicode ( child . text ) <EOL> for child in elem . findall ( '<STR_LIT>' ) : <EOL> info . setdefault ( '<STR_LIT>' , { } ) [ child . tag ] = unicode ( child . text ) <EOL> time_zones [ elem . attrib [ '<STR_LIT:type>' ] ] = info <EOL> meta_zones = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for elem in tree . findall ( '<STR_LIT>' ) : <EOL> info = { } <EOL> city = elem . findtext ( '<STR_LIT>' ) <EOL> if city : <EOL> info [ '<STR_LIT>' ] = unicode ( city ) <EOL> for child in elem . findall ( '<STR_LIT>' ) : <EOL> info . setdefault ( '<STR_LIT>' , { } ) [ child . tag ] = unicode ( child . text ) <EOL> for child in elem . findall ( '<STR_LIT>' ) : <EOL> info . setdefault ( '<STR_LIT>' , { } ) [ child . tag ] = unicode ( child . text ) <EOL> info [ '<STR_LIT>' ] = elem . findtext ( '<STR_LIT>' ) == '<STR_LIT:true>' <EOL> meta_zones [ elem . attrib [ '<STR_LIT:type>' ] ] = info <EOL> for calendar in tree . findall ( '<STR_LIT>' ) : <EOL> if calendar . attrib [ '<STR_LIT:type>' ] != '<STR_LIT>' : <EOL> continue <EOL> months = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for ctxt in calendar . findall ( '<STR_LIT>' ) : <EOL> ctxt_type = ctxt . attrib [ '<STR_LIT:type>' ] <EOL> ctxts = months . setdefault ( ctxt_type , { } ) <EOL> for width in ctxt . findall ( '<STR_LIT>' ) : <EOL> width_type = width . attrib [ '<STR_LIT:type>' ] <EOL> widths = ctxts . setdefault ( width_type , { } ) <EOL> for elem in width . getiterator ( ) : <EOL> if elem . tag == '<STR_LIT>' : <EOL> if ( '<STR_LIT>' in elem . attrib or '<STR_LIT>' in elem . attrib ) and int ( elem . attrib [ '<STR_LIT:type>' ] ) in widths : <EOL> continue <EOL> widths [ int ( elem . attrib . get ( '<STR_LIT:type>' ) ) ] = unicode ( elem . text ) <EOL> elif elem . tag == '<STR_LIT>' : <EOL> ctxts [ width_type ] = Alias ( <EOL> _translate_alias ( [ '<STR_LIT>' , ctxt_type , width_type ] , <EOL> elem . attrib [ '<STR_LIT:path>' ] ) <EOL> ) <EOL> days = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for ctxt in calendar . findall ( '<STR_LIT>' ) : <EOL> ctxt_type = ctxt . attrib [ '<STR_LIT:type>' ] <EOL> ctxts = days . setdefault ( ctxt_type , { } ) <EOL> for width in ctxt . findall ( '<STR_LIT>' ) : <EOL> width_type = width . attrib [ '<STR_LIT:type>' ] <EOL> widths = ctxts . setdefault ( width_type , { } ) <EOL> for elem in width . getiterator ( ) : <EOL> if elem . tag == '<STR_LIT>' : <EOL> dtype = weekdays [ elem . attrib [ '<STR_LIT:type>' ] ] <EOL> if ( '<STR_LIT>' in elem . attrib or '<STR_LIT>' not in elem . attrib ) and dtype in widths : <EOL> continue <EOL> widths [ dtype ] = unicode ( elem . text ) <EOL> elif elem . tag == '<STR_LIT>' : <EOL> ctxts [ width_type ] = Alias ( <EOL> _translate_alias ( [ '<STR_LIT>' , ctxt_type , width_type ] , <EOL> elem . attrib [ '<STR_LIT:path>' ] ) <EOL> ) <EOL> quarters = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for ctxt in calendar . findall ( '<STR_LIT>' ) : <EOL> ctxt_type = ctxt . attrib [ '<STR_LIT:type>' ] <EOL> ctxts = quarters . setdefault ( ctxt . attrib [ '<STR_LIT:type>' ] , { } ) <EOL> for width in ctxt . findall ( '<STR_LIT>' ) : <EOL> width_type = width . attrib [ '<STR_LIT:type>' ] <EOL> widths = ctxts . setdefault ( width_type , { } ) <EOL> for elem in width . getiterator ( ) : <EOL> if elem . tag == '<STR_LIT>' : <EOL> if ( '<STR_LIT>' in elem . attrib or '<STR_LIT>' in elem . attrib ) and int ( elem . attrib [ '<STR_LIT:type>' ] ) in widths : <EOL> continue <EOL> widths [ int ( elem . attrib [ '<STR_LIT:type>' ] ) ] = unicode ( elem . text ) <EOL> elif elem . tag == '<STR_LIT>' : <EOL> ctxts [ width_type ] = Alias ( <EOL> _translate_alias ( [ '<STR_LIT>' , ctxt_type , width_type ] , <EOL> elem . attrib [ '<STR_LIT:path>' ] ) <EOL> ) <EOL> eras = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for width in calendar . findall ( '<STR_LIT>' ) : <EOL> width_type = NAME_MAP [ width . tag ] <EOL> widths = eras . setdefault ( width_type , { } ) <EOL> for elem in width . getiterator ( ) : <EOL> if elem . tag == '<STR_LIT>' : <EOL> if ( '<STR_LIT>' in elem . attrib or '<STR_LIT>' in elem . attrib ) and int ( elem . attrib [ '<STR_LIT:type>' ] ) in widths : <EOL> continue <EOL> widths [ int ( elem . attrib . get ( '<STR_LIT:type>' ) ) ] = unicode ( elem . text ) <EOL> elif elem . tag == '<STR_LIT>' : <EOL> eras [ width_type ] = Alias ( <EOL> _translate_alias ( [ '<STR_LIT>' , width_type ] , <EOL> elem . attrib [ '<STR_LIT:path>' ] ) <EOL> ) <EOL> periods = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for elem in calendar . findall ( '<STR_LIT>' ) : <EOL> if ( '<STR_LIT>' in elem . attrib or '<STR_LIT>' in elem . attrib ) and elem . tag in periods : <EOL> continue <EOL> periods [ elem . tag ] = unicode ( elem . text ) <EOL> for elem in calendar . findall ( '<STR_LIT>' ) : <EOL> if ( '<STR_LIT>' in elem . attrib or '<STR_LIT>' in elem . attrib ) and elem . tag in periods : <EOL> continue <EOL> periods [ elem . tag ] = unicode ( elem . text ) <EOL> date_formats = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for format in calendar . findall ( '<STR_LIT>' ) : <EOL> for elem in format . getiterator ( ) : <EOL> if elem . tag == '<STR_LIT>' : <EOL> if '<STR_LIT>' in elem . attrib and elem . attrib . get ( '<STR_LIT:type>' ) in date_formats : <EOL> continue <EOL> try : <EOL> date_formats [ elem . attrib . get ( '<STR_LIT:type>' ) ] = dates . parse_pattern ( unicode ( elem . findtext ( '<STR_LIT>' ) ) ) <EOL> except ValueError , e : <EOL> print >> sys . stderr , '<STR_LIT>' % e <EOL> elif elem . tag == '<STR_LIT>' : <EOL> date_formats = Alias ( _translate_alias ( <EOL> [ '<STR_LIT>' ] , elem . attrib [ '<STR_LIT:path>' ] ) <EOL> ) <EOL> time_formats = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for format in calendar . findall ( '<STR_LIT>' ) : <EOL> for elem in format . getiterator ( ) : <EOL> if elem . tag == '<STR_LIT>' : <EOL> if ( '<STR_LIT>' in elem . attrib or '<STR_LIT>' in elem . attrib ) and elem . attrib . get ( '<STR_LIT:type>' ) in time_formats : <EOL> continue <EOL> try : <EOL> time_formats [ elem . attrib . get ( '<STR_LIT:type>' ) ] = dates . parse_pattern ( unicode ( elem . findtext ( '<STR_LIT>' ) ) ) <EOL> except ValueError , e : <EOL> print >> sys . stderr , '<STR_LIT>' % e <EOL> elif elem . tag == '<STR_LIT>' : <EOL> time_formats = Alias ( _translate_alias ( <EOL> [ '<STR_LIT>' ] , elem . attrib [ '<STR_LIT:path>' ] ) <EOL> ) <EOL> datetime_formats = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for format in calendar . findall ( '<STR_LIT>' ) : <EOL> for elem in format . getiterator ( ) : <EOL> if elem . tag == '<STR_LIT>' : <EOL> if ( '<STR_LIT>' in elem . attrib or '<STR_LIT>' in elem . attrib ) and elem . attrib . get ( '<STR_LIT:type>' ) in datetime_formats : <EOL> continue <EOL> try : <EOL> datetime_formats [ elem . attrib . get ( '<STR_LIT:type>' ) ] = unicode ( elem . findtext ( '<STR_LIT>' ) ) <EOL> except ValueError , e : <EOL> print >> sys . stderr , '<STR_LIT>' % e <EOL> elif elem . tag == '<STR_LIT>' : <EOL> datetime_formats = Alias ( _translate_alias ( <EOL> [ '<STR_LIT>' ] , elem . attrib [ '<STR_LIT:path>' ] ) <EOL> ) <EOL> number_symbols = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for elem in tree . findall ( '<STR_LIT>' ) : <EOL> if ( '<STR_LIT>' in elem . attrib or '<STR_LIT>' in elem . attrib ) : <EOL> continue <EOL> number_symbols [ elem . tag ] = unicode ( elem . text ) <EOL> decimal_formats = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for elem in tree . findall ( '<STR_LIT>' ) : <EOL> if ( '<STR_LIT>' in elem . attrib or '<STR_LIT>' in elem . attrib ) and elem . attrib . get ( '<STR_LIT:type>' ) in decimal_formats : <EOL> continue <EOL> pattern = unicode ( elem . findtext ( '<STR_LIT>' ) ) <EOL> decimal_formats [ elem . attrib . get ( '<STR_LIT:type>' ) ] = numbers . parse_pattern ( pattern ) <EOL> scientific_formats = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for elem in tree . findall ( '<STR_LIT>' ) : <EOL> if ( '<STR_LIT>' in elem . attrib or '<STR_LIT>' in elem . attrib ) and elem . attrib . get ( '<STR_LIT:type>' ) in scientific_formats : <EOL> continue <EOL> pattern = unicode ( elem . findtext ( '<STR_LIT>' ) ) <EOL> scientific_formats [ elem . attrib . get ( '<STR_LIT:type>' ) ] = numbers . parse_pattern ( pattern ) <EOL> currency_formats = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for elem in tree . findall ( '<STR_LIT>' ) : <EOL> if ( '<STR_LIT>' in elem . attrib or '<STR_LIT>' in elem . attrib ) and elem . attrib . get ( '<STR_LIT:type>' ) in currency_formats : <EOL> continue <EOL> pattern = unicode ( elem . findtext ( '<STR_LIT>' ) ) <EOL> currency_formats [ elem . attrib . get ( '<STR_LIT:type>' ) ] = numbers . parse_pattern ( pattern ) <EOL> percent_formats = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for elem in tree . findall ( '<STR_LIT>' ) : <EOL> if ( '<STR_LIT>' in elem . attrib or '<STR_LIT>' in elem . attrib ) and elem . attrib . get ( '<STR_LIT:type>' ) in percent_formats : <EOL> continue <EOL> pattern = unicode ( elem . findtext ( '<STR_LIT>' ) ) <EOL> percent_formats [ elem . attrib . get ( '<STR_LIT:type>' ) ] = numbers . parse_pattern ( pattern ) <EOL> currency_names = data . setdefault ( '<STR_LIT>' , { } ) <EOL> currency_symbols = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for elem in tree . findall ( '<STR_LIT>' ) : <EOL> code = elem . attrib [ '<STR_LIT:type>' ] <EOL> for name in elem . findall ( '<STR_LIT>' ) : <EOL> if ( '<STR_LIT>' in name . attrib or '<STR_LIT:count>' in name . attrib ) and code in currency_names : <EOL> continue <EOL> currency_names [ code ] = unicode ( name . text ) <EOL> symbol = elem . find ( '<STR_LIT>' ) <EOL> if symbol is not None and '<STR_LIT>' not in symbol . attrib and '<STR_LIT>' not in symbol . attrib : <EOL> currency_symbols [ code ] = unicode ( symbol . text ) <EOL> unit_patterns = data . setdefault ( '<STR_LIT>' , { } ) <EOL> for elem in tree . findall ( '<STR_LIT>' ) : <EOL> unit_type = elem . attrib [ '<STR_LIT:type>' ] <EOL> unit_pattern = unit_patterns . setdefault ( unit_type , { } ) <EOL> for pattern in elem . findall ( '<STR_LIT>' ) : <EOL> unit_patterns [ unit_type ] [ pattern . attrib [ '<STR_LIT:count>' ] ] = unicode ( pattern . text ) <EOL> outfile = open ( os . path . join ( destdir , '<STR_LIT>' , stem + '<STR_LIT>' ) , '<STR_LIT:wb>' ) <EOL> try : <EOL> pickle . dump ( data , outfile , <NUM_LIT:2> ) <EOL> finally : <EOL> outfile . close ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
