当前位置: 首页>>代码示例>>Python>>正文


Python arelle.XmlValidate类代码示例

本文整理汇总了Python中arelle.XmlValidate的典型用法代码示例。如果您正苦于以下问题:Python XmlValidate类的具体用法?Python XmlValidate怎么用?Python XmlValidate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了XmlValidate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: createFact

 def createFact(self, conceptQname, attributes=None, text=None, parent=None, afterSibling=None, beforeSibling=None):
     if parent is None: parent = self.modelDocument.xmlRootElement
     newFact = XmlUtil.addChild(parent, conceptQname, attributes=attributes, text=text,
                                afterSibling=afterSibling, beforeSibling=beforeSibling)
     self.modelDocument.factDiscover(newFact, parentElement=parent)
     XmlValidate.validate(self, newFact)
     return newFact    
开发者ID:Bourne-Law,项目名称:Arelle,代码行数:7,代码来源:ModelXbrl.py

示例2: sEqual

def sEqual(dts1, elt1, elt2, equalMode=S_EQUAL, excludeIDs=NO_IDs_EXCLUDED, dts2=None, ns2ns1Tbl=None):
    if dts2 is None: dts2 = dts1
    if elt1.localName != elt2.localName:
        return False
    if ns2ns1Tbl and elt2.namespaceURI in ns2ns1Tbl:
        if elt1.namespaceURI != ns2ns1Tbl[elt2.namespaceURI]:
            return False
    elif elt1.namespaceURI != elt2.namespaceURI:
        return False
    if not hasattr(elt1,u"xValid"):
        XmlValidate.validate(dts1, elt1)
    if not hasattr(elt2,u"xValid"):
        XmlValidate.validate(dts2, elt2)
    children1 = childElements(elt1)
    children2 = childElements(elt2)
    if len(children1) != len(children2):
        return False
    if (not xEqual(elt1, elt2,
                   # must use stringValue for nested contents of mixed content 
                   # ... this is now in xValue for mixed content
                   # VALIDATE_BY_STRING_VALUE if len(children1) and elt1.xValid == VALID else
                   equalMode
                   ) or 
        attributeDict(dts1, elt1, (), equalMode, excludeIDs) != 
        attributeDict(dts2, elt2, (), equalMode, excludeIDs, ns2ns1Tbl)):
        return False
    excludeChildIDs = excludeIDs if excludeIDs != TOP_IDs_EXCLUDED else NO_IDs_EXCLUDED
    for i in xrange( len(children1) ):
        if not sEqual(dts1, children1[i], children2[i], equalMode, excludeChildIDs, dts2, ns2ns1Tbl):
            return False
    return True
开发者ID:sternshus,项目名称:not_arelle2.7,代码行数:31,代码来源:XbrlUtil.py

示例3: equalityHash

def equalityHash(elt, equalMode=S_EQUAL, excludeIDs=NO_IDs_EXCLUDED):
    if isinstance(elt, ModelObject):
        try:
            if equalMode == S_EQUAL:
                return elt._hashSEqual
            else:
                return elt._hashXpathEqual
        except AttributeError:
            dts = elt.modelXbrl
            if not hasattr(elt,"xValid"):
                XmlValidate.validate(dts, elt)
            hashableValue = elt.sValue if equalMode == S_EQUAL else elt.xValue
            if isinstance(hashableValue,float) and math.isnan(hashableValue): 
                hashableValue = (hashableValue,elt)    # ensure this NaN only compares to itself and no other NaN
            _hash = hash((elt.elementQname,
                          hashableValue,
                          tuple(attributeDict(dts, elt, (), equalMode, excludeIDs, distinguishNaNs=True).items()),
                          tuple(equalityHash(child,equalMode,excludeIDs) for child in childElements(elt))
                          ))
            if equalMode == S_EQUAL:
                elt._hashSEqual = _hash
            else:
                elt._hashXpathEqual = _hash
            return _hash
    elif isinstance(elt, (tuple,list,set)):
        return hash( tuple(equalityHash(i) for i in elt) )
    else:
        return hash(None)
开发者ID:marado,项目名称:Arelle,代码行数:28,代码来源:XbrlUtil.py

示例4: sEqual

