Rename xsd_element into element_schema
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 07 Oct 2016 18:04:30 +0200
changeset 1628 9393d8e2702f
parent 1627 c88820fa450e
child 1634 c2ccf07bb418
Rename xsd_element into element_schema It's not xsd specific since it may be overriden to generate RNG. Name inspired from recently introduced 'attribute_schema'. Related to #15045341
entities/profile_generation.py
--- a/entities/profile_generation.py	Fri Oct 07 18:04:58 2016 +0200
+++ b/entities/profile_generation.py	Fri Oct 07 18:04:30 2016 +0200
@@ -792,8 +792,8 @@
 
     concepts_language = 'seda-1'
 
-    def xsd_element(self, parent, name, xsd_type=None, fixed_value=None, cardinality='1',
-                    documentation=None, xsd_attributes=()):
+    def element_schema(self, parent, name, xsd_type=None, fixed_value=None, cardinality='1',
+                       documentation=None, xsd_attributes=()):
         attributes = {'name': name}
         if fixed_value is not None:
             attributes['fixed'] = text_type(fixed_value)
@@ -845,36 +845,36 @@
 
     def xsd_transfer(self, parent, archive_transfer):
         """Append XSD elements for the archive transfer to the given parent node."""
-        transfer_node = self.xsd_element(parent, 'ArchiveTransfer',
-                                         documentation=archive_transfer.title,
-                                         xsd_attributes=[XAttr('Id', 'xsd:ID')])
+        transfer_node = self.element_schema(parent, 'ArchiveTransfer',
+                                            documentation=archive_transfer.title,
+                                            xsd_attributes=[XAttr('Id', 'xsd:ID')])
         for comment in archive_transfer.comments:
-            self.xsd_element(transfer_node, 'Comment', 'udt:TextType',
-                             fixed_value=comment.comment,
-                             cardinality=comment.user_cardinality,
-                             documentation=comment.user_annotation,
-                             xsd_attributes=[XAttr('languageID', 'xsd:language')])
-        self.xsd_element(transfer_node, 'Date', 'udt:DateTimeType')
-        self.xsd_element(transfer_node, 'TransferIdentifier', 'qdt:ArchivesIDType',
-                         xsd_attributes=self.xsd_attributes_scheme())
+            self.element_schema(transfer_node, 'Comment', 'udt:TextType',
+                                fixed_value=comment.comment,
+                                cardinality=comment.user_cardinality,
+                                documentation=comment.user_annotation,
+                                xsd_attributes=[XAttr('languageID', 'xsd:language')])
+        self.element_schema(transfer_node, 'Date', 'udt:DateTimeType')
+        self.element_schema(transfer_node, 'TransferIdentifier', 'qdt:ArchivesIDType',
+                            xsd_attributes=self.xsd_attributes_scheme())
         for archive_unit in archive_transfer.archive_units:
             self.xsd_archive(transfer_node, archive_unit)
 
     def xsd_archive(self, parent, archive_unit):
         """Append XSD elements for an archive to the given parent node."""
-        archive_node = self.xsd_element(parent, 'Archive',
-                                        cardinality=archive_unit.user_cardinality,
-                                        documentation=archive_unit.user_annotation,
-                                        xsd_attributes=[XAttr('Id', 'xsd:ID')])
+        archive_node = self.element_schema(parent, 'Archive',
+                                           cardinality=archive_unit.user_cardinality,
+                                           documentation=archive_unit.user_annotation,
+                                           xsd_attributes=[XAttr('Id', 'xsd:ID')])
         # hard-coded description's language XXX fine, content language may be specified
-        self.xsd_element(archive_node, 'DescriptionLanguage', 'qdt:CodeLanguageType',
-                         fixed_value='fra',
-                         xsd_attributes=[LIST_VERSION_ID_2011])
+        self.element_schema(archive_node, 'DescriptionLanguage', 'qdt:CodeLanguageType',
+                            fixed_value='fra',
+                            xsd_attributes=[LIST_VERSION_ID_2011])
         name_entity = self.archive_unit_name(archive_unit)
-        self.xsd_element(archive_node, 'Name', 'udt:TextType',
-                         fixed_value=name_entity.title,
-                         documentation=name_entity.user_annotation,
-                         xsd_attributes=[XAttr('languageID', 'xsd:language')])
+        self.element_schema(archive_node, 'Name', 'udt:TextType',
+                            fixed_value=name_entity.title,
+                            documentation=name_entity.user_annotation,
+                            xsd_attributes=[XAttr('languageID', 'xsd:language')])
         appraisal_rule_entity = self.archive_unit_appraisal_rule(archive_unit)
         if appraisal_rule_entity:
             self.xsd_appraisal_rule(archive_node, appraisal_rule_entity)
