예제 #1
0
 def l_linkbase_ref(self, e):
     href = e.get(f'{{{const.NS_XLINK}}}href')
     if not href.startswith('http'):
         href = util.reduce_url(
             os.path.join(self.base, href).replace('\\', '/'))
     self.linkbase_refs[href] = e
     self.pool.add_reference(href, self.base)
예제 #2
0
 def l_redirects(self, ce):
     for e in ce.iterchildren():
         if e.tag != f'{{{const.NS_OASIS_CATALOG}}}rewriteURI':
             continue
         url = e.attrib.get('uriStartString')
         rewrite_prefix = e.attrib.get('rewritePrefix')
         self.redirects[url] = rewrite_prefix
     # Reduce redirects according to position of catalog.xml
     self.redirects_reduced = dict([(u, util.reduce_url(os.path.join(self.catalog_location, r)))
                                    for u, r in self.redirects.items()])
예제 #3
0
 def __init__(self, e, container_xlink=None):
     self.xlink = container_xlink
     super().__init__(e)
     href = e.attrib.get(f'{{{const.NS_XLINK}}}href')
     if href.startswith('#'):
         href = f'{self.xlink.linkbase.location}{href}' if self.xlink else href
     elif href.startswith('..'):
         href = os.path.join(self.xlink.linkbase.base, href)
         href = href.replace('\\', '/')
     elif not href.startswith('http') and self.xlink is not None:
         href = os.path.join(self.xlink.linkbase.base, href)
         href = href.replace('\\', '/')
     self.href = util.reduce_url(href)
     self.label = e.attrib.get(f'{{{const.NS_XLINK}}}label')
     self.url = self.href[:self.href.find('#')]
     self.fragment_identifier = self.href[self.href.find('#') + 1:]
     if self.xlink is not None:
         self.xlink.locators[self.label] = self
         self.xlink.locators_by_href[self.href] = self
예제 #4
0
    def __init__(self, location, container_pool):
        self.target_namespace = ''
        self.target_namespace_prefix = ''
        parsers = {
            f'{{{const.NS_XS}}}schema': self.l_schema,
            f'{{{const.NS_XS}}}annotation': self.l_annotation,
            f'{{{const.NS_XS}}}appinfo': self.l_appinfo,
            f'{{{const.NS_LINK}}}linkbase': self.l_linkbase,
            f'{{{const.NS_XS}}}import': self.l_import,
            f'{{{const.NS_LINK}}}linkbaseRef': self.l_linkbase_ref,
            f'{{{const.NS_LINK}}}roleType': self.l_roletype,
            f'{{{const.NS_LINK}}}arcroleType': self.l_arcroletype,
            f'{{{const.NS_XS}}}element': self.l_element,
            f'{{{const.NS_XS}}}complexType': self.l_complex_type,
            f'{{{const.NS_XS}}}simpleType': self.l_complex_type,
        }
        self.imports = {}
        self.linkbase_refs = {}
        """ Elements, which are concepts """
        self.concepts = {}
        """ Elements, which are not concepts """
        self.elements = {}
        self.elements_by_id = {}
        """ Role types in the schema """
        self.role_types = {}
        """ Arcrole types in the schema """
        self.arcrole_types = {}
        """ Simple types """
        self.simple_types = {}
        """ Complex types with simple content """
        self.item_types = {}
        """ Complex types with complex content """
        self.tuple_types = {}

        self.pool = container_pool
        resolved_location = util.reduce_url(location)
        if self.pool is not None:
            self.pool.discovered[location] = True
        super().__init__(resolved_location, container_pool, parsers)
        if self.pool is not None:
            self.pool.schemas[resolved_location] = self