def sEqual(dts1, elt1, elt2, equalMode=S_EQUAL, excludeIDs=NO_IDs_EXCLUDED, dts2=None, ns2ns1Tbl=None):
    if dts2 is None: dts2 = dts1
    if elt1.localName != elt2.localName:
        return False
    if ns2ns1Tbl and elt2.namespaceURI in ns2ns1Tbl:
        if elt1.namespaceURI != ns2ns1Tbl[elt2.namespaceURI]:
            return False
    elif elt1.namespaceURI != elt2.namespaceURI:
        return False
    if not hasattr(elt1,"xValid"):
        XmlValidate.validate(dts1, elt1)
    if not hasattr(elt2,"xValid"):
        XmlValidate.validate(dts2, elt2)
    if (not xEqual(elt1, elt2, equalMode) or 
        attributeDict(dts1, elt1, (), equalMode, excludeIDs) != 
        attributeDict(dts2, elt2, (), equalMode, excludeIDs, ns2ns1Tbl)):
        return False
    children1 = childElements(elt1)
    children2 = childElements(elt2)
    if len(children1) != len(children2):
        return False
    excludeChildIDs = excludeIDs if excludeIDs != TOP_IDs_EXCLUDED else NO_IDs_EXCLUDED
    for i in range( len(children1) ):
        if not sEqual(dts1, children1[i], children2[i], equalMode, excludeChildIDs, dts2, ns2ns1Tbl):
            return False
    return True
开发者ID:marado,项目名称:Arelle,代码行数:26,代码来源:XbrlUtil.py

示例5: createUnit

 def createUnit(self, multiplyBy, divideBy, afterSibling=None, beforeSibling=None):
     """Creates new unit, by measures, as in formula usage, if any
     
     :param multiplyBy: List of multiply-by measure QNames (or top level measures if no divideBy)
     :type multiplyBy: [QName]
     :param divideBy: List of multiply-by measure QNames (or empty list if no divideBy)
     :type divideBy: [QName]
     :param beforeSibling: lxml element in instance to insert new concept before
     :type beforeSibling: ModelObject
     :param afterSibling: lxml element in instance to insert new concept after
     :type afterSibling: ModelObject
     :returns: ModelUnit -- New unit object
     """
     xbrlElt = self.modelDocument.xmlRootElement
     if afterSibling == AUTO_LOCATE_ELEMENT:
         afterSibling = XmlUtil.lastChild(xbrlElt, XbrlConst.xbrli, ("schemaLocation", "roleType", "arcroleType", "context", "unit"))
     unitId = 'u-{0:02n}'.format( len(self.units) + 1)
     newUnitElt = XmlUtil.addChild(xbrlElt, XbrlConst.xbrli, "unit", attributes=("id", unitId),
                                   afterSibling=afterSibling, beforeSibling=beforeSibling)
     if len(divideBy) == 0:
         for multiply in multiplyBy:
             XmlUtil.addChild(newUnitElt, XbrlConst.xbrli, "measure", text=XmlUtil.addQnameValue(xbrlElt, multiply))
     else:
         divElt = XmlUtil.addChild(newUnitElt, XbrlConst.xbrli, "divide")
         numElt = XmlUtil.addChild(divElt, XbrlConst.xbrli, "unitNumerator")
         denElt = XmlUtil.addChild(divElt, XbrlConst.xbrli, "unitDenominator")
         for multiply in multiplyBy:
             XmlUtil.addChild(numElt, XbrlConst.xbrli, "measure", text=XmlUtil.addQnameValue(xbrlElt, multiply))
         for divide in divideBy:
             XmlUtil.addChild(denElt, XbrlConst.xbrli, "measure", text=XmlUtil.addQnameValue(xbrlElt, divide))
     self.modelDocument.unitDiscover(newUnitElt)
     XmlValidate.validate(self, newUnitElt)
     return newUnitElt
开发者ID:benrosemeyer-wf,项目名称:Arelle,代码行数:33,代码来源:ModelXbrl.py

示例6: attributeDict

def attributeDict(modelXbrl, elt, exclusions=set(), equalMode=S_EQUAL, excludeIDs=NO_IDs_EXCLUDED, ns2ns1Tbl=None, keyByTag=False, distinguishNaNs=False):
    if not hasattr(elt,"xValid"):
        XmlValidate.validate(modelXbrl, elt)
    attrs = {}
    # TBD: replace with validated attributes
    for modelAttribute in elt.xAttributes.values():
        attrTag = modelAttribute.attrTag
        ns, sep, localName = attrTag.partition('}')
        attrNsURI = ns[1:] if sep else None
        if ns2ns1Tbl and attrNsURI in ns2ns1Tbl:
            attrNsURI = ns2ns1Tbl[attrNsURI]
        if (attrTag not in exclusions and 
            (attrNsURI is None or attrNsURI not in exclusions)):
            if keyByTag:
                qname = attrTag
            elif attrNsURI is not None:
                qname = QName(None, attrNsURI, localName)
            else:
                qname = QName(None, None, attrTag)
            try:
                if excludeIDs and modelAttribute.xValid == XmlValidate.VALID_ID:
                    continue
                value = modelAttribute.sValue if equalMode <= S_EQUAL2 else modelAttribute.xValue
                if distinguishNaNs and isinstance(value,float) and math.isnan(value):
                    value = (value,elt)
                attrs[qname] = value
            except KeyError:
                pass  # what should be done if attribute failed to have psvi value
    return attrs
