Mercurial > babel > old > babel-test
annotate scripts/import_cldr.py @ 31:b6ff3e4b43e5
Raise error on unsupported locales. Closes #5.
author | cmlenz |
---|---|
date | Mon, 04 Jun 2007 11:29:55 +0000 |
parents | 11278622ede9 |
children | 0740b6d31799 |
rev | line source |
---|---|
1 | 1 #!/usr/bin/env python |
2 # -*- coding: utf-8 -*- | |
3 # | |
4 # Copyright (C) 2007 Edgewall Software | |
5 # All rights reserved. | |
6 # | |
7 # This software is licensed as described in the file COPYING, which | |
8 # you should have received as part of this distribution. The terms | |
9 # are also available at http://babel.edgewall.org/wiki/License. | |
10 # | |
11 # This software consists of voluntary contributions made by many | |
12 # individuals. For the exact contribution history, see the revision | |
13 # history and logs, available at http://babel.edgewall.org/log/. | |
14 | |
15 import copy | |
16 from optparse import OptionParser | |
17 import os | |
18 import pickle | |
19 import sys | |
20 try: | |
21 from xml.etree.ElementTree import parse | |
22 except ImportError: | |
23 from elementtree.ElementTree import parse | |
24 | |
9 | 25 from babel import dates, numbers |
1 | 26 |
15 | 27 weekdays = {'mon': 0, 'tue': 1, 'wed': 2, 'thu': 3, 'fri': 4, 'sat': 5, |
28 'sun': 6} | |
8
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
29 |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
30 try: |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
31 any |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
32 except NameError: |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
33 def any(iterable): |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
34 return filter(None, list(iterable)) |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
35 |
1 | 36 def _text(elem): |
37 buf = [elem.text or ''] | |
38 for child in elem: | |
39 buf.append(_text(child)) | |
40 buf.append(elem.tail or '') | |
41 return u''.join(filter(None, buf)).strip() | |
42 | |
43 def main(): | |
44 parser = OptionParser(usage='%prog path/to/cldr') | |
45 options, args = parser.parse_args() | |
46 if len(args) != 1: | |
47 parser.error('incorrect number of arguments') | |
48 | |
49 srcdir = args[0] | |
50 destdir = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), | |
51 '..', 'babel', 'localedata') | |
52 | |
8
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
53 sup = parse(os.path.join(srcdir, 'supplemental', 'supplementalData.xml')) |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
54 |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
55 # build a territory containment mapping for inheritance |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
56 regions = {} |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
57 for elem in sup.findall('//territoryContainment/group'): |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
58 regions[elem.attrib['type']] = elem.attrib['contains'].split() |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
59 |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
60 # Resolve territory containment |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
61 territory_containment = {} |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
62 region_items = regions.items() |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
63 region_items.sort() |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
64 for group, territory_list in region_items: |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
65 for territory in territory_list: |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
66 containers = territory_containment.setdefault(territory, set([])) |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
67 if group in territory_containment: |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
68 containers |= territory_containment[group] |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
69 containers.add(group) |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
70 |
1 | 71 filenames = os.listdir(os.path.join(srcdir, 'main')) |
72 filenames.remove('root.xml') | |
73 filenames.sort(lambda a,b: len(a)-len(b)) | |
74 filenames.insert(0, 'root.xml') | |
75 | |
76 dicts = {} | |
77 | |
78 for filename in filenames: | |
79 print>>sys.stderr, 'Processing input file %r' % filename | |
80 stem, ext = os.path.splitext(filename) | |
81 if ext != '.xml': | |
82 continue | |
83 | |
26
710090104678
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
22
diff
changeset
|
84 tree = parse(os.path.join(srcdir, 'main', filename)) |
1 | 85 data = {} |
86 | |
8
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
87 language = None |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
88 elem = tree.find('//identity/language') |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
89 if elem is not None: |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
90 language = elem.attrib['type'] |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
91 print>>sys.stderr, ' Language: %r' % language |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
92 |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
93 territory = None |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
94 elem = tree.find('//identity/territory') |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
95 if elem is not None: |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
96 territory = elem.attrib['type'] |
13 | 97 else: |
98 territory = '001' # world | |
8
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
99 print>>sys.stderr, ' Territory: %r' % territory |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
100 regions = territory_containment.get(territory, []) |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
101 print>>sys.stderr, ' Regions: %r' % regions |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
102 |
1 | 103 # <localeDisplayNames> |
104 | |
105 territories = data.setdefault('territories', {}) | |
106 for elem in tree.findall('//territories/territory'): | |
107 if 'draft' in elem.attrib and elem.attrib['type'] in territories: | |
108 continue | |
109 territories[elem.attrib['type']] = _text(elem) | |
110 | |
111 languages = data.setdefault('languages', {}) | |
112 for elem in tree.findall('//languages/language'): | |
113 if 'draft' in elem.attrib and elem.attrib['type'] in languages: | |
114 continue | |
115 languages[elem.attrib['type']] = _text(elem) | |
116 | |
117 variants = data.setdefault('variants', {}) | |
118 for elem in tree.findall('//variants/variant'): | |
119 if 'draft' in elem.attrib and elem.attrib['type'] in variants: | |
120 continue | |
121 variants[elem.attrib['type']] = _text(elem) | |
122 | |
123 scripts = data.setdefault('scripts', {}) | |
124 for elem in tree.findall('//scripts/script'): | |
125 if 'draft' in elem.attrib and elem.attrib['type'] in scripts: | |
126 continue | |
127 scripts[elem.attrib['type']] = _text(elem) | |
128 | |
129 # <dates> | |
130 | |
8
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
131 week_data = data.setdefault('week_data', {}) |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
132 supelem = sup.find('//weekData') |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
133 |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
134 for elem in supelem.findall('minDays'): |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
135 territories = elem.attrib['territories'].split() |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
136 if territory in territories or any([r in territories for r in regions]): |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
137 week_data['min_days'] = int(elem.attrib['count']) |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
138 |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
139 for elem in supelem.findall('firstDay'): |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
140 territories = elem.attrib['territories'].split() |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
141 if territory in territories or any([r in territories for r in regions]): |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
142 week_data['first_day'] = weekdays[elem.attrib['day']] |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
143 |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
144 for elem in supelem.findall('weekendStart'): |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
145 territories = elem.attrib['territories'].split() |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
146 if territory in territories or any([r in territories for r in regions]): |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
147 week_data['weekend_start'] = weekdays[elem.attrib['day']] |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
148 |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
149 for elem in supelem.findall('weekendEnd'): |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
150 territories = elem.attrib['territories'].split() |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
151 if territory in territories or any([r in territories for r in regions]): |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
152 week_data['weekend_end'] = weekdays[elem.attrib['day']] |
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
153 |
1 | 154 time_zones = data.setdefault('time_zones', {}) |
155 for elem in tree.findall('//timeZoneNames/zone'): | |
28
11278622ede9
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
26
diff
changeset
|
156 info = {} |
11278622ede9
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
26
diff
changeset
|
157 city = elem.findtext('exemplarCity') |
11278622ede9
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
26
diff
changeset
|
158 if city: |
11278622ede9
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
26
diff
changeset
|
159 info['city'] = unicode(city) |
11278622ede9
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
26
diff
changeset
|
160 for child in elem.findall('long/*'): |
11278622ede9
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
26
diff
changeset
|
161 info.setdefault('long', {})[child.tag] = unicode(child.text) |
11278622ede9
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
26
diff
changeset
|
162 for child in elem.findall('short/*'): |
11278622ede9
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
26
diff
changeset
|
163 info.setdefault('short', {})[child.tag] = unicode(child.text) |
11278622ede9
Import basic timezone info from CLDR (see #3). Still missing a couple other pieces in the puzzle.
cmlenz
parents:
26
diff
changeset
|
164 time_zones[elem.attrib['type']] = info |
1 | 165 |
166 for calendar in tree.findall('//calendars/calendar'): | |
167 if calendar.attrib['type'] != 'gregorian': | |
168 # TODO: support other calendar types | |
169 continue | |
170 | |
171 months = data.setdefault('months', {}) | |
172 for ctxt in calendar.findall('months/monthContext'): | |
173 ctxts = months.setdefault(ctxt.attrib['type'], {}) | |
174 for width in ctxt.findall('monthWidth'): | |
175 widths = ctxts.setdefault(width.attrib['type'], {}) | |
176 for elem in width.findall('month'): | |
177 if 'draft' in elem.attrib and int(elem.attrib['type']) in widths: | |
178 continue | |
179 widths[int(elem.attrib.get('type'))] = unicode(elem.text) | |
180 | |
181 days = data.setdefault('days', {}) | |
182 for ctxt in calendar.findall('days/dayContext'): | |
183 ctxts = days.setdefault(ctxt.attrib['type'], {}) | |
184 for width in ctxt.findall('dayWidth'): | |
185 widths = ctxts.setdefault(width.attrib['type'], {}) | |
186 for elem in width.findall('day'): | |
8
9132c9218745
Pull in some supplemental data from the CLDR, for things like the first day of the week.
cmlenz
parents:
1
diff
changeset
|
187 dtype = weekdays[elem.attrib['type']] |
1 | 188 if 'draft' in elem.attrib and dtype in widths: |
189 continue | |
190 widths[dtype] = unicode(elem.text) | |
191 | |
192 quarters = data.setdefault('quarters', {}) | |
193 for ctxt in calendar.findall('quarters/quarterContext'): | |
194 ctxts = quarters.setdefault(ctxt.attrib['type'], {}) | |
195 for width in ctxt.findall('quarterWidth'): | |
196 widths = ctxts.setdefault(width.attrib['type'], {}) | |
197 for elem in width.findall('quarter'): | |
198 if 'draft' in elem.attrib and int(elem.attrib['type']) in widths: | |
199 continue | |
200 widths[int(elem.attrib.get('type'))] = unicode(elem.text) | |
201 | |
202 eras = data.setdefault('eras', {}) | |
203 for width in calendar.findall('eras/*'): | |
204 ewidth = {'eraNames': 'wide', 'eraAbbr': 'abbreviated'}[width.tag] | |
205 widths = eras.setdefault(ewidth, {}) | |
206 for elem in width.findall('era'): | |
207 if 'draft' in elem.attrib and int(elem.attrib['type']) in widths: | |
208 continue | |
209 widths[int(elem.attrib.get('type'))] = unicode(elem.text) | |
210 | |
211 # AM/PM | |
212 periods = data.setdefault('periods', {}) | |
213 for elem in calendar.findall('am'): | |
214 if 'draft' in elem.attrib and elem.tag in periods: | |
215 continue | |
216 periods[elem.tag] = unicode(elem.text) | |
217 for elem in calendar.findall('pm'): | |
218 if 'draft' in elem.attrib and elem.tag in periods: | |
219 continue | |
220 periods[elem.tag] = unicode(elem.text) | |
221 | |
222 date_formats = data.setdefault('date_formats', {}) | |
223 for elem in calendar.findall('dateFormats/dateFormatLength'): | |
224 if 'draft' in elem.attrib and elem.attrib.get('type') in date_formats: | |
225 continue | |
226 try: | |
227 date_formats[elem.attrib.get('type')] = \ | |
9 | 228 dates.parse_pattern(unicode(elem.findtext('dateFormat/pattern'))) |
1 | 229 except ValueError, e: |
26
710090104678
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
22
diff
changeset
|
230 print>>sys.stderr, 'ERROR: %s' % e |
1 | 231 |
232 time_formats = data.setdefault('time_formats', {}) | |
233 for elem in calendar.findall('timeFormats/timeFormatLength'): | |
234 if 'draft' in elem.attrib and elem.attrib.get('type') in time_formats: | |
235 continue | |
236 try: | |
237 time_formats[elem.attrib.get('type')] = \ | |
9 | 238 dates.parse_pattern(unicode(elem.findtext('timeFormat/pattern'))) |
1 | 239 except ValueError, e: |
26
710090104678
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
22
diff
changeset
|
240 print>>sys.stderr, 'ERROR: %s' % e |
1 | 241 |
242 # <numbers> | |
243 | |
244 number_symbols = data.setdefault('number_symbols', {}) | |
245 for elem in tree.findall('//numbers/symbols/*'): | |
246 number_symbols[elem.tag] = unicode(elem.text) | |
247 | |
248 decimal_formats = data.setdefault('decimal_formats', {}) | |
249 for elem in tree.findall('//decimalFormats/decimalFormatLength'): | |
250 if 'draft' in elem.attrib and elem.attrib.get('type') in decimal_formats: | |
251 continue | |
26
710090104678
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
22
diff
changeset
|
252 pattern = unicode(elem.findtext('decimalFormat/pattern')) |
710090104678
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
22
diff
changeset
|
253 decimal_formats[elem.attrib.get('type')] = numbers.parse_pattern(pattern) |
1 | 254 |
255 scientific_formats = data.setdefault('scientific_formats', {}) | |
256 for elem in tree.findall('//scientificFormats/scientificFormatLength'): | |
257 if 'draft' in elem.attrib and elem.attrib.get('type') in scientific_formats: | |
258 continue | |
26
710090104678
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
22
diff
changeset
|
259 # FIXME: should use numbers.parse_pattern |
1 | 260 scientific_formats[elem.attrib.get('type')] = unicode(elem.findtext('scientificFormat/pattern')) |
261 | |
262 currency_formats = data.setdefault('currency_formats', {}) | |
263 for elem in tree.findall('//currencyFormats/currencyFormatLength'): | |
264 if 'draft' in elem.attrib and elem.attrib.get('type') in currency_formats: | |
265 continue | |
26
710090104678
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
22
diff
changeset
|
266 # FIXME: should use numbers.parse_pattern |
1 | 267 currency_formats[elem.attrib.get('type')] = unicode(elem.findtext('currencyFormat/pattern')) |
268 | |
269 percent_formats = data.setdefault('percent_formats', {}) | |
270 for elem in tree.findall('//percentFormats/percentFormatLength'): | |
271 if 'draft' in elem.attrib and elem.attrib.get('type') in percent_formats: | |
272 continue | |
26
710090104678
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
22
diff
changeset
|
273 pattern = unicode(elem.findtext('percentFormat/pattern')) |
710090104678
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
22
diff
changeset
|
274 percent_formats[elem.attrib.get('type')] = numbers.parse_pattern(pattern) |
1 | 275 |
26
710090104678
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
22
diff
changeset
|
276 currency_names = data.setdefault('currency_names', {}) |
710090104678
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
22
diff
changeset
|
277 currency_symbols = data.setdefault('currency_symbols', {}) |
1 | 278 for elem in tree.findall('//currencies/currency'): |
26
710090104678
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
22
diff
changeset
|
279 name = elem.findtext('displayName') |
710090104678
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
22
diff
changeset
|
280 if name: |
710090104678
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
22
diff
changeset
|
281 currency_names[elem.attrib['type']] = unicode(name) |
710090104678
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
22
diff
changeset
|
282 symbol = elem.findtext('symbol') |
710090104678
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
22
diff
changeset
|
283 if symbol: |
710090104678
* Reduce size of locale data pickles by only storing the data provided by each locale itself, and merging inherited data at runtime.
cmlenz
parents:
22
diff
changeset
|
284 currency_symbols[elem.attrib['type']] = unicode(symbol) |
1 | 285 |
286 dicts[stem] = data | |
287 outfile = open(os.path.join(destdir, stem + '.dat'), 'wb') | |
288 try: | |
289 pickle.dump(data, outfile, 2) | |
290 finally: | |
291 outfile.close() | |
292 | |
293 if __name__ == '__main__': | |
294 main() |