@@ -896,22 +896,22 @@
     def xsd_appraisal_rule(self, parent, appraisal_rule):
         # XXX cardinality 1 on rule, not multiple + element name : 'Appraisal' ou 'AppraisalRule'
         # (cf http://www.archivesdefrance.culture.gouv.fr/seda/api/index.html)
-        ar_node = self.xsd_element(parent, 'Appraisal',
-                                   cardinality=appraisal_rule.user_cardinality,
-                                   documentation=appraisal_rule.user_annotation,
-                                   xsd_attributes=[XAttr('Id', 'xsd:ID')])
+        ar_node = self.element_schema(parent, 'Appraisal',
+                                      cardinality=appraisal_rule.user_cardinality,
+                                      documentation=appraisal_rule.user_annotation,
+                                      xsd_attributes=[XAttr('Id', 'xsd:ID')])
         ar_code = appraisal_rule.final_action_concept
         ar_code_value = _concept_value(ar_code, self.concepts_language)
-        self.xsd_element(ar_node, 'Code', 'qdt:CodeAppraisalType',
-                         fixed_value=ar_code_value,
-                         xsd_attributes=[LIST_VERSION_ID_2009])
+        self.element_schema(ar_node, 'Code', 'qdt:CodeAppraisalType',
+                            fixed_value=ar_code_value,
+                            xsd_attributes=[LIST_VERSION_ID_2009])
 
         rule = appraisal_rule.rules[0] if appraisal_rule.rules else None
         value = _concept_value(rule.rule_concept, self.concepts_language) if rule else None
-        self.xsd_element(ar_node, 'Duration', 'qdt:ArchivesDurationType',
-                         fixed_value=value,
-                         documentation=rule.user_annotation if rule else None)
-        self.xsd_element(ar_node, 'StartDate', 'udt:DateType')
+        self.element_schema(ar_node, 'Duration', 'qdt:ArchivesDurationType',
+                            fixed_value=value,
+                            documentation=rule.user_annotation if rule else None)
+        self.element_schema(ar_node, 'StartDate', 'udt:DateType')
 
     def archive_unit_access_rule(self, archive_unit):
         seq = archive_unit.first_level_choice.content_sequence
@@ -921,18 +921,18 @@
 
     def xsd_access_rule(self, parent, access_rule):
         """Append XSD elements for an access restriction to the given parent node."""
-        ar_node = self.xsd_element(parent, self.access_restriction_tag_name,
-                                   cardinality=access_rule.user_cardinality,
-                                   documentation=access_rule.user_annotation,
-                                   xsd_attributes=[XAttr('Id', 'xsd:ID')])
+        ar_node = self.element_schema(parent, self.access_restriction_tag_name,
+                                      cardinality=access_rule.user_cardinality,
+                                      documentation=access_rule.user_annotation,
+                                      xsd_attributes=[XAttr('Id', 'xsd:ID')])
         # XXX cardinality 1
         rule = access_rule.rules[0] if access_rule.rules else None
         value = _concept_value(rule.rule_concept, self.concepts_language) if rule else None
-        self.xsd_element(ar_node, 'Code', 'qdt:CodeAccessRestrictionType',
-                         fixed_value=value,
-                         documentation=rule.user_annotation if rule else None,
-                         xsd_attributes=[LIST_VERSION_ID_2009])
-        self.xsd_element(ar_node, 'StartDate', 'udt:DateType')
+        self.element_schema(ar_node, 'Code', 'qdt:CodeAccessRestrictionType',
+                            fixed_value=value,
+                            documentation=rule.user_annotation if rule else None,
+                            xsd_attributes=[LIST_VERSION_ID_2009])
+        self.element_schema(ar_node, 'StartDate', 'udt:DateType')
 
     def archive_unit_content(self, archive_unit):
         seq = archive_unit.first_level_choice.content_sequence
@@ -940,18 +940,18 @@
 
     def xsd_content_description(self, parent, content):
         """Append XSD elements for a description content to the given parent node"""