开发者ID:marado,项目名称:Arelle,代码行数:29,代码来源:XbrlUtil.py

示例7: xEqual

def xEqual(elt1, elt2, equalMode=S_EQUAL):
    if not hasattr(elt1,"xValid"):
        XmlValidate.validate(elt1.modelXbrl, elt1)
    if not hasattr(elt2,"xValid"):
        XmlValidate.validate(elt2.modelXbrl, elt2)
    if equalMode == S_EQUAL or (equalMode == S_EQUAL2 and not isinstance(elt1.sValue, QName)):
        return elt1.sValue == elt2.sValue
    else:
        return elt1.xValue == elt2.xValue
开发者ID:marado,项目名称:Arelle,代码行数:9,代码来源:XbrlUtil.py

示例8: usedOns

 def usedOns(self): 
     try:
         return self._usedOns
     except AttributeError:
         XmlValidate.validate(self.modelXbrl, self)
         self._usedOns = set(usedOn.xValue
                             for usedOn in self.iterdescendants("{http://www.xbrl.org/2003/linkbase}usedOn")
                             if isinstance(usedOn,ModelObject))
         return self._usedOns
开发者ID:marado,项目名称:Arelle,代码行数:9,代码来源:ModelDtsObject.py

示例9: checkAttribute

 def checkAttribute(elt, isIxElt, attrTag, attrValue):
     ixEltAttrDefs = ixAttrDefined.get(elt.namespaceURI, EMPTYDICT).get(elt.localName, ())
     if attrTag.startswith("{"):
         ns, sep, localName = attrTag[1:].partition("}")
     else:
         ns = None
         localName = attrTag
     if ns is not None and ns not in XbrlConst.ixbrlAll and attrTag not in ixEltAttrDefs:
         if isIxElt:
             allowedNs = allowedNonIxAttrNS.get(elt.localName, None)
             if allowedNs != "##other" and ns != allowedNs:
                 modelXbrl.error(ixMsgCode("qualifiedAttributeNotExpected", elt),
                     _("Inline XBRL element %(element)s has qualified attribute %(name)s"),
                     modelObject=elt, element=str(elt.elementQname), name=attrTag)
             if ns == XbrlConst.xbrli and elt.localName in {
                 "fraction", "nonFraction", "nonNumeric", "references", "relationship", "tuple"}:                
                 modelXbrl.error(ixMsgCode("qualifiedAttributeDisallowed", elt),
                     _("Inline XBRL element %(element)s has disallowed attribute %(name)s"),
                     modelObject=elt, element=str(elt.elementQname), name=attrTag)
         else:
             if ns in XbrlConst.ixbrlAll:
                 modelXbrl.error(ixMsgCode("inlineAttributeMisplaced", elt, name="other"),
                     _("Inline XBRL attributes are not allowed on html elements: ix:%(name)s"),
                     modelObject=elt, name=localName)
             elif ns not in {XbrlConst.xml, XbrlConst.xsi, XbrlConst.xhtml}:
                 modelXbrl.error(ixMsgCode("extensionAttributeMisplaced", ns=_ixNS),
                     _("Extension attributes are not allowed on html elements: %(tag)s"),
                     modelObject=elt, tag=attrTag)
     elif isIxElt:
         try:
             _xsdType = ixAttrType[elt.namespaceURI][localName]
             if isinstance(_xsdType, dict):
                 baseXsdType = _xsdType["type"]
                 facets = _xsdType
             else:
                 baseXsdType = _xsdType
                 facets = None
             XmlValidate.validateValue(modelXbrl, elt, attrTag, baseXsdType, attrValue, facets=facets)
             
             if not (attrTag in ixEltAttrDefs or
                     (localName in ixEltAttrDefs and (not ns or ns in XbrlConst.ixbrlAll))):
                 raise KeyError
             disallowedXbrliAttrs = ({"scheme", "periodType",     "balance", "contextRef", "unitRef", "precision", "decimals"} -
                                     {"fraction": {"contextRef", "unitRef"},
                                      "nonFraction": {"contextRef", "unitRef", "decimals", "precision"},
                                      "nonNumeric": {"contextRef"}}.get(elt.localName, set()))
             disallowedAttrs = set(a for a in disallowedXbrliAttrs if elt.get(a) is not None)
             if disallowedAttrs:
                 modelXbrl.error(ixMsgCode("inlineElementAttributes",elt),
                     _("Inline XBRL element %(element)s has disallowed attributes %(attributes)s"),
                     modelObject=elt, element=elt.elementQname, attributes=", ".join(disallowedAttrs))
         except KeyError:
             modelXbrl.error(ixMsgCode("attributeNotExpected",elt),
                 _("Attribute %(attribute)s is not expected on element ix:%(element)s"),
                 modelObject=elt, attribute=attrTag, element=elt.localName)
