def __init__(self, sourceStr, loc, name, toks, skipFirstTok): self.sourceStr = sourceStr self.loc = loc self.name = name if skipFirstTok: toks1 = toks[1] if len(toks) > 1 else None if ( isinstance(toks1, _STR_BASE) and isinstance(name, _STR_BASE) and name in ("/", "//", "rootChild", "rootDescendant") ): if toks1 == "*": toks1 = QNameDef(loc, None, "*", "*") elif toks1.startswith("*:"): toks1 = QNameDef(loc, None, "*", toks1[2:]) elif toks1.endswith(":*"): prefix = toks1[:-2] ns = XmlUtil.xmlns(xmlElement, prefix) if ns is None: modelXbrl.error( "err:XPST0081", _("wildcard prefix not defined for %(token)s"), modelObject=xmlElement, token=toks1, ) toks1 = QNameDef(loc, prefix, ns, "*") self.args = [toks1] + toks[2:] # special case for wildcard path segment else: self.args = toks[1:] """ self.args = toks[1:] """ else: # for others first token is just op code, no expression self.args = toks
def __init__(self, sourceStr, loc, name, toks, skipFirstTok): self.sourceStr = sourceStr self.loc = loc self.name = name if skipFirstTok: toks1 = toks[1] if len(toks) > 1 else None if (isinstance(toks1,_STR_BASE) and isinstance(name,_STR_BASE) and name in ('/', '//', 'rootChild', 'rootDescendant')): if toks1 == '*': toks1 = QNameDef(loc,None,'*','*') elif toks1.startswith('*:'): toks1 = QNameDef(loc,None,'*',toks1[2:]) elif toks1.endswith(':*'): prefix = toks1[:-2] ns = XmlUtil.xmlns(xmlElement, prefix) if ns is None: modelXbrl.error("err:XPST0081", _("wildcard prefix not defined for %(token)s"), modelObject=xmlElement, token=toks1) toks1 = QNameDef(loc,prefix,ns,'*') self.args = [toks1] + toks[2:] # special case for wildcard path segment else: self.args = toks[1:] ''' self.args = toks[1:] ''' else: # for others first token is just op code, no expression self.args = toks
def qname(value, name=None, noPrefixIsNoNamespace=False, castException=None, prefixException=None): # either value can be an etree ModelObject element: if no name then qname is element tag quanem # if name provided qname uses element as xmlns reference and name as prefixed name # value can be namespaceURI and name is localname or prefix:localname # value can be prefix:localname (and localname omitted) # for xpath qnames which do not take default namespace if no prefix, specify noPrefixIsNoNamespace if isinstance(value, ModelObject): if name: element = value # may be an attribute value = name name = None else: return QName(value.prefix, value.namespaceURI, value.localName) elif isinstance(name, ModelObject): element = name name = None elif value is None: element = None value = name else: element = None if isinstance(value,QName): return value elif not isinstance(value,str): if castException: raise castException return None if value.startswith('{'): # clark notation (with optional prefix) namespaceURI,sep,prefixedLocalName = value[1:].partition('}') prefix,sep,localName = prefixedLocalName.partition(':') if len(localName) == 0: localName = prefix prefix = None else: if name is not None: if name: # len > 0 namespaceURI = value else: namespaceURI = None value = name else: namespaceURI = None prefix,sep,localName = value.partition(":") if len(localName) == 0: #default namespace localName = prefix prefix = None if noPrefixIsNoNamespace: return QName(None, None, localName) if namespaceURI: return QName(prefix, namespaceURI, localName) elif element is not None: from arelle import (XmlUtil) namespaceURI = XmlUtil.xmlns(element, prefix) if not namespaceURI: if prefix: if castException: raise castException return None # error, prefix not found if not namespaceURI: namespaceURI = None # cancel namespace if it is a zero length string return QName(prefix, namespaceURI, localName)
def __init__(self, sourceStr, loc, name, toks, skipFirstTok): self.sourceStr = sourceStr self.loc = loc self.name = name if skipFirstTok: toks1 = toks[1] if len(toks) > 1 else None if (isinstance(toks1,str) and isinstance(name,str) and name in ('/', '//', 'rootChild', 'rootDescendant')): if toks1 == '*': toks1 = QNameDef(loc,None,'*','*') elif toks1.startswith('*:'): toks1 = QNameDef(loc,None,'*',toks1[2:]) elif toks1.endswith(':*'): prefix = toks1[:-2] ns = XmlUtil.xmlns(xmlElement, prefix) if ns is None: modelXbrl.error( _("wildcard prefix not defined for {0}").format(toks1), "err","err:XPST0081") toks1 = QNameDef(loc,prefix,ns,'*') self.args = [toks1] + toks[2:] # special case for wildcard path segment else: self.args = toks[1:] ''' self.args = toks[1:] ''' else: # for others first token is just op code, no expression self.args = toks
def namespace_uri_for_prefix(xc, p, contextItem, args): prefix = nodeArg(xc, args, 0, 'string?', emptyFallback='') node = nodeArg(xc, args, 1, 'element()', emptyFallback=()) if node and isinstance( node, xml.dom.Node) and node.nodeType == xml.dom.Node.ELEMENT_NODE: return XmlUtil.xmlns(node, prefix) return ()
def qname(value, name=None, noPrefixIsNoNamespace=False, castException=None, prefixException=None): # either value can be an xml.dom Node: if no name then qname is element tag quanem # if name provided qname uses element as xmlns reference and name as prefixed name # value can be namespaceURI and name is localname or prefix:localname # value can be prefix:localname (and localname omitted) # for xpath qnames which do not take default namespace if no prefix, specify noPrefixIsNoNamespace if isinstance(value, xml.dom.Node): if name: element = value # may be an attribute value = name name = None else: return QName(value.prefix, value.namespaceURI, value.localName) elif isinstance(name, xml.dom.Node): element = name name = None elif value is None: element = None value = name else: element = None if isinstance(value,QName): return value elif not isinstance(value,str): if castException: raise castException return None if value.startswith('{'): namespaceURI,sep,localName = value[1:].partition('}') prefix = None else: if name is not None: if name: # len > 0 namespaceURI = value else: namespaceURI = None value = name else: namespaceURI = None names = value.partition(":") if names[2] == "": #default namespace prefix = None localName = names[0] if noPrefixIsNoNamespace: return QName(None, None, localName) else: prefix = names[0] localName = names[2] if namespaceURI: return QName(prefix, namespaceURI, localName) elif element: from arelle import (XmlUtil) namespaceURI = XmlUtil.xmlns(element, prefix) if not namespaceURI: if prefix: if castException: raise castException return None # error, prefix not found return QName(prefix, namespaceURI, localName)
def namespace_uri_for_prefix(xc, p, contextItem, args): prefix = nodeArg(xc, args, 0, 'string?', emptyFallback='') node = nodeArg(xc, args, 1, 'element()', emptyFallback=()) if node is not None and isinstance(node,ModelObject): return XmlUtil.xmlns(node, prefix) return ()
def namespace_uri_for_prefix(xc, p, contextItem, args): prefix = nodeArg(xc, args, 0, 'string?', emptyFallback='') node = nodeArg(xc, args, 1, 'element()', emptyFallback=()) if node and isinstance(node,xml.dom.Node) and node.nodeType == xml.dom.Node.ELEMENT_NODE: return XmlUtil.xmlns(node, prefix) return ()
def qname(value, name=None, noPrefixIsNoNamespace=False, castException=None, prefixException=None): # either value can be an etree ModelObject element: if no name then qname is element tag quanem # if name provided qname uses element as xmlns reference and name as prefixed name # value can be namespaceURI and name is localname or prefix:localname # value can be prefix:localname (and localname omitted) # for xpath qnames which do not take default namespace if no prefix, specify noPrefixIsNoNamespace if isinstance(value, ModelObject): if name: element = value # may be an attribute value = name name = None else: return QName(value.prefix, value.namespaceURI, value.localName) elif isinstance(name, ModelObject): element = name name = None element = None value = name else: element = None if isinstance(value,QName): return value elif not isinstance(value,_STR_BASE): if castException: raise castException return None if value.startswith('{'): # clark notation (with optional prefix) namespaceURI,sep,prefixedLocalName = value[1:].partition('}') prefix,sep,localName = prefixedLocalName.partition(':') if len(localName) == 0: localName = prefix prefix = None namespaceDict = None else: if isinstance(name, dict): namespaceURI = None namespaceDict = name elif name is not None: if name: # len > 0 namespaceURI = value else: namespaceURI = None namespaceDict = None value = name else: namespaceURI = None namespaceDict = None prefix,sep,localName = value.partition(":") if len(localName) == 0: #default namespace localName = prefix prefix = None if noPrefixIsNoNamespace: return QName(None, None, localName) if namespaceURI: return QName(prefix, namespaceURI, localName) elif namespaceDict and prefix in namespaceDict: return QName(prefix, namespaceDict[prefix], localName) elif element is not None: from arelle import (XmlUtil) namespaceURI = XmlUtil.xmlns(element, prefix) if not namespaceURI: if prefix: if castException: raise castException return None # error, prefix not found if not namespaceURI: namespaceURI = None # cancel namespace if it is a zero length string return QName(prefix, namespaceURI, localName)
def qname(value, name=None, noPrefixIsNoNamespace=False, castException=None, prefixException=None): # either value can be an xml.dom Node: if no name then qname is element tag quanem # if name provided qname uses element as xmlns reference and name as prefixed name # value can be namespaceURI and name is localname or prefix:localname # value can be prefix:localname (and localname omitted) # for xpath qnames which do not take default namespace if no prefix, specify noPrefixIsNoNamespace if isinstance(value, xml.dom.Node): if name: element = value # may be an attribute value = name name = None else: return QName(value.prefix, value.namespaceURI, value.localName) elif isinstance(name, xml.dom.Node): element = name name = None elif value is None: element = None value = name else: element = None if isinstance(value, QName): return value elif not isinstance(value, str): if castException: raise castException return None if value.startswith('{'): namespaceURI, sep, localName = value[1:].partition('}') prefix = None else: if name is not None: if name: # len > 0 namespaceURI = value else: namespaceURI = None value = name else: namespaceURI = None names = value.partition(":") if names[2] == "": #default namespace prefix = None localName = names[0] if noPrefixIsNoNamespace: return QName(None, None, localName) else: prefix = names[0] localName = names[2] if namespaceURI: return QName(prefix, namespaceURI, localName) elif element: from arelle import (XmlUtil) namespaceURI = XmlUtil.xmlns(element, prefix) if not namespaceURI: if prefix: if castException: raise castException return None # error, prefix not found return QName(prefix, namespaceURI, localName)