-        cd_node = self.xsd_element(parent, 'ContentDescription',
-                                   # XXX should always be 1
-                                   # cardinality=content.user_cardinality,
-                                   documentation=content.user_annotation,
-                                   xsd_attributes=[XAttr('Id', 'xsd:ID')])
+        cd_node = self.element_schema(parent, 'ContentDescription',
+                                      # XXX should always be 1
+                                      # cardinality=content.user_cardinality,
+                                      documentation=content.user_annotation,
+                                      xsd_attributes=[XAttr('Id', 'xsd:ID')])
         self.xsd_description_level(cd_node, content.description_level_concept)
         for seda2_name, seda1_name in (('start', 'oldest'), ('end', 'latest')):
             date_entity = getattr(content, '%s_date' % seda2_name)
             if date_entity:
-                self.xsd_element(cd_node, '%sDate' % seda1_name.capitalize(), 'udt:DateType',
-                                 cardinality=date_entity.user_cardinality,
-                                 documentation=date_entity.user_annotation)
+                self.element_schema(cd_node, '%sDate' % seda1_name.capitalize(), 'udt:DateType',
+                                    cardinality=date_entity.user_cardinality,
+                                    documentation=date_entity.user_annotation)
         if content.description:
             self.xsd_description(cd_node, content.description)
         for keyword in content.keywords:
@@ -960,17 +960,17 @@
     def xsd_description_level(self, parent, concept):
         """Append XSD elements for a description level to the given parent node"""
         value = _concept_value(concept, self.concepts_language)
-        self.xsd_element(parent, 'DescriptionLevel', 'qdt:CodeDescriptionLevelType',
-                         fixed_value=value,
-                         xsd_attributes=[LIST_VERSION_ID_2009])
+        self.element_schema(parent, 'DescriptionLevel', 'qdt:CodeDescriptionLevelType',
+                            fixed_value=value,
+                            xsd_attributes=[LIST_VERSION_ID_2009])
 
     def xsd_description(self, parent, description):
         """Append XSD elements for a description to the given parent node"""
-        self.xsd_element(parent, 'Description', 'udt:TextType',
-                         cardinality=description.user_cardinality,
-                         documentation=description.user_annotation,
-                         fixed_value=description.description,
-                         xsd_attributes=[XAttr('languageID', 'xsd:language')])
+        self.element_schema(parent, 'Description', 'udt:TextType',
+                            cardinality=description.user_cardinality,
+                            documentation=description.user_annotation,
+                            fixed_value=description.description,
+                            xsd_attributes=[XAttr('languageID', 'xsd:language')])
 
     # extracted from xsd_keyword to allow parametrization for SEDA 1.0 vs 0.2 generation
     kw_tag_name = 'Keyword'
@@ -980,10 +980,10 @@
 
     def xsd_keyword(self, parent, keyword):
         """Append XSD elements for a keyword to the given parent node"""
-        kw_node = self.xsd_element(parent, self.kw_tag_name,
-                                   cardinality=keyword.user_cardinality,
-                                   documentation=keyword.user_annotation,
-                                   xsd_attributes=[XAttr('Id', 'xsd:ID')])
+        kw_node = self.element_schema(parent, self.kw_tag_name,
+                                      cardinality=keyword.user_cardinality,
+                                      documentation=keyword.user_annotation,
+                                      xsd_attributes=[XAttr('Id', 'xsd:ID')])
         content = keyword.content_string
         url = None
         if keyword.reference:
@@ -992,13 +992,13 @@
                 url = self.cwuri_url(concept)
                 if content is None:
                     content = concept.label()
-        self.xsd_element(kw_node, 'KeywordContent', self.kw_content_tag_type,
-                         fixed_value=content,
-                         xsd_attributes=self.kw_content_tag_attributes)
+        self.element_schema(kw_node, 'KeywordContent', self.kw_content_tag_type,
+                            fixed_value=content,
+                            xsd_attributes=self.kw_content_tag_attributes)
         scheme = keyword.reference.scheme if keyword.reference else None
-        self.xsd_element(kw_node, 'KeywordReference', 'qdt:ArchivesIDType',
-                         fixed_value=url,
-                         xsd_attributes=self.xsd_attributes_scheme(scheme))
+        self.element_schema(kw_node, 'KeywordReference', 'qdt:ArchivesIDType',
+                            fixed_value=url,
+                            xsd_attributes=self.xsd_attributes_scheme(scheme))
         # XXX keyword type
 
     def xsd_children(self, parent, entity):
@@ -1016,15 +1016,15 @@
 
     def xsd_archive_object(self, parent, archive_unit):
         """Append XSD elements for the archive object to the given parent node."""