开发者ID:sagesmith-wf,项目名称:Arelle,代码行数:55,代码来源:XhtmlValidate.py

示例10: xEqual

def xEqual(elt1, elt2, equalMode=S_EQUAL):
    if not hasattr(elt1,u"xValid"):
        XmlValidate.validate(elt1.modelXbrl, elt1)
    if not hasattr(elt2,u"xValid"):
        XmlValidate.validate(elt2.modelXbrl, elt2)
    if equalMode == VALIDATE_BY_STRING_VALUE:
        return elt1.stringValue == elt2.stringValue
    elif equalMode == S_EQUAL or (equalMode == S_EQUAL2 and not isinstance(elt1.sValue, QName)):
        return elt1.sValue == elt2.sValue
    else:
        return elt1.xValue == elt2.xValue
开发者ID:sternshus,项目名称:not_arelle2.7,代码行数:11,代码来源:XbrlUtil.py

示例11: typedValue

def typedValue(dts, element, attrQname=None):
    try:
        if attrQname:
            node = element.getAttributeNodeNS(attrQname.namespaceURI,attrQname.localName)
        else:
            node = element
        if node.xValid == XmlValidate.VALID:
            return node.xValue
    except AttributeError:
        if dts:
            XmlValidate.validate(dts, element, recurse=False, attrQname=attrQname)
            return typedValue(None, element, attrQname=attrQname)
        return None
开发者ID:8maki,项目名称:Arelle,代码行数:13,代码来源:XbrlUtil.py

示例12: typedValue

def typedValue(dts, element, attrQname=None):
    try:
        if attrQname: # PSVI attribute value
            modelAttribute = element.xAttributes[attrQname.clarkNotation]
            if modelAttribute.xValid >= XmlValidate.VALID:
                return modelAttribute.xValue
        else: # PSVI element value (of text)
            if element.xValid >= XmlValidate.VALID:
                return element.xValue
    except (AttributeError, KeyError):
        if dts:
            XmlValidate.validate(dts, element, recurse=False, attrQname=attrQname)
            return typedValue(None, element, attrQname=attrQname)
    return None
开发者ID:marado,项目名称:Arelle,代码行数:14,代码来源:XbrlUtil.py

示例13: xfxc_element

def  xfxc_element(xc, p, contextItem, args):
    if not 2 <= len(args) <= 4: raise XPathContext.FunctionNumArgs()
    qn = qnameArg(xc, p, args, 0, 'QName', emptyFallback=None)
    attrArg = args[1] if isinstance(args[1],(list,tuple)) else (args[1],)
    # attributes have to be pairs
    if attrArg:
        if len(attrArg) & 1 or any(not isinstance(attrArg[i], (QName, _STR_BASE))
                                   for i in range(0, len(attrArg),2)):
            raise XPathContext.FunctionArgType(1,"((xs:qname|xs:string),xs:anyAtomicValue)", errCode="xfxce:AttributesNotNameValuePairs")
        else:
            attrParam = [(attrArg[i],attrArg[i+1]) # need name-value pairs for XmlUtil function
                         for i in range(0, len(attrArg),2)]
    else:
        attrParam = None
         
    value = atomicArg(xc, p, args, 2, "xs:anyAtomicType", emptyFallback='') 
    if not value: # be sure '' is None so no text node is created
        value = None  
    if len(args) < 4:
        childElements = None
    else:
        childElements = xc.flattenSequence(args[3])
    
    # scratchpad instance document emulates fn:doc( ) to hold XML nodes
    scratchpadXmlDocUrl = "http://www.xbrl.org/2012/function/creation/xml_scratchpad.xml"
    if scratchpadXmlDocUrl in xc.modelXbrl.urlDocs:
        modelDocument = xc.modelXbrl.urlDocs[scratchpadXmlDocUrl]
    else:
        # create scratchpad xml document
        # this will get the fake instance document in the list of modelXbrl docs so that it is garbage collected
        from arelle import ModelDocument
        modelDocument = ModelDocument.create(xc.modelXbrl, 
                                             ModelDocument.Type.UnknownXML, 
                                             scratchpadXmlDocUrl,
                                             initialXml="<xfc:dummy xmlns:xfc='http://www.xbrl.org/2012/function/creation'/>")
        
    newElement = XmlUtil.addChild(modelDocument.xmlRootElement,
                                  qn,
                                  attributes=attrParam,
                                  text=value)
    if childElements:
        for element in childElements:
            if isinstance(element, etree.ElementBase):
                newElement.append(element)
                
    # node myst be validated for use in instance creation (typed dimension references)
    XmlValidate.validate(xc.modelXbrl, newElement)
                
    return newElement
