forked from Freely-Given-org/BibleOrgSys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LDML.py
executable file
·3894 lines (3793 loc) · 334 KB
/
LDML.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# LDML.py
#
# Module handling Unicode LOCALE DATA MARKUP LANGUAGE (XML) files
#
# Copyright (C) 2017 Robert Hunt
# Author: Robert Hunt <Freely.Given.org@gmail.com>
# License: See gpl-3.0.txt
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Module handling / reading Unicode LDML XML files.
LDML = Locale Data Markup Language (see http://unicode.org/reports/tr35/tr35-4.html)
The XML data file is loaded into a Python dictionary and made available in
that form.
This module (and most of the Bible Organisational System / BOS modules that
load XML files) do it quite manually and quite pedantically. Although
this makes what could be simple code quite long, it does allow us to
be alerted if/when the file format (which we have no control over) is
modified or extended.
Note that this module is not developed from the specification above,
but rather from loading a large range of actual data files.
Like all of the BOS file-loading modules, this code aims to be quite
fault-tolerant, except when the strictCheckingFlag is set,
in which case it should halt on any errors.
The module is tested on LDML files from the SIL NRSI SLDR Github repository
at https://github.com/silnrsi/sldr
CLDR stands for Common Locale Data Repository.
NOTE: This preliminary module currently parses a range of XML files
but does not yet store the parsed data in many cases.
"""
from gettext import gettext as _
LastModifiedDate = '2019-05-28' # by RJH
ShortProgName = "LDML_Handler"
ProgName = "Unicode LOCALE DATA MARKUP LANGUAGE handler"
ProgVersion = '0.13'
ProgNameVersion = '{} v{}'.format( ShortProgName, ProgVersion )
ProgNameVersionDate = '{} {} {}'.format( ProgNameVersion, _("last modified"), LastModifiedDate )
debuggingThisModule = False
import sys, os, logging
from collections import OrderedDict
import multiprocessing
from xml.etree.ElementTree import ElementTree
import BibleOrgSysGlobals
DRAFT_VALUES = ( 'provisional', 'contributed', 'unconfirmed', 'approved',
'proposed', # 'proposed' is not in the Unicode standard but does occur in SIL sldr files
'generated', 'suspect' ) # Seems new ??? TODO: Check it out
def exp( messageString ):
"""
Expands the message string in debug mode.
Prepends the module name to a error or warning message string
if we are in debug mode.
Returns the new string.
"""
try: nameBit, errorBit = messageString.split( ': ', 1 )
except ValueError: nameBit, errorBit = '', messageString
if BibleOrgSysGlobals.debugFlag or debuggingThisModule:
nameBit = '{}{}{}'.format( ShortProgName, '.' if nameBit else '', nameBit )
return '{}{}'.format( nameBit+': ' if nameBit else '', errorBit )
# end of exp
def getFlagFromAttribute( attributeName, attributeValue ):
"""
Get a 'true' or 'false' string and convert to True/False.
"""
if attributeValue == 'true': return True
if attributeValue == 'false': return False
logging.error( _("Unexpected {} attribute value of {}").format( attributeName, attributeValue ) )
return attributeValue
# end of getFlagFromAttribute
def getFlagFromText( subelement ):
"""
Get a 'true' or 'false' string and convert to True/False.
"""
if subelement.text == 'true': return True
if subelement.text == 'false': return False
logging.error( _("Unexpected {} text value of {}").format( subelement.tag, subelement.text ) )
return subelement.text
# end of getFlagFromText
class LDMLFile:
"""
A class to load and validate the XML Unicode LOCALE DATA MARKUP LANGUAGE files.
"""
def __init__( self, givenFolderName, givenFilename ):
"""
"""
assert givenFolderName
assert givenFilename
assert givenFilename.endswith( '.ldml' ) or givenFilename.endswith( '.xml' )
self.givenFolderName, self.givenFilename = givenFolderName, givenFilename
self.filepath = os.path.join( givenFolderName, givenFilename )
if givenFilename.endswith( '.ldml' ): removeLength = 5
elif givenFilename.endswith( '.xml' ): removeLength = 4
else: removeLength = 0
self.languageCode = givenFilename[:-removeLength] # Remove the dot and the file-extension
# end of LDMLFile.__init__
def load( self ):
"""
Load the something.ldml file (which is an LDML file) and parse it into the dictionary PTXLanguages.
LDML = Locale Data Markup Language (see http://unicode.org/reports/tr35/tr35-4.html)
"""
if BibleOrgSysGlobals.debugFlag or BibleOrgSysGlobals.verbosityLevel > 2:
print( exp("load()") )
SIL_URN_Prefix = '{urn://www.sil.org/ldml/0.1}'
lenSILURNPrefix = len( SIL_URN_Prefix )
def removeSILPrefix( someText ):
"""
Remove the SIL URN which might be prefixed to the element tag.
"""
if someText and someText.startswith( SIL_URN_Prefix ): return someText[lenSILURNPrefix:]
return someText
# end of removeSILPrefix
def loadIdentity( element, elementLocation, identity ):
"""
Returns the updated dictionary.
"""
for subelement in element:
subelementLocation = subelement.tag + ' in ' + elementLocation
#print( " Processing {}…".format( subelementLocation ) )
BibleOrgSysGlobals.checkXMLNoTail( subelement, subelementLocation )
if subelement.tag == 'version':
BibleOrgSysGlobals.checkXMLNoText( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoSubelements( subelement, subelementLocation )
number = None
for attrib,value in subelement.items():
#print( "hereV6", attrib, value )
if attrib=='number': number = value
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
assert subelement.tag not in identity
identity[subelement.tag] = number
elif subelement.tag == 'generation':
BibleOrgSysGlobals.checkXMLNoText( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoSubelements( subelement, subelementLocation )
date = None
for attrib,value in subelement.items():
if attrib=='date': date = value
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
assert subelement.tag not in identity
identity[subelement.tag] = date
elif subelement.tag in ('language','territory'):
BibleOrgSysGlobals.checkXMLNoText( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoSubelements( subelement, subelementLocation )
lgType = lgCode = lgName = None
for attrib,value in subelement.items():
#print( "hereLorT6", attrib, value )
if attrib=='type': lgType = value
elif attrib=='code': lgCode = value
elif attrib=='name': lgName = value
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
if subelement.tag in identity: logging.critical("Losing lang/terr data here")
identity[subelement.tag] = lgType, lgCode, lgName
elif subelement.tag == 'script':
#BibleOrgSysGlobals.checkXMLNoText( subelement, subelementLocation )
# TODO: Losing text here
BibleOrgSysGlobals.checkXMLNoSubelements( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoTail( subelement, subelementLocation )
sName = sCode = sType = None
for attrib,value in subelement.items():
#print( "hereS6", attrib, value )
if attrib=='name': sName = value; assert sName in ('Latin','Arabic')
elif attrib=='code': sCode = value; assert sCode in ('Latn','Arab')
elif attrib=='type': sType = value # assert sType in ('Latn','Ethi','Cans','Deva') # Why in type??? Mistake???
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
if subelement.tag in identity: logging.critical("Losing script data here")
identity[subelement.tag] = (sName,sCode)
elif subelement.tag == 'variant':
BibleOrgSysGlobals.checkXMLNoText( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoSubelements( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoTail( subelement, subelementLocation )
vType = None
for attrib,value in subelement.items():
#print( "hereV6", attrib, value )
if attrib=='type': vType = value; assert vType in ('POSIX','VALENCIA','x-Lati-BF','x-Susu-002','x-kala')
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
assert subelement.tag not in identity
identity[subelement.tag] = vType
elif subelement.tag == 'special':
BibleOrgSysGlobals.checkXMLNoText( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoAttributes( subelement, subelementLocation )
for sub2element in subelement:
sub2elementLocation = sub2element.tag + ' in ' + subelementLocation
#if debuggingThisModule: print( " Processing {}…".format( sub2elementLocation ) )
BibleOrgSysGlobals.checkXMLNoText( sub2element, sub2elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub2element, sub2elementLocation )
BibleOrgSysGlobals.checkXMLNoSubelements( sub2element, sub2elementLocation )
windowsLCID = draft = source = sDefaultRegion = None
for attrib,value in sub2element.items():
#print( "hereSP", attrib, value )
if attrib=='windowsLCID': windowsLCID = value
elif attrib=='draft': draft = value; assert draft in DRAFT_VALUES
elif attrib=='source': source = value
elif attrib=='defaultRegion': sDefaultRegion = value
elif attrib=='uid': sUID = value; assert sUID=='dbl'
elif attrib=='usage': sUsage = value; assert sUsage=='unused'
elif attrib=='alt': sAlt = value; assert sAlt=='proposed-dbl'
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub2elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
assert subelement.tag not in identity
identity[subelement.tag] = {'tag':sub2element.tag,'windowsLCID':windowsLCID,'draft':draft,'source':source}
else:
logging.error( _("Unprocessed {!r} subelement ({}) in {}").format( subelement.tag, subelement.text.strip() if subelement.text else subelement.text, elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
return identity
# end of loadIdentity
def loadContacts( element, elementLocation, contacts ):
"""
Returns the updated dictionary.
"""
for subelement in element:
subelementLocation = subelement.tag + ' in ' + elementLocation
#if debuggingThisModule: print( " Processing {}…".format( subelementLocation ) )
BibleOrgSysGlobals.checkXMLNoText( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoSubelements( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoTail( subelement, subelementLocation )
if subelement.tag == 'contact':
cName = cEmail = None
for attrib,value in subelement.items():
#print( "hereC1", attrib, value )
if attrib=='name': cName = value
elif attrib=='email': cEmail = value
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
assert cName not in contacts
contacts[cName] = cEmail
else:
logging.error( _("Unprocessed {!r} subelement ({}) in {}").format( subelement.tag, subelement.text.strip() if subelement.text else subelement.text, elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
return contacts
# end of loadContacts
def loadComments( element, elementLocation, comments ):
"""
Returns the updated dictionary.
"""
for subelement in element:
subelementLocation = subelement.tag + ' in ' + elementLocation
#if debuggingThisModule: print( " Processing {}…".format( subelementLocation ) )
BibleOrgSysGlobals.checkXMLNoText( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoSubelements( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoTail( subelement, subelementLocation )
if subelement.tag == 'entry':
cDate = cName = cComment = None
for attrib,value in subelement.items():
#print( "hereC2", attrib, value )
if attrib=='date': cDate = value
elif attrib=='name': cName = value
elif attrib=='comment': cComment = value
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
assert cDate not in comments # Note: comment date might not be unique ???
comments[cDate] = (cName,cComment)
else:
logging.error( _("Unprocessed {!r} subelement ({}) in {}").format( subelement.tag, subelement.text.strip() if subelement.text else subelement.text, elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
return comments
# end of loadComments
def loadStatus( element, elementLocation, status ):
"""
Returns the updated dictionary.
"""
sValue = None
for attrib,value in element.items():
#print( "hereSt2", attrib, value )
if attrib=='value': sValue = value
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
assert element.tag not in status
status[element.tag] = sValue
return status
# end of loadStatus
def loadCharacters( element, elementLocation, characters ):
"""
Returns the updated dictionary.
"""
for subelement in element:
subelementLocation = subelement.tag + ' in ' + elementLocation
#print( " ProcessingCharacters {}…".format( subelementLocation ) )
BibleOrgSysGlobals.checkXMLNoTail( subelement, subelementLocation )
if subelement.tag == 'exemplarCharacters':
BibleOrgSysGlobals.checkXMLNoSubelements( subelement, subelementLocation )
ecType = ecDraft = None
for attrib,value in subelement.items():
#print( 'ECattrib', attrib, repr(value) )
# TODO: Check if 'numbers' is an error
if attrib=='type': ecType = value; assert ecType in ('auxiliary','index','digits','punctuation','numbers')
elif attrib=='draft': ecDraft = value; assert ecDraft in DRAFT_VALUES
elif attrib=='alt': ecAlt = value; assert ecAlt=='proposed-dbl'
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
if subelement.tag not in characters:
characters[subelement.tag] = []
characters[subelement.tag].append( (ecType,subelement.text) )
elif subelement.tag == 'ellipsis':
BibleOrgSysGlobals.checkXMLNoSubelements( subelement, subelementLocation )
eType = eDraft = None
for attrib,value in subelement.items():
#print( 'attribE2', attrib, repr(value) )
if attrib=='type': eType = value; assert eType in ('initial','medial','final','word-initial','word-medial','word-final')
elif attrib=='draft': eDraft = value; assert eDraft in DRAFT_VALUES
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
if subelement.tag not in characters:
characters[subelement.tag] = []
characters[subelement.tag].append( (eType,subelement.text) )
elif subelement.tag == 'special':
BibleOrgSysGlobals.checkXMLNoAttributes( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoText( subelement, subelementLocation )
assert subelement.tag not in characters
characters[subelement.tag] = {}
for sub2element in subelement:
sub2elementLocation = sub2element.tag + ' in ' + subelementLocation
#if debuggingThisModule: print( " Processing {}…".format( sub2elementLocation ) )
BibleOrgSysGlobals.checkXMLNoTail( sub2element, sub2elementLocation )
BibleOrgSysGlobals.checkXMLNoSubelements( sub2element, sub2elementLocation )
secType = None
for attrib,value in sub2element.items():
#print( "heref7", attrib, value )
if attrib=='type': secType = value
elif attrib=='draft': secDraft = value; assert secDraft in DRAFT_VALUES
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub2elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
if sub2element.tag not in characters[subelement.tag]:
characters[subelement.tag][sub2element.tag] = []
characters[subelement.tag][sub2element.tag].append( (secType,sub2element.text) )
elif subelement.tag == 'moreInformation':
BibleOrgSysGlobals.checkXMLNoSubelements( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoTail( subelement, subelementLocation )
miDraft = None
for attrib,value in subelement.items():
#print( "here7", attrib, value )
if attrib=='draft': miDraft = value; assert miDraft in DRAFT_VALUES
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, su2elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
assert subelement.tag not in characters
characters[subelement.tag] = subelement.text
elif subelement.tag == 'parseLenients':
BibleOrgSysGlobals.checkXMLNoText( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoTail( subelement, subelementLocation )
# TODO: Write this
else:
logging.error( _("Unprocessed {!r} subelement ({}) in {}").format( subelement.tag, subelement.text.strip() if subelement.text else subelement.text, elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
return characters
# end of loadCharacters
def loadDelimiters( element, elementLocation, delimiters ):
"""
Returns the updated dictionary.
"""
for subelement in element:
subelementLocation = subelement.tag + ' in ' + elementLocation
#if debuggingThisModule: print( " Processing {}…".format( subelementLocation ) )
BibleOrgSysGlobals.checkXMLNoTail( subelement, subelementLocation )
if subelement.tag in ('quotationStart','quotationEnd','alternateQuotationStart','alternateQuotationEnd'):
BibleOrgSysGlobals.checkXMLNoSubelements( subelement, subelementLocation )
qDraft = None
for attrib,value in subelement.items():
#print( "here9", attrib, value )
if attrib=='draft': qDraft = value; assert qDraft in DRAFT_VALUES
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
assert subelement.tag not in delimiters
delimiters[subelement.tag] = subelement.text
elif subelement.tag == 'special':
BibleOrgSysGlobals.checkXMLNoAttributes( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoText( subelement, subelementLocation )
assert subelement.tag not in delimiters
delimiters[subelement.tag] = OrderedDict()
for sub2element in subelement:
sub2elementLocation = sub2element.tag + ' in ' + subelementLocation
adjusted2Tag = removeSILPrefix( sub2element.tag )
#if debuggingThisModule: print( " Processing {}…".format( sub2elementLocation ) )
BibleOrgSysGlobals.checkXMLNoText( sub2element, sub2elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub2element, sub2elementLocation )
if adjusted2Tag not in delimiters:
delimiters[subelement.tag][adjusted2Tag] = {}
paraContinueType = None
for attrib,value in sub2element.items():
#print( "here9", attrib, value )
if attrib=='paraContinueType': paraContinueType = value
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub2elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
for sub3element in sub2element:
sub3elementLocation = sub3element.tag + ' in ' + sub2elementLocation
adjusted3Tag = removeSILPrefix( sub3element.tag )
#if debuggingThisModule: print( " Processing {}…".format( sub3elementLocation ) )
#BibleOrgSysGlobals.checkXMLNoText( sub3element, sub3elementLocation, "ABC" )
BibleOrgSysGlobals.checkXMLNoTail( sub3element, sub3elementLocation )
BibleOrgSysGlobals.checkXMLNoSubelements( sub3element, sub3elementLocation )
openA = close = level = paraClose = pattern = context = qContinue = qType = None
for attrib,value in sub3element.items():
#print( attrib, value )
if attrib=='open': openA = value
elif attrib=='close': close = value
elif attrib=='level':
level = value
if debuggingThisModule: assert level in '123'
elif attrib=='paraClose':
paraClose = value
if debuggingThisModule: assert paraClose in ('false',)
elif attrib=='pattern': pattern = value
elif attrib=='context':
context = value
if debuggingThisModule: assert context in ('medial','final')
elif attrib=='continue':
qContinue = value
elif attrib=='type':
qType = value
else:
logging.error( _("DS Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub3elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
if adjusted3Tag not in delimiters[subelement.tag][adjusted2Tag]:
delimiters[subelement.tag][adjusted2Tag][adjusted3Tag] = []
delimiters[subelement.tag][adjusted2Tag][adjusted3Tag] \
.append( (openA,close,level,paraClose,pattern,context,paraContinueType,qContinue,qType,sub3element.text) )
else:
logging.error( _("Unprocessed {!r} subelement ({}) in {}").format( subelement.tag, subelement.text.strip() if subelement.text else subelement.text, elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
#print( '\n', element.tag, LDMLData[element.tag] )
return delimiters
# end of loadDelimiters
def loadLayout( element, elementLocation, layout ):
"""
Returns the updated dictionary.
"""
for subelement in element:
subelementLocation = subelement.tag + ' in ' + elementLocation
#if debuggingThisModule: print( " Processing {}…".format( subelementLocation ) )
BibleOrgSysGlobals.checkXMLNoAttributes( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoText( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoTail( subelement, subelementLocation )
if subelement.tag == 'orientation':
assert subelement.tag not in layout
layout[subelement.tag] = {}
for sub2element in subelement:
sub2elementLocation = sub2element.tag + ' in ' + subelementLocation
#if debuggingThisModule: print( " Processing {}…".format( sub2elementLocation ) )
BibleOrgSysGlobals.checkXMLNoTail( sub2element, sub2elementLocation )
BibleOrgSysGlobals.checkXMLNoSubelements( sub2element, sub2elementLocation )
if sub2element.tag == 'orientation':
oLines = oCharacters = None
for attrib,value in sub2element.items():
if attrib=='lines': oLines = value; assert oLines in ('left-to-right',)
elif attrib=='characters': oCharacters = value; assert oCharacters in ('top-to-bottom',)
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub2elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
elif sub2element.tag in ('characterOrder','lineOrder','characters','lines'):
BibleOrgSysGlobals.checkXMLNoAttributes( sub2element, sub2elementLocation )
pass # Save data XXXXXXXXXXXXXXXXXXX
else:
logging.error( _("Unprocessed {!r} sub2element ({}) in {}").format( sub2element.tag, sub2element.text.strip() if sub2element.text else sub2element.text, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag: halt
assert sub2element.tag not in layout[subelement.tag]
layout[subelement.tag][sub2element.tag] = sub2element.text
else:
logging.error( _("Unprocessed {!r} subelement ({}) in {}").format( subelement.tag, subelement.text.strip() if subelement.text else subelement.text, elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
return layout
# end of loadLayout
def loadNumbers( element, elementLocation, numbers ):
"""
Returns the updated dictionary.
"""
currencies = {}
percentFormats = {}
decimalFormats = {}
miscPatterns = {}
otherNumberingSystems = {}
scientificFormats = {}
for subelement in element:
subelementLocation = subelement.tag + ' in ' + elementLocation
#print( " Processing {}…".format( subelementLocation ) )
BibleOrgSysGlobals.checkXMLNoTail( subelement, subelementLocation )
if subelement.tag == 'defaultNumberingSystem':
dnsDraft = None
for attrib,value in subelement.items():
print( "here dns1", attrib, value )
if attrib=='draft': dnsDraft = value; assert dnsDraft in DRAFT_VALUES
elif attrib=='alt': dnsAlt = value; assert dnsAlt=='latn'
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
if subelement.tag in numbers:logging.critical("Losing defaultNumberingSystem data here")
numbers[subelement.tag] = subelement.text
elif subelement.tag == 'numberingSystem': # Only in Paratext8 files
BibleOrgSysGlobals.checkXMLNoText( subelement, subelementLocation )
nID = digits = nType = None
for attrib,value in subelement.items():
if attrib=='id': nID = value
elif attrib=='digits': digits = value
elif attrib=='type': nType = value
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
assert subelement.tag not in numbers
numbers[subelement.tag] = (nID,digits,nType)
elif subelement.tag == 'symbols':
symbols = {}
BibleOrgSysGlobals.checkXMLNoText( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoTail( subelement, subelementLocation )
numberSystem = None
for attrib,value in subelement.items():
if attrib=='numberSystem': numberSystem = value
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
if numberSystem not in symbols:
symbols[numberSystem] = {}
for sub2element in subelement:
sub2elementLocation = sub2element.tag + ' in ' + subelementLocation
#if debuggingThisModule: print( " Processing {} ({})…".format( sub2elementLocation, sub2element.tag.strip() ) )
BibleOrgSysGlobals.checkXMLNoSubelements( sub2element, sub2elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub2element, sub2elementLocation )
sAlt = sDraft = sSource = sPath = None
for attrib,value in sub2element.items():
#print( "here dn2", attrib, value )
if attrib=='alt': sAlt = value; assert sAlt in ('variant',)
elif attrib=='draft': sDraft = value; assert sDraft in DRAFT_VALUES
elif attrib=='source': sSource = value; assert sSource in ('locale',)
elif attrib=='path': sPath = value # This is a relative path
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub2elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
if sub2element.tag not in symbols[numberSystem]:
symbols[numberSystem][sub2element.tag] = sub2element.text
if symbols:
#print( "symbols", symbols, subelement.tag )
#assert subelement.tag not in numbers # losing data here XXXXXXXXXXXXXXXXXXXXXXX
if subelement.tag in numbers: logging.critical( "Losing data here for {!r} numbers field".format( subelement.tag ) )
numbers[subelement.tag] = symbols
elif subelement.tag == 'currencyFormats':
currencyFormats = {}
BibleOrgSysGlobals.checkXMLNoText( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoTail( subelement, subelementLocation )
numberSystem = None
for attrib,value in subelement.items():
if attrib=='numberSystem': numberSystem = value
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
if numberSystem not in currencyFormats:
currencyFormats[numberSystem] = {}
for sub2element in subelement:
sub2elementLocation = sub2element.tag + ' in ' + subelementLocation
#if debuggingThisModule: print( " Processing {} ({})…".format( sub2elementLocation, sub2element.tag.strip() ) )
BibleOrgSysGlobals.checkXMLNoTail( sub2element, sub2elementLocation )
#if sub2element.tag not in currencyFormats[numberSystem]:
#currencyFormats[numberSystem][sub2element.tag] = sub2element.text
if sub2element.tag == 'currencyFormatLength':
BibleOrgSysGlobals.checkXMLNoText( sub2element, sub2elementLocation )
cflType = alt = None
for attrib,value in sub2element.items():
if attrib=='type': cflType = value; assert cflType in ('short',)
#elif attrib=='alt': alt = value
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub2elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
for sub3element in sub2element:
sub3elementLocation = sub3element.tag + ' in ' + sub2elementLocation
#if debuggingThisModule: print( " Processing {} ({})…".format( sub3elementLocation, sub3element.text.strip() ) )
BibleOrgSysGlobals.checkXMLNoText( sub3element, sub3elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub3element, sub3elementLocation )
if sub3element.tag == 'currencyFormat':
draft = cfType = alt = None
for attrib,value in sub3element.items():
if attrib=='type': cfType = value
#elif attrib=='alt': alt = value
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub3elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
for sub4element in sub3element:
sub4elementLocation = sub4element.tag + ' in ' + sub3elementLocation
#if debuggingThisModule: print( " ProcessingCF {} ({})…".format( sub4elementLocation, sub4element.text.strip() if sub4element.text else sub4element.text ) )
BibleOrgSysGlobals.checkXMLNoSubelements( sub4element, sub4elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub4element, sub4elementLocation )
if sub4element.tag == 'pattern':
pType = pCount = pDraft = None
for attrib,value in sub4element.items():
#print( "here CF-T7", attrib, value )
if attrib=='type': pType = value # assert pType in ('1000','10000')
elif attrib=='count': pCount = value; assert pCount in ('zero','one','two','other','few','many')
elif attrib=='draft': pDraft = value; assert pDraft in DRAFT_VALUES
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub4elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
pass # Save text XXXXX
elif sub4element.tag == 'alias':
BibleOrgSysGlobals.checkXMLNoSubelements( sub4element, sub4elementLocation )
aSource = aPath = None
for attrib,value in sub4element.items():
#print( "hereA39", attrib, value )
if attrib=='source': aSource = value; assert aSource in ('locale',)
elif attrib=='path': aPath = value # aPath is a relative path
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub4elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
else:
logging.error( _("Unprocessed {!r} sub4element ({}) in {}").format( sub4element.tag, sub4element.text.strip() if sub4element.text else sub4element.text, sub3elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag: halt
else:
logging.error( _("Unprocessed {!r} sub3element ({}) in {}").format( sub3element.tag, sub3element.text.strip() if sub3element.text else sub3element.text, sub2elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag: halt
elif sub2element.tag == 'unitPattern':
BibleOrgSysGlobals.checkXMLNoSubelements( sub2element, sub2elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub2element, sub2elementLocation )
upCount = upDraft = None
for attrib,value in sub2element.items():
#print( "here UP7", attrib, value )
if attrib=='count': upCount = value; assert upCount in ('zero','one','two','other','few','many')
elif attrib=='draft': upDraft = value; assert upDraft in DRAFT_VALUES
#elif attrib=='alt': alt = value
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub2elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
pass # Save text XXXXXXXXXXXXXXXXXXXXXX
elif sub2element.tag == 'currencySpacing':
BibleOrgSysGlobals.checkXMLNoAttributes( sub2element, sub2elementLocation )
BibleOrgSysGlobals.checkXMLNoText( sub2element, sub2elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub2element, sub2elementLocation )
#upCount = upDraft = None
#for attrib,value in sub2element.items():
##print( "here UP7", attrib, value )
#if attrib=='count': upCount = value; assert upCount in ('zero','one','two','other','few','many')
#elif attrib=='draft': upDraft = value; assert upDraft in DRAFT_VALUES
##elif attrib=='alt': alt = value
#else:
#logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub2elementLocation ) )
#if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
for sub3element in sub2element:
sub3elementLocation = sub3element.tag + ' in ' + sub2elementLocation
#if debuggingThisModule: print( " ProcessingCS {} ({})…".format( sub3elementLocation, sub3element.text.strip() ) )
BibleOrgSysGlobals.checkXMLNoText( sub3element, sub3elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub3element, sub3elementLocation )
if sub3element.tag in ('beforeCurrency','afterCurrency'):
BibleOrgSysGlobals.checkXMLNoAttributes( sub3element, sub3elementLocation )
#draft = cfType = alt = None
#for attrib,value in sub3element.items():
#if attrib=='type': cfType = value
##elif attrib=='alt': alt = value
#else:
#logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub3elementLocation ) )
#if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
for sub4element in sub3element:
sub4elementLocation = sub4element.tag + ' in ' + sub3elementLocation
#if debuggingThisModule: print( " ProcessingBfC {} ({})…".format( sub4elementLocation, sub4element.text.strip() if sub4element.text else sub4element.text ) )
BibleOrgSysGlobals.checkXMLNoAttributes( sub4element, sub4elementLocation )
BibleOrgSysGlobals.checkXMLNoSubelements( sub4element, sub4elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub4element, sub4elementLocation )
if sub4element.tag in ('currencyMatch','surroundingMatch','insertBetween'):
#pType = pCount = pDraft = None
#for attrib,value in sub4element.items():
##print( "here CF-T7", attrib, value )
#if attrib=='type': pType = value # assert pType in ('1000','10000')
#elif attrib=='count': pCount = value; assert pCount in ('zero','one','two','other','few','many')
#elif attrib=='draft': pDraft = value; assert pDraft in DRAFT_VALUES
#else:
#logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub4elementLocation ) )
#if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
pass # Save text XXXXX
else:
logging.error( _("Unprocessed {!r} sub4element ({}) in {}").format( sub4element.tag, sub4element.text.strip() if sub4element.text else sub4element.text, sub3elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag: halt
elif sub3element.tag == 'alias':
BibleOrgSysGlobals.checkXMLNoText( sub3element, sub3elementLocation )
BibleOrgSysGlobals.checkXMLNoSubelements( sub3element, sub3elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub3element, sub3elementLocation )
aPath = aSource = None
for attrib,value in sub3element.items():
#print( "here A36", attrib, value )
if attrib=='path': aPath = value # This is a relative path
elif attrib=='source': aSource = value; assert aSource in ('locale',)
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub3elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
else:
logging.error( _("Unprocessed {!r} sub3element ({}) in {}").format( sub3element.tag, sub3element.text.strip() if sub3element.text else sub3element.text, sub2elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag: halt
pass # Save text XXXXXXXXXXXXXXXXXXXXXX
elif sub2element.tag == 'alias':
BibleOrgSysGlobals.checkXMLNoText( sub2element, sub2elementLocation )
BibleOrgSysGlobals.checkXMLNoSubelements( sub2element, sub2elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub2element, sub2elementLocation )
aPath = aSource = None
for attrib,value in sub2element.items():
#print( "here A40", attrib, value )
if attrib=='path': aPath = value # This is a relative path
elif attrib=='source': aSource = value; assert aSource in ('locale',)
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub2elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
else:
logging.error( _("Unprocessed {!r} sub2element ({}) in {}").format( sub2element.tag, sub2element.text.strip() if sub2element.text else sub2element.text, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag: halt
if currencyFormats:
#print( "currencyFormats", currencyFormats )
#assert subelement.tag not in numbers # losing data here XXXXXXXXXXXXXXXXXXXXXXX
if subelement.tag in numbers: logging.critical( "Losing data here for {!r} currencyFormats field".format( subelement.tag ) )
numbers[subelement.tag] = currencyFormats
elif subelement.tag == 'currencies':
BibleOrgSysGlobals.checkXMLNoAttributes( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoText( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoTail( subelement, subelementLocation )
for sub2element in subelement:
sub2elementLocation = sub2element.tag + ' in ' + subelementLocation
#if debuggingThisModule: print( " Processing {} ({})…".format( sub2elementLocation, sub2element.text.strip() ) )
BibleOrgSysGlobals.checkXMLNoText( sub2element, sub2elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub2element, sub2elementLocation )
if sub2element.tag == 'currency':
cuType = None
for attrib,value in sub2element.items():
if attrib=='type': cuType = value
#elif attrib=='alt': alt = value
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub2elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
#assert cuType not in currencies # XXXXXXXXXXXXXX losing some info here
if cuType in currencies: logging.critical( "Losing data here for {!r} currencies field".format( cuType ) )
currencies[cuType] = {}
for sub3element in sub2element:
sub3elementLocation = sub3element.tag + ' in ' + sub2elementLocation
#if debuggingThisModule: print( " Processing {} ({})…".format( sub3elementLocation, sub3element.text.strip() ) )
BibleOrgSysGlobals.checkXMLNoSubelements( sub3element, sub3elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub3element, sub3elementLocation )
displayNames = []
symbols = []
if sub3element.tag == 'displayName':
dnCount = dnDraft = None
for attrib,value in sub3element.items():
#print( "here dn2", attrib, value )
if attrib=='count': dnCount = value
elif attrib=='draft': dnDraft = value; assert dnDraft in DRAFT_VALUES
#elif attrib=='alt': alt = value
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub3elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
displayNames.append( (dnCount,sub3element.text) )
elif sub3element.tag == 'symbol':
sDraft = sAlt = None
for attrib,value in sub3element.items():
#print( "here S2", attrib, value )
if attrib=='draft': sDraft = value; assert sDraft in DRAFT_VALUES
elif attrib=='alt': sAlt = value; assert sAlt in ('variant','narrow','formal')
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub3elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
symbols.append( sub3element.text )
elif sub3element.tag in ('pattern','decimal','group'):
BibleOrgSysGlobals.checkXMLNoAttributes( sub3element, sub3elementLocation )
symbols.append( sub3element.text )
else:
logging.error( _("Unprocessed {!r} sub3element ({}) in {}").format( sub3element.tag, sub3element.text.strip() if sub3element.text else sub3element.text, sub2elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag: halt
if displayNames:
assert 'displayNames' not in currencies[cuType]
currencies[cuType]['displayNames']= displayNames
if symbols:
assert 'symbols' not in currencies[cuType]
currencies[cuType]['symbols']= symbols
else:
logging.error( _("Unprocessed {!r} sub2element ({}) in {}").format( sub2element.tag, sub2element.text.strip() if sub2element.text else sub2element.text, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag: halt
if currencies:
#print( "currencies", currencies )
assert subelement.tag not in numbers
numbers[subelement.tag] = currencies
elif subelement.tag == 'percentFormats':
BibleOrgSysGlobals.checkXMLNoText( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoTail( subelement, subelementLocation )
numberSystem = None
for attrib,value in subelement.items():
if attrib=='numberSystem': numberSystem = value
#elif attrib=='alt': alt = value
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
for sub2element in subelement:
sub2elementLocation = sub2element.tag + ' in ' + subelementLocation
#if debuggingThisModule: print( " Processing {} ({})…".format( sub2elementLocation, sub2element.text.strip() ) )
BibleOrgSysGlobals.checkXMLNoText( sub2element, sub2elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub2element, sub2elementLocation )
if sub2element.tag == 'percentFormat':
BibleOrgSysGlobals.checkXMLNoAttributes( sub2element, sub2elementLocation )
for sub3element in sub2element:
sub3elementLocation = sub3element.tag + ' in ' + sub2elementLocation
#if debuggingThisModule: print( " Processing {} ({})…".format( sub3elementLocation, sub3element.text.strip() ) )
BibleOrgSysGlobals.checkXMLNoSubelements( sub3element, sub3elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub3element, sub3elementLocation )
displayNames = []
symbols = []
if sub3element.tag == 'displayName':
dnCount = None
for attrib,value in sub3element.items():
if attrib=='count': dnCount = value
#elif attrib=='alt': alt = value
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub3elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
displayNames.append( (dnCount,sub3element.text) )
elif sub3element.tag == 'symbol':
BibleOrgSysGlobals.checkXMLNoAttributes( sub3element, sub3elementLocation )
symbols.append( sub3element.text )
else:
logging.error( _("Unprocessed {!r} sub3element ({}) in {}").format( sub3element.tag, sub3element.text.strip() if sub3element.text else sub3element.text, sub2elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag: halt
if displayNames:
assert 'displayNames' not in percentFormats[cuType]
percentFormats[cuType]['displayNames']= displayNames
if symbols:
assert 'symbols' not in percentFormats[cuType]
percentFormats[cuType]['symbols']= symbols
elif sub2element.tag == 'percentFormatLength':
BibleOrgSysGlobals.checkXMLNoAttributes( sub2element, sub2elementLocation )
for sub3element in sub2element:
sub3elementLocation = sub3element.tag + ' in ' + sub2elementLocation
#if debuggingThisModule: print( " Processing {} ({})…".format( sub3elementLocation, sub3element.text.strip() ) )
BibleOrgSysGlobals.checkXMLNoAttributes( sub3element, sub3elementLocation )
BibleOrgSysGlobals.checkXMLNoText( sub3element, sub3elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub3element, sub3elementLocation )
if sub3element.tag == 'percentFormat':
for sub4element in sub3element:
sub4elementLocation = sub4element.tag + ' in ' + sub3elementLocation
#if debuggingThisModule: print( " Processing {} ({})…".format( sub4elementLocation, sub4element.text.strip() if sub4element.text else sub4element.text ) )
BibleOrgSysGlobals.checkXMLNoSubelements( sub4element, sub4elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub4element, sub4elementLocation )
if sub4element.tag == 'pattern':
pDraft = None
for attrib,value in sub4element.items():
if attrib=='draft': pDraft = value; assert pDraft in DRAFT_VALUES
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub4elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
pass # Save text XXXXX
else:
logging.error( _("Unprocessed {!r} sub4element ({}) in {}").format( sub4element.tag, sub4element.text.strip() if sub4element.text else sub4element.text, sub3elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag: halt
else:
logging.error( _("Unprocessed {!r} sub3element ({}) in {}").format( sub3element.tag, sub3element.text.strip() if sub3element.text else sub3element.text, sub2elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag: halt
elif sub2element.tag == 'alias':
BibleOrgSysGlobals.checkXMLNoText( sub2element, sub2elementLocation )
BibleOrgSysGlobals.checkXMLNoSubelements( sub2element, sub2elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub2element, sub2elementLocation )
aPath = aSource = None
for attrib,value in sub2element.items():
#print( "here A35", attrib, value )
if attrib=='path': aPath = value # This is a relative path
elif attrib=='source': aSource = value; assert aSource in ('locale',)
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub2elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
else:
logging.error( _("Unprocessed {!r} sub2element ({}) in {}").format( sub2element.tag, sub2element.text.strip() if sub2element.text else sub2element.text, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag: halt
if percentFormats:
#print( "percentFormats", percentFormats )
assert subelement.tag not in numbers
numbers[subelement.tag] = percentFormats
elif subelement.tag == 'minimumGroupingDigits':
BibleOrgSysGlobals.checkXMLNoSubelements( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoTail( subelement, subelementLocation )
mgdDraft = None
for attrib,value in subelement.items():
if attrib=='draft': mgdDraft = value; assert mgdDraft in DRAFT_VALUES
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
pass # save text XXXXXXXXXXXXXXXXXXX
elif subelement.tag == 'decimalFormats':
BibleOrgSysGlobals.checkXMLNoText( subelement, subelementLocation )
BibleOrgSysGlobals.checkXMLNoTail( subelement, subelementLocation )
numberSystem = None
for attrib,value in subelement.items():
#print( "hereDF1", attrib, value )
if attrib=='numberSystem': numberSystem = value # assert numberSystem in ('latn','arab','arabext','fullwide')
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, subelementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
for sub2element in subelement:
sub2elementLocation = sub2element.tag + ' in ' + subelementLocation
#if debuggingThisModule: print( " Processing {} ({})…".format( sub2elementLocation, sub2element.text.strip() ) )
BibleOrgSysGlobals.checkXMLNoText( sub2element, sub2elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub2element, sub2elementLocation )
if sub2element.tag == 'decimalFormatLength':
dflType = None
for attrib,value in sub2element.items():
if attrib=='type': dflType = value
#elif attrib=='alt': alt = value
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub2elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
for sub3element in sub2element:
sub3elementLocation = sub3element.tag + ' in ' + sub2elementLocation
#if debuggingThisModule: print( " Processing {} ({})…".format( sub3elementLocation, sub3element.text.strip() ) )
BibleOrgSysGlobals.checkXMLNoText( sub3element, sub3elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub3element, sub3elementLocation )
if sub3element.tag == 'decimalFormat':
BibleOrgSysGlobals.checkXMLNoAttributes( sub3element, sub3elementLocation )
for sub4element in sub3element:
sub4elementLocation = sub4element.tag + ' in ' + sub3elementLocation
#if debuggingThisModule: print( " Processing {} ({})…".format( sub4elementLocation, sub4element.text.strip() if sub4element.text else sub4element.text ) )
BibleOrgSysGlobals.checkXMLNoSubelements( sub4element, sub4elementLocation )
BibleOrgSysGlobals.checkXMLNoTail( sub4element, sub4elementLocation )
if sub4element.tag == 'pattern':
pType = pCount = pDraft = None
for attrib,value in sub4element.items():
#print( "here DF-T7", attrib, value )
if attrib=='type': pType = value # assert pType in ('1000','10000')
elif attrib=='count': pCount = value; assert pCount in ('zero','one','two','other','few','many')
elif attrib=='draft': pDraft = value; assert pDraft in DRAFT_VALUES
else:
logging.error( _("Unprocessed {!r} attribute ({}) in {}").format( attrib, value, sub4elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag and BibleOrgSysGlobals.haltOnXMLWarning: halt
pass # Save text XXXXX
else:
logging.error( _("Unprocessed {!r} sub4element ({}) in {}").format( sub4element.tag, sub4element.text.strip() if sub4element.text else sub4element.text, sub3elementLocation ) )
if BibleOrgSysGlobals.strictCheckingFlag or BibleOrgSysGlobals.debugFlag: halt
elif sub3element.tag == 'xdecimalFormatLength':
BibleOrgSysGlobals.checkXMLNoAttributes( sub3element, sub3elementLocation )