-        ao_node = self.xsd_element(parent, self.archive_object_tag_name,
-                                   cardinality=archive_unit.user_cardinality,
-                                   documentation=archive_unit.user_annotation,
-                                   xsd_attributes=[XAttr('Id', 'xsd:ID')])
+        ao_node = self.element_schema(parent, self.archive_object_tag_name,
+                                      cardinality=archive_unit.user_cardinality,
+                                      documentation=archive_unit.user_annotation,
+                                      xsd_attributes=[XAttr('Id', 'xsd:ID')])
         content_entity = self.archive_unit_content(archive_unit)
-        self.xsd_element(ao_node, 'Name', 'udt:TextType',
-                         fixed_value=content_entity.title.title,
-                         documentation=content_entity.title.user_annotation,
-                         xsd_attributes=[XAttr('languageID', 'xsd:language')])
+        self.element_schema(ao_node, 'Name', 'udt:TextType',
+                            fixed_value=content_entity.title.title,
+                            documentation=content_entity.title.user_annotation,
+                            xsd_attributes=[XAttr('languageID', 'xsd:language')])
         appraisal_rule_entity = self.archive_unit_appraisal_rule(archive_unit)
         if appraisal_rule_entity:
             self.xsd_appraisal_rule(ao_node, appraisal_rule_entity)
@@ -1038,10 +1038,10 @@
 
     def xsd_document(self, parent, data_object):
         """Append XSD elements for the document to the given parent node."""
-        document_node = self.xsd_element(parent, 'Document',
-                                         cardinality=data_object.user_cardinality,
-                                         documentation=data_object.user_annotation,
-                                         xsd_attributes=[XAttr('Id', 'xsd:ID')])
+        document_node = self.element_schema(parent, 'Document',
+                                            cardinality=data_object.user_cardinality,
+                                            documentation=data_object.user_annotation,
+                                            xsd_attributes=[XAttr('Id', 'xsd:ID')])
 
         def safe_cardinality(entity):
             if entity is None:
@@ -1055,28 +1055,28 @@
 
         format_id = data_object.format_id
         encoding = data_object.encoding
-        self.xsd_element(document_node, 'Attachment', 'qdt:ArchivesBinaryObjectType',
-                         xsd_attributes=[
-                             XAttr('format', 'clmDAFFileTypeCode:FileTypeCodeType',
-                                   cardinality=safe_cardinality(format_id),
-                                   fixed_value=safe_concept_value(format_id)),
-                             XAttr('encodingCode',
-                                   'clm60133:CharacterSetEncodingCodeContentType',
-                                   cardinality=safe_cardinality(encoding),
-                                   fixed_value=safe_concept_value(encoding)),
-                             # hard-coded attributes
-                             XAttr('characterSetCode',
-                                   'clmIANACharacterSetCode:CharacterSetCodeContentType'),
-                             XAttr('mimeCode', 'clmIANAMIMEMediaType:MIMEMediaTypeContentType'),
-                             XAttr('uri', 'xsd:anyURI'),
-                             XAttr('filename', 'xsd:string'),
-                         ])
+        self.element_schema(document_node, 'Attachment', 'qdt:ArchivesBinaryObjectType',
+                            xsd_attributes=[
+                                XAttr('format', 'clmDAFFileTypeCode:FileTypeCodeType',
+                                      cardinality=safe_cardinality(format_id),
+                                      fixed_value=safe_concept_value(format_id)),
+                                XAttr('encodingCode',
+                                      'clm60133:CharacterSetEncodingCodeContentType',
+                                      cardinality=safe_cardinality(encoding),
+                                      fixed_value=safe_concept_value(encoding)),
+                                # hard-coded attributes
+                                XAttr('characterSetCode',
+                                      'clmIANACharacterSetCode:CharacterSetCodeContentType'),
+                                XAttr('mimeCode', 'clmIANAMIMEMediaType:MIMEMediaTypeContentType'),
+                                XAttr('uri', 'xsd:anyURI'),
+                                XAttr('filename', 'xsd:string'),
+                            ])
         references = list(data_object.referenced_by)
         assert len(references) == 1
         seq = references[0]
-        self.xsd_element(document_node, 'Type', 'qdt:CodeDocumentType',
-                         fixed_value=safe_concept_value(seq.contents[0].type),
-                         xsd_attributes=[LIST_VERSION_ID_2009])
+        self.element_schema(document_node, 'Type', 'qdt:CodeDocumentType',
+                            fixed_value=safe_concept_value(seq.contents[0].type),
+                            xsd_attributes=[LIST_VERSION_ID_2009])
         # if document.description:
         #     self.xsd_description(document_node, document.description)
 
