Exemple #1
0
def fn_dateTime(xc, p, contextItem, args):
    if len(args) != 2: raise XPathContext.FunctionNumArgs()
    date = anytypeArg(xc, args, 0, "xs:date", missingArgFallback=())
    time = anytypeArg(xc, args, 1, "xs:time", missingArgFallback=())
    if date is None or time is None:
        return ()
    return dateTime(date) + dayTimeDuration(time)
Exemple #2
0
def instance(xc, p, args, i=0):
    if len(args[i]) != 1:
        raise XPathContext.FunctionArgType(i + 1, "xbrl:xbrl")
    modelXbrl = xc.modelInstance(anytypeArg(xc, args, i, "xbrli:xbrl"))
    if modelXbrl:
        return modelXbrl
    raise XPathContext.FunctionArgType(i + 1, "xbrl:xbrl")
Exemple #3
0
def element_name(xc, p, args, elementParent=False):
    if len(args) != 1: raise XPathContext.FunctionNumArgs()
    modelRel = anytypeArg(xc, args, 0, "arelle:ModelRelationship", None)
    if modelRel is None: raise XPathContext.FunctionArgType(1,"arelle:modelRelationship")
    element = modelRel.arcElement
    if elementParent: element = element.getparent()
    return qname(element)
Exemple #4
0
def base_uri(xc, p, contextItem, args):
    item = anytypeArg(xc, args, 0, "node()?", missingArgFallback=contextItem)
    if item == ():
        return ''
    if isinstance(item, (ModelObject, ModelDocument)):
        return UrlUtil.ensureUrl(item.modelDocument.uri)
    return ''
Exemple #5
0
def base_uri(xc, p, contextItem, args):
    item = anytypeArg(xc, args, 0, "node()?", missingArgFallback=contextItem)
    if item == (): 
        return ''
    if isinstance(item, (ModelObject, ModelDocument)):
        return UrlUtil.ensureUrl(item.modelDocument.uri)
    return ''
Exemple #6
0
def seconds_from_duration(xc, p, contextItem, args):
    if len(args) != 1: raise XPathContext.FunctionNumArgs()
    d = anytypeArg(xc, args, 0, 'duration', missingArgFallback=())
    if d == (): return d
    if isinstance(d, DayTimeDuration): return 0
    if isinstance(d, YearMonthDuration): return d.dayHrsMinsSecs[2]
    raise XPathContext.FunctionArgType(1,"xs:duration")    
Exemple #7
0
def element_name(xc, p, args, elementParent=False):
    if len(args) != 1: raise XPathContext.FunctionNumArgs()
    modelRel = anytypeArg(xc, args, 0, "arelle:ModelRelationship", None)
    if not modelRel:
        raise XPathContext.FunctionArgType(1, "arelle:modelRelationship")
    element = modelRel.element
    if elementParent: element = element.parentNode
    return qname(element)
Exemple #8
0
def concat(xc, p, contextItem, args):
    if len(args) < 2: raise XPathContext.FunctionNumArgs()
    atomizedArgs = []
    for i in range(len(args)):
        item = anytypeArg(xc, args, i, "xs:anyAtomicType?")
        if item != ():
            atomizedArgs.append( FunctionXs.xsString( xc, p, xc.atomize(p, item) ) )
    return ''.join(atomizedArgs)
Exemple #9
0
def relationship_element_attribute(xc, p, args, elementParent=False):
    if len(args) != 2: raise XPathContext.FunctionNumArgs()
    modelRel = anytypeArg(xc, args, 0, "arelle:ModelRelationship", None)
    if modelRel is None: raise XPathContext.FunctionArgType(1,"arelle:modelRelationship")
    qnAttr = qnameArg(xc, p, args, 1, 'QName', emptyFallback=None)
    if qnAttr is None: raise XPathContext.FunctionArgType(2,"xs:QName")
    element = modelRel.arcElement
    if elementParent: element = element.getparent()
    return element_attribute(element, qnAttr)
Exemple #10
0
def string(xc, p, contextItem, args):
    if len(args) > 1: raise XPathContext.FunctionNumArgs()
    item = anytypeArg(xc, args, 0, "item()?", missingArgFallback=contextItem)
    if item == (): 
        return ''
    if isinstance(item, ModelObject) and getattr(item,"xValid", 0) == VALID_NO_CONTENT:
        x = item.stringValue # represents inner text of this and all subelements
    else:
        x = xc.atomize(p, item)
    return FunctionXs.xsString( xc, p, x ) 
Exemple #11
0
def string(xc, p, contextItem, args):
    if len(args) > 1: raise XPathContext.FunctionNumArgs()
    item = anytypeArg(xc, args, 0, "item()?", missingArgFallback=contextItem)
    if item == ():
        return ''
    if isinstance(item, ModelObject) and getattr(item, "xValid",
                                                 0) == VALID_NO_CONTENT:
        x = item.stringValue  # represents inner text of this and all subelements
    else:
        x = xc.atomize(p, item)
    return FunctionXs.xsString(xc, p, x)
