Beispiel #1
0
def countrynameen(arg):
    countryMatch = countryNamePattern.match(arg)
    if not countryMatch or len(arg.strip()) == 0:
        raise FunctionArgType(1, "countrynameen lexical error")
    try:
        return countryCodes[codeIndex(countryMatch)]
    except (IndexException, TypeError) as ex:
        raise FunctionArgType(0, str(ex))
Beispiel #2
0
def stateprovnameen(arg):
    stateProvMatch = stateProvNamePattern.match(arg)
    if not stateProvMatch or len(arg.strip()) == 0:
        raise FunctionArgType(1, "stateprovnameen lexical error")
    try:
        return stateProvCodes[codeIndex(stateProvMatch)]
    except (IndexException, TypeError) as ex:
        raise FunctionArgType(0, str(ex))
Beispiel #3
0
def boolballotbox(arg):
    ballotboxMatch = ballotboxPattern.match(arg)
    if not ballotboxMatch or len(arg.strip()) == 0:
        raise FunctionArgType(1, "boolballotboxMatch lexical error")
    try:
        return ("false", "true", "true")[ord(ballotboxMatch.group(1)[0]) - ord('\u2610')]
    except (IndexException, TypeError) as ex:
        raise FunctionArgType(0, str(ex))
Beispiel #4
0
def entityfilercategoryen(arg):
    entityFilerMatch = entityFilerNamePattern.match(arg)
    if not entityFilerMatch or len(arg.strip()) == 0:
        raise FunctionArgType(1, "entityfilercategoryen lexical error")
    try:
        return entityFilerCodes[codeIndex(entityFilerMatch)]
    except (IndexException, TypeError) as ex:
        raise FunctionArgType(0, str(ex))
Beispiel #5
0
def edgarprovcountryen(arg):
    edgarProvCountryMatch = edgarProvCountryNamePattern.match(arg)
    if not edgarProvCountryMatch or len(arg.strip()) == 0:
        raise FunctionArgType(1, "stateorcountrynameen lexical error")
    try:
        return edgarProvCountryCodes[codeIndex(edgarProvCountryMatch)]
    except (IndexException, TypeError) as ex:
        raise FunctionArgType(0, str(ex))
Beispiel #6
0
def exchnameen(arg):
    exchMatch = exchNamePattern.match(arg)
    if not exchMatch or len(arg.strip()) == 0:
        raise FunctionArgType(1, "exchnameen lexical error")
    try:
        return exchCodes[codeIndex(exchMatch)]
    except (IndexException, TypeError) as ex:
        raise FunctionArgType(0, str(ex))
Beispiel #7
0
def numwordsen(arg):
    if not numwordsenPattern.match(arg) or len(arg) == 0:
        raise FunctionArgType(1, "numwordsen lexical error")
    elif numwordsNoPattern.match(arg): # match "no" or "none"
        return "0"
    try:
        return str(text2num(commaAndPattern.sub(" ", arg.strip().lower()))) # must be returned as a string
    except (NumberException, TypeError, ValueError) as ex:
        raise FunctionArgType(1, str(ex))
Beispiel #8
0
def getValue(arg):
    if not decimalValuePattern.match(arg):
        raise FunctionArgType(0, "xs:duration")
    try:
        n = float(arg)  # could cause a ValueError exception
        if n < 0:
            return (abs(n), '-')  # add a negative sign
        return (n, '')  # don't add a sign
    except ValueError:
        raise FunctionArgType(0, "xs:duration")
Beispiel #9
0
def durwordsen(arg):
    durWordsMatch = durwordsenPattern.match(arg)
    if not durWordsMatch or len(arg.strip()) == 0:
        raise FunctionArgType(1, "durwordsen lexical error")
    try:
        dur = 'P'
        durWordsMatchGroups = durWordsMatch.groups()
        for groupIndex, groupSuffix in ((1,"Y"), (61,"M"), (121, "D")):
            groupPart = durWordsMatchGroups[groupIndex]
            if groupPart and not durwordZeroNoPattern.match(groupPart):
                if groupPart.isnumeric():
                    dur += groupPart + groupSuffix
                else:
                    dur += str(text2num(commaAndPattern.sub(" ", groupPart.strip().lower()))) + groupSuffix
        return dur if len(dur) > 1 else "P0D" # must have at least one number and designator
    except (NumberException, TypeError, ValueError) as ex:
        raise FunctionArgType(1, str(ex))
Beispiel #10
0
def getValue(arg):
    try:
        n = float(arg) # could cause a ValueError exception
        if n < 0:
            return (abs(n), '-') # add a negative sign
        return (n, '') # don't add a sign
    except ValueError:
        raise FunctionArgType(1, "xs:duration")
Beispiel #11
0
def datequarterend(arg):
    try:
        m = dateQuarterEndPattern.match(arg)
        year = int(m.group(3) or m.group(5)) # year pattern, raises AttributeError if no pattern match
        month = {"first":3, "1":3, "second":6, "2":6, "third":9, "3":9, "fourth":12, "last":12, "4":12
                 }[(m.group(2) or m.group(6)).lower()]
        return str(datetime.date(year, month, lastDayOfMonth(year, month)))
    except (AttributeError, ValueError, KeyError):
        raise FunctionArgType(0, "xs:date")
Beispiel #12
0
def anytypeArg(xc, args, i, type, missingArgFallback=None):
    if len(args) > i:
        item = args[i]
    else:
        item = missingArgFallback
    if isinstance(item, (tuple, list)):
        if len(item) > 1: raise FunctionArgType(i, type, item)
        if len(item) == 0: return ()
        item = item[0]
    return item
Beispiel #13
0
def numericArg(xc, p, args, i=0, missingArgFallback=None, emptyFallback=0, convertFallback=None):
    item = anytypeArg(xc, args, i, "numeric?", missingArgFallback)
    if item == (): return emptyFallback
    numeric = xc.atomize(p, item)
    if not isinstance(numeric,_NUM_TYPES): 
        if convertFallback is None:
            raise FunctionArgType(i,"numeric?")
        try:
            numeric = float(numeric)
        except ValueError:
            numeric = convertFallback
    return numeric
Beispiel #14
0
def anytypeArg(xc, args, i, type, missingArgFallback=None):
    if len(args) > i:
        item = args[i]
    else:
        item = missingArgFallback
    if hasattr(item, "__iter__") and not isinstance(item, str):
        if len(item) > 1: raise FunctionArgType(i, type)
        if len(item) == 0: return ()
        item = item[0]
    if isinstance(
            item,
            ModelObject.ModelObject) and not type.startswith("arelle:Model"):
        item = item.element
    return item
Beispiel #15
0
def nodeArg(xc, args, i, type, missingArgFallback=None, emptyFallback=None):
    item = anytypeArg(xc, args, i, type, missingArgFallback)
    if item == (): return emptyFallback
    if not isinstance(item, xml.dom.Node): raise FunctionArgType(i, type)
    return item
Beispiel #16
0
def nodeArg(xc, args, i, type, missingArgFallback=None, emptyFallback=None):
    item = anytypeArg(xc, args, i, type, missingArgFallback)
    if item == (): return emptyFallback
    if not isinstance(item, (ModelObject, ModelAttribute)):
        raise FunctionArgType(i, type, item)
    return item
Beispiel #17
0
def qnameArg(xc, p, args, i, type, missingArgFallback=None, emptyFallback=()):
    item = anytypeArg(xc, args, i, type, missingArgFallback)
    if item == (): return emptyFallback
    qn = xc.atomize(p, item)
    if not isinstance(qn, ModelValue.QName): raise FunctionArgType(i, type, qn)
    return qn