开发者ID:Arelle,项目名称:Arelle,代码行数:49,代码来源:functionsXmlCreation.py

示例14: checkAttribute

 def checkAttribute(elt, isIxElt, attrTag, attrValue):
     if attrTag.startswith("{"):
         ns, sep, localName = attrTag[1:].partition("}")
         if isIxElt:
             allowedNs = nonIxAttrNS.get(elt.localName, None)
             if allowedNs != "##other" and ns != allowedNs:
                 modelXbrl.error("ix:qualifiedAttributeNotExpected",
                     _("Inline XBRL element %(element)s: has qualified attribute %(name)s"),
                     modelObject=elt, element=str(elt.elementQname), name=attrTag)
         else:
             if ns in XbrlConst.ixbrlAll:
                 modelXbrl.error("ix:inlineAttributeMisplaced",
                     _("Inline XBRL attributes are not allowed on html elements: ix:%(name)s"),
                     modelObject=elt, name=localName)
             elif ns not in {XbrlConst.xml, XbrlConst.xsi, XbrlConst.xhtml}:
                 modelXbrl.error("ix:extensionAttributeMisplaced",
                     _("Extension attributes are not allowed on html elements: %(tag)s"),
                     modelObject=elt, tag=attrTag)
     elif isIxElt:
         try:
             _xsdType = ixAttrType[elt.namespaceURI][attrTag]
             if isinstance(_xsdType, dict):
                 baseXsdType = _xsdType["type"]
                 facets = _xsdType
             else:
                 baseXsdType = _xsdType
                 facets = None
             XmlValidate.validateValue(modelXbrl, elt, attrTag, baseXsdType, attrValue, facets=facets)
             
             disallowedXbrliAttrs = ({"scheme", "periodType", "balance", "contextRef", "unitRef", "precision", "decimals"} -
                                     {"fraction": {"contextRef", "unitRef"},
                                      "nonFraction": {"contextRef", "unitRef", "decimals", "precision"},
                                      "nonNumeric": {"contextRef"}}.get(elt.localName, set()))
             disallowedAttrs = [a for a in disallowedXbrliAttrs if elt.get(a) is not None]
             if disallowedAttrs:
                 modelXbrl.error("ix:inlineElementAttributes",
                     _("Inline XBRL element %(element)s has disallowed attributes %(attributes)s"),
                     modelObject=elt, element=elt.elementQname, attributes=", ".join(disallowedAttrs))
         except KeyError:
             modelXbrl.error("ix:attributeNotExpected",
                 _("Attribute %(attribute)s is not expected on element element ix:%(element)s"),
                 modelObject=elt, attribute=attrTag, element=elt.localName)
开发者ID:davidjbell,项目名称:Arelle,代码行数:42,代码来源:XhtmlValidate.py

示例15: endElementNS

 def endElementNS(self, name, qname):
     thisQname = QName(None, *name)
     if self.qnameStack and self.qnameStack[0].elementQname == thisQname:
         elt = self.qnameStack.pop(0)
         if elt.namespaceURI == XbrlConst.xbrli:
             if elt.localName == "unit":
                 elt._measures = (sorted(elt._measures[0]), sorted(elt._measures[1]))
                 if elt.id in self.unitRefedFacts:
                     for fact in self.unitRefedFacts[elt.id]:
                         fact._unit = elt
                     del self.unitRefedFacts[elt.id]
             elif elt.localName == "context":
                 if elt.id in self.contextRefedFacts:
                     for fact in self.contextRefedFacts[elt.id]:
                         fact._context = elt
                     del self.contextRefedFacts[elt.id]
         self.currentNamespaceURI = None
         self.currentLocalName = None
         XmlValidate.validate(self.modelXbrl, elt, recurse=False)
         pass
开发者ID:Arelle,项目名称:Arelle,代码行数:20,代码来源:bigInstance.py


注:本文中的arelle.XmlValidate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。