Exemple #12
0
def element_attribute(xc, p, args, elementParent=False):
    if len(args) != 2: raise XPathContext.FunctionNumArgs()
    modelRel = anytypeArg(xc, args, 0, "arelle:ModelRelationship", None)
    if not modelRel: raise XPathContext.FunctionArgType(1,"arelle:modelRelationship")
    qnAttr = qnameArg(xc, p, args, 1, 'QName', emptyFallback=None)
    if not qnAttr: raise XPathContext.FunctionArgType(2,"xs:QName")
    element = modelRel.element
    if elementParent: element = element.parentNode
    if qnAttr.namespaceURI:
        if not element.hasAttributeNS(qnAttr.namespaceURI, qnAttr.localName):
            return ()
        return xc.atomize(p, element.getAttributeNodeNS(qnAttr.namespaceURI, qnAttr.localName))
    else:
        if not element.hasAttribute(qnAttr.localName):
            return ()
        return xc.atomize(p, element.getAttributeNode(qnAttr.localName))
Exemple #13
0
def element_attribute(xc, p, args, elementParent=False):
    if len(args) != 2: raise XPathContext.FunctionNumArgs()
    modelRel = anytypeArg(xc, args, 0, "arelle:ModelRelationship", None)
    if not modelRel:
        raise XPathContext.FunctionArgType(1, "arelle:modelRelationship")
    qnAttr = qnameArg(xc, p, args, 1, 'QName', emptyFallback=None)
    if not qnAttr: raise XPathContext.FunctionArgType(2, "xs:QName")
    element = modelRel.element
    if elementParent: element = element.parentNode
    if qnAttr.namespaceURI:
        if not element.hasAttributeNS(qnAttr.namespaceURI, qnAttr.localName):
            return ()
        return xc.atomize(
            p, element.getAttributeNodeNS(qnAttr.namespaceURI,
                                          qnAttr.localName))
    else:
        if not element.hasAttribute(qnAttr.localName):
            return ()
        return xc.atomize(p, element.getAttributeNode(qnAttr.localName))
Exemple #14
0
def relationship_to_concept(xc, p, args):
    if len(args) != 1: raise XPathContext.FunctionNumArgs()
    modelRel = anytypeArg(xc, args, 0, "arelle:ModelRelationship", None)
    if modelRel is not None:
        return modelRel.toModelObject.qname
    raise XPathContext.FunctionArgType(1,"arelle:modelRelationship")
Exemple #15
0
def timezone_from_time(xc, p, contextItem, args):
    if len(args) != 1: raise XPathContext.FunctionNumArgs()
    d = anytypeArg(xc, args, 0, 'time', missingArgFallback=())
    if d == (): return d
    if isinstance(d, Time): return d.tzinfo
    raise XPathContext.FunctionArgType(1,"xs:time")    
Exemple #16
0
def day_from_date(xc, p, contextItem, args):
    if len(args) != 1: raise XPathContext.FunctionNumArgs()
    d = anytypeArg(xc, args, 0, 'dateTime', missingArgFallback=())
    if d == (): return d
    if isinstance(d, DateTime): return d.day
    raise XPathContext.FunctionArgType(1,"xs:dateTime")    
Exemple #17
0
def instance(xc, p, args, i=0):
    if len(args[i]) != 1: raise XPathContext.FunctionArgType(i+1,"xbrl:xbrl")
    modelXbrl = xc.modelInstance(anytypeArg(xc, args, i, "xbrli:xbrl"))
    if modelXbrl:
        return modelXbrl
    raise XPathContext.FunctionArgType(i+1,"xbrl:xbrl")
Exemple #18
0
def instance(xc, p, args, i=0):
    if len(args[i]) != 1: raise XPathContext.FunctionArgType(i+1,"xbrl:xbrl")
    xbrliXbrl = anytypeArg(xc, args, i, "xbrli:xbrl")
    if isinstance(xbrliXbrl, ModelObject) and xbrliXbrl.elementQname == XbrlConst.qnXbrliXbrl:
        return xbrliXbrl.modelXbrl
    raise XPathContext.FunctionArgType(i+1,"xbrl:xbrl")
Exemple #19
0
def relationship_to_concept(xc, p, args):
    if len(args) != 1: raise XPathContext.FunctionNumArgs()
    modelRel = anytypeArg(xc, args, 0, "arelle:ModelRelationship", None)
    if modelRel:
        return modelRel.toModelObject.qname
    raise XPathContext.FunctionArgType(1, "arelle:modelRelationship")