@@ -1125,19 +1125,19 @@
 
     def xsd_archive(self, parent, archive_unit):
         """Append XSD elements for an archive to the given parent node."""
-        archive_node = self.xsd_element(parent, 'Contains',
-                                        cardinality=archive_unit.user_cardinality,
-                                        documentation=archive_unit.user_annotation,
-                                        xsd_attributes=[XAttr('Id', 'xsd:ID')])
+        archive_node = self.element_schema(parent, 'Contains',
+                                           cardinality=archive_unit.user_cardinality,
+                                           documentation=archive_unit.user_annotation,
+                                           xsd_attributes=[XAttr('Id', 'xsd:ID')])
         # hard-coded description's language
-        self.xsd_element(archive_node, 'DescriptionLanguage', 'qdt:CodeLanguageType',
-                         fixed_value='fr',
-                         xsd_attributes=[LIST_VERSION_ID_2009])
+        self.element_schema(archive_node, 'DescriptionLanguage', 'qdt:CodeLanguageType',
+                            fixed_value='fr',
+                            xsd_attributes=[LIST_VERSION_ID_2009])
         name_entity = self.archive_unit_name(archive_unit)
-        self.xsd_element(archive_node, 'Name', 'udt:TextType',
-                         fixed_value=name_entity.title,
-                         documentation=name_entity.user_annotation,
-                         xsd_attributes=[XAttr('languageID', 'xsd:language')])
+        self.element_schema(archive_node, 'Name', 'udt:TextType',
+                            fixed_value=name_entity.title,
+                            documentation=name_entity.user_annotation,
+                            xsd_attributes=[XAttr('languageID', 'xsd:language')])
         # in SEDA 0.2, description level is on the archive element, not on its content description
         content_entity = self.archive_unit_content(archive_unit)
         self.xsd_description_level(archive_node, content_entity.description_level_concept)
@@ -1156,23 +1156,23 @@
         """Append XSD elements for a description content to the given parent node"""
         if not (content.start_date or content.end_date or content.description or content.keywords):
             return
-        cd_node = self.xsd_element(parent, 'ContentDescription',
-                                   # XXX should always be 1
-                                   # cardinality=content_description.user_cardinality,
-                                   documentation=content.user_annotation,
-                                   xsd_attributes=[XAttr('Id', 'xsd:ID')])
+        cd_node = self.element_schema(parent, 'ContentDescription',
+                                      # XXX should always be 1
+                                      # cardinality=content_description.user_cardinality,
+                                      documentation=content.user_annotation,
+                                      xsd_attributes=[XAttr('Id', 'xsd:ID')])
         for seda2_name, seda1_name in (('start', 'oldest'), ('end', 'latest')):
             date_entity = getattr(content, '%s_date' % seda2_name)
             if date_entity:
-                self.xsd_element(cd_node, '%sDate' % seda1_name.capitalize(), 'udt:DateType',
-                                 cardinality=date_entity.user_cardinality,
-                                 documentation=date_entity.user_annotation)
+                self.element_schema(cd_node, '%sDate' % seda1_name.capitalize(), 'udt:DateType',
+                                    cardinality=date_entity.user_cardinality,
+                                    documentation=date_entity.user_annotation)
         if content.description:
             self.xsd_description(cd_node, content.description)
         # in SEDA 0.2, content description has a description language as well
-        self.xsd_element(cd_node, 'DescriptionLanguage', 'qdt:CodeLanguageType',
-                         fixed_value='fr',
-                         xsd_attributes=[LIST_VERSION_ID_2009])
+        self.element_schema(cd_node, 'DescriptionLanguage', 'qdt:CodeLanguageType',
+                            fixed_value='fr',
+                            xsd_attributes=[LIST_VERSION_ID_2009])
         for keyword in content.keywords:
             self.xsd_keyword(cd_node, keyword)
         # in SEDA 0.2, there may be some access restriction on the content description but it's on
@@ -1212,8 +1212,8 @@
         'datatypeLibrary': 'http://www.w3.org/2001/XMLSchema-datatypes',
     }
 
-    def xsd_element(self, parent, name, xsd_type=None, fixed_value=None, cardinality='1',
-                    documentation=None, xsd_attributes=()):
+    def element_schema(self, parent, name, xsd_type=None, fixed_value=None, cardinality='1',
+                       documentation=None, xsd_attributes=()):
         attributes = {'name': name}
         if documentation:
             attributes['documentation'] = documentation