예제 #5
0
 def add_reference(self, href, base):
     """ Loads schema or linkbase depending on file type. TO IMPROVE!!! """
     allowed_extensions = ('xsd', 'xml', 'json')
     if not href.split('.')[-1] in allowed_extensions:  # if pairs in
         return
     if 'http://xbrl.org' in href or 'http://www.xbrl.org' in href:
         return  # Basic schema objects are predefined.
     if not href.startswith('http'):
         href = util.reduce_url(
             os.path.join(base, href).replace(os.path.sep, '/'))
     key = f'{self.current_taxonomy_hash}_{href}'
     if key in self.discovered:
         return
     self.discovered[key] = False
     # print(href)
     if href.endswith(".xsd"):
         sh = self.schemas.get(href, schema.Schema(href, self))
         self.current_taxonomy.attach_schema(href, sh)
     else:
         lb = self.linkbases.get(href, linkbase.Linkbase(href, self))
         self.current_taxonomy.attach_linkbase(href, lb)
예제 #6
0
 def identify_objects(self, xlbl):
     # Seek by XLabel directly in current link
     res = self.resources.get(xlbl, None)
     if res is not None:
         return res
     # Seek role type by roleUri in taxonomy
     rt = self.linkbase.pool.current_taxonomy.role_types.get(xlbl, None)
     if rt is not None:
         return [rt]
     # Seek arcrole type by roleUri in taxonomy
     art = self.linkbase.pool.current_taxonomy.arcrole_types.get(xlbl, None)
     if art is not None:
         return [art]
     loc = self.locators.get(xlbl, None)
     if loc is None:
         return None
     if loc.url == const.URL_ASSERTION_SEVERITIES:
         return [loc.fragment_identifier
                 ]  # Directly assign severity to assertion
     href = urllib.parse.unquote(util.reduce_url(loc.href))
     # Seek for a concept
     c = self.linkbase.pool.current_taxonomy.concepts.get(href, None)
     if c is not None:
         return [c]
     # Seek global resource by XPointer
     res = self.linkbase.pool.current_taxonomy.resources.get(href, None)
     if res is not None:
         return [res]
     # Seek role type by XPointer
     rt = self.linkbase.pool.current_taxonomy.role_types_by_href.get(
         href, None)
     if rt is not None:
         return [rt]
     # Seek arcrole type by XPointer
     art = self.linkbase.pool.current_taxonomy.arcrole_types_by_href.get(
         href, None)
     if art is not None:
         return [art]
예제 #7
0
 def __init__(self,
              location=None,
              container_pool=None,
              parsers=None,
              root=None):
     if parsers is None:
         parsers = {}
     self.pool = container_pool
     self.namespaces = {}  # Key is the prefix and value is the URI
     self.namespaces_reverse = {}  # Key is the UrI and value is the prefix
     self.schema_location_parts = {}
     self.base = ''
     if location:
         self.location = util.reduce_url(location)
         # self.base = self.location.replace('\\', '/')[:location.rfind("/")]
         self.base = os.path.split(location)[0]
         if root is None:  # Only parsing file again the root element is not explicitly passed
             root = self.get_root()
     if root is None:
         return
     self.l_namespaces(root)
     self.l_schema_location(root)
     super().__init__(root, parsers)
예제 #8
0
 def __init__(self, location, container_pool, root=None):
     parsers = {
         f'{{{const.NS_LINK}}}linkbase': self.l_linkbase,
         f'{{{const.NS_LINK}}}calculationLink': self.l_link,
         f'{{{const.NS_LINK}}}presentationLink': self.l_link,
         f'{{{const.NS_LINK}}}definitionLink': self.l_link,
         f'{{{const.NS_LINK}}}labelLink': self.l_link,
         f'{{{const.NS_LINK}}}referenceLink': self.l_link,
         f'{{{const.NS_GEN}}}link': self.l_link,  # Generic link
         f'{{{const.NS_LINK}}}roleRef': self.l_role_ref,
         f'{{{const.NS_LINK}}}arcroleRef': self.l_arcrole_ref
     }
     self.role_refs = {}
     self.arcrole_refs = {}
     self.refs = set({})
     self.pool = container_pool
     self.links = []
     resolved_location = util.reduce_url(location)
     if self.pool is not None:
         self.pool.discovered[location] = True
     super().__init__(resolved_location, container_pool, parsers, root)
     if self.pool is not None:
         self.pool.linkbases[resolved_location] = self