def compile(self):
     if not hasattr(self, "relationshipSourceQnameExpressionProg"):
         self.relationshipSourceQnameExpressionProg = XPathParser.parse(self, self.relationshipSourceQnameExpression, self, "relationshipSourceQnameExpressionProg", Trace.VARIABLE)
         self.linkroleExpressionProg = XPathParser.parse(self, self.linkroleExpression, self, "linkroleQnameExpressionProg", Trace.VARIABLE)
         self.axisExpressionProg = XPathParser.parse(self, self.axisExpression, self, "axisExpressionProg", Trace.VARIABLE)
         self.generationsExpressionProg = XPathParser.parse(self, self.generationsExpression, self, "generationsExpressionProg", Trace.VARIABLE)
         super(ModelRelationshipDefinitionNode, self).compile()
Exemple #2
0
def executeCallTest(val, name, callTuple, testTuple):
    if callTuple:
        XPathParser.initializeParser(val)
        
        try:                            
            val.modelXbrl.modelManager.showStatus(_("Executing call"))
            callExprStack = XPathParser.parse(val, callTuple[0], callTuple[1], name + " call", Trace.CALL)
            xpathContext = XPathContext.create(val.modelXbrl, sourceElement=callTuple[1])
            result = xpathContext.evaluate(callExprStack)
            xpathContext.inScopeVars[qname('result',noPrefixIsNoNamespace=True)] = result 
            val.modelXbrl.error( _("{0} result {1}").format( name, result),
                "info", "formula:trace")
            
            if testTuple:
                val.modelXbrl.modelManager.showStatus(_("Executing test"))
                testExprStack = XPathParser.parse(val, testTuple[0], testTuple[1], name + " test", Trace.CALL)
                testResult = xpathContext.effectiveBooleanValue( None, xpathContext.evaluate(testExprStack) )
                
                val.modelXbrl.error(
                    _("Test {0} result {1}").format( name, testResult), 
                    "info" if testResult else "err", 
                    "cfcn:testPass" if testResult else "cfcn:testFail")
        except XPathContext.XPathException as err:
            val.modelXbrl.error(
                _("{0} evaluation error: {1} \n{2}").format(name,
                     err.message, err.sourceErrorIndication), 
                "err", err.code)

        val.modelXbrl.modelManager.showStatus(_("ready"), 2000)
Exemple #3
0
def executeCallTest(val, name, callTuple, testTuple):
    if callTuple:
        XPathParser.initializeParser(val)

        try:
            val.modelXbrl.modelManager.showStatus(_("Executing call"))
            callExprStack = XPathParser.parse(val, callTuple[0], callTuple[1],
                                              name + " call", Trace.CALL)
            xpathContext = XPathContext.create(val.modelXbrl,
                                               sourceElement=callTuple[1])
            result = xpathContext.evaluate(callExprStack)
            xpathContext.inScopeVars[qname(
                'result', noPrefixIsNoNamespace=True)] = result
            val.modelXbrl.error(
                _("{0} result {1}").format(name, result), "info",
                "formula:trace")

            if testTuple:
                val.modelXbrl.modelManager.showStatus(_("Executing test"))
                testExprStack = XPathParser.parse(val, testTuple[0],
                                                  testTuple[1], name + " test",
                                                  Trace.CALL)
                testResult = xpathContext.effectiveBooleanValue(
                    None, xpathContext.evaluate(testExprStack))

                val.modelXbrl.error(
                    _("Test {0} result {1}").format(name, testResult),
                    "info" if testResult else "err",
                    "cfcn:testPass" if testResult else "cfcn:testFail")
        except XPathContext.XPathException as err:
            val.modelXbrl.error(
                _("{0} evaluation error: {1} \n{2}").format(
                    name, err.message, err.sourceErrorIndication), "err",
                err.code)

        val.modelXbrl.modelManager.showStatus(_("ready"), 2000)
Exemple #4
0
 def ok(self, event=None):
     trName = self.trNameName.value
     sourceValue = self.sourceVar.get()
     try:
         self.modelXbrl.modelManager.showStatus(_("Executing call"))
         elt = self.modelXbrl.modelDocument.xmlRootElement
         callExprStack = XPathParser.parse(
             self.validator, '{}("{}")'.format(trName, sourceValue), elt,
             trName + " call", Trace.CALL)
         xpathContext = XPathContext.create(self.modelXbrl,
                                            sourceElement=elt)
         result = xpathContext.evaluate(callExprStack)
         while result and isinstance(result, (tuple, list, set)):
             result = next(iter(result))  # de-sequence result
         self.resultVar.set(str(result))
     except XPathContext.XPathException as err:
         self.resultVar.set(str(err))
         self.modelXbrl.error(err.code, err.message)
Exemple #5
0
 def transform(self, trReg, trName, sourceValue):
     try:                            
         trNS = self.trPrefixNSs[trReg]
         trPrefix = trReg.split()[0] # for ixt remove TRn part
         setXmlns(self.modelXbrl.modelDocument, trPrefix, trNS)
         self.modelXbrl.modelManager.showStatus(_("Executing call"))
         elt = self.modelXbrl.modelDocument.xmlRootElement
         if ':' in trName:
             prefixedFnName = trName
         else:
             prefixedFnName = "{}:{}".format(trPrefix, trName)
         callExprStack = XPathParser.parse(self.validator, 
                                           '{}("{}")'.format(prefixedFnName, sourceValue),
                                           elt, trName + " call", Trace.CALL)
         xpathContext = XPathContext.create(self.modelXbrl, sourceElement=elt)
         result = xpathContext.evaluate(callExprStack)
         while result and isinstance(result, (tuple,list,set)):
             result = next(iter(result)) # de-sequence result
         return result
     except XPathContext.XPathException as err:
         self.modelXbrl.error(err.code, err.message)
         return err
Exemple #6
0
    def backgroundFind(self, expr, logViewLines):
        exprType = self.options["exprType"]
        inConceptLabel = self.options["conceptLabel"]
        inConceptName = self.options["conceptName"]
        inConceptType = self.options["conceptType"]
        inConceptSubs = self.options["conceptSubs"]
        inConceptPer = self.options["conceptPer"]
        inConceptBal = self.options["conceptBal"]
        inFactLabel = self.options["factLabel"]
        inFactName = self.options["factName"]
        inFactValue = self.options["factValue"]
        inFactCntx = self.options["factCntx"]
        inFactUnit = self.options["factUnit"]
        inMessagesLog = self.options["messagesLog"]
        nextIsDown = self.options["direction"] == "down"

        objsFound = set()

        try:
            if exprType == "text":
                # escape regex metacharacters
                pattern = re.compile(
                    ''.join([(('\\' + c) if c in reMetaChars else c)
                             for c in expr]), re.IGNORECASE)
                isRE = True
                isXP = False
            elif exprType == "regex":
                pattern = re.compile(expr, re.IGNORECASE)
                isRE = True
                isXP = False
            elif exprType == "xpath":
                isRE = False
                isXP = True
                self.resultText.setValue(_("Compiling xpath expression..."))
                XPathParser.initializeParser(self.modelManager)
                self.modelManager.showStatus(
                    _("Compiling xpath expression..."))
                xpProg = XPathParser.parse(
                    self, expr, XPathParser.staticExpressionFunctionContext(),
                    "find expression", Trace.CALL)
                xpCtx = XPathContext.create(self.modelXbrl, sourceElement=None)

            else:
                return  # nothing to do

            if inMessagesLog:
                for lineNumber, line in enumerate(logViewLines):
                    if pattern.search(line):
                        objsFound.add(lineNumber)
            elif self.modelXbrl.modelDocument.type == ModelDocument.Type.RSSFEED:
                for rssItem in self.modelXbrl.modelDocument.items:
                    if any(
                            pattern.search(str(value))
                            for name, value in rssItem.propertyView):
                        objsFound.add(rssItem)
            else:  # DTS search
                if inConceptLabel or inConceptName or inConceptType or inConceptSubs or inConceptPer or inConceptBal:
                    self.modelManager.cntlr.uiThreadQueue.put(
                        (self.resultText.setValue, [_("Matching concepts...")
                                                    ]))
                    self.modelManager.showStatus(_("Matching concepts..."))
                    for conceptName, concepts in self.modelXbrl.nameConcepts.items(
                    ):
                        for concept in concepts:
                            if ((isXP and xpCtx.evaluateBooleanValue(
                                    xpProg, contextItem=concept.qname)) or
                                (isRE and
                                 (inConceptLabel
                                  and pattern.search(concept.label())) or
                                 (inConceptName
                                  and pattern.search(conceptName)) or
                                 (inConceptType
                                  and pattern.search(str(concept.typeQname)))
                                 or (inConceptSubs and pattern.search(
                                     str(concept.substitutionGroupQname))) or
                                 (inConceptPer and concept.periodType
                                  and pattern.search(concept.periodType)) or
                                 (inConceptBal and concept.balance
                                  and pattern.search(concept.balance)))):
                                objsFound.add(concept)
                if inFactLabel or inFactName or inFactValue or inFactCntx or inFactUnit:
                    self.modelManager.cntlr.uiThreadQueue.put(
                        (self.resultText.setValue, [_("Matching facts...")]))
                    self.modelManager.showStatus(_("Matching facts..."))
                    for fact in self.modelXbrl.facts:
                        if ((isXP and xpCtx.evaluateBooleanValue(
                                xpProg, contextItem=fact)) or
                            (isRE and
                             (inFactName and pattern.search(fact.concept.name)
                              or (inFactLabel
                                  and pattern.search(fact.concept.label())) or
                              (inFactValue and pattern.search(fact.value)) or
                              (inFactCntx and pattern.search(
                                  XmlUtil.innerText(fact.context.element))) or
                              (inFactUnit and pattern.search(
                                  XmlUtil.innerText(fact.unit.element)))))):
                            objsFound.add(fact)
        except XPathContext.XPathException as err:
            err = _("Find expression error: {0} \n{1}").format(
                err.message, err.sourceErrorIndication)
            self.modelManager.addToLog(err)
            self.modelManager.cntlr.uiThreadQueue.put(
                (self.resultText.setValue, [err]))
            self.modelManager.showStatus(_("Completed with errors"), 5000)

        numConcepts = 0
        numFacts = 0
        numRssItems = 0
        numMessages = 0
        self.objsList = []
        for obj in objsFound:
            if inMessagesLog:
                numMessages += 1
                self.objsList.append(('m', "{0:06}".format(obj), obj))
            elif isinstance(obj, ModelConcept):
                numConcepts += 1
                self.objsList.append(('c', obj.localName, obj.objectId()))
            elif isinstance(obj, ModelFact):
                numFacts += 1
                self.objsList.append(('f', obj.__hash__(), obj.objectId()))
            elif isinstance(obj, ModelRssItem):
                numRssItems += 1
                self.objsList.append(('r', obj.__hash__(), obj.objectId()))
        self.objsList.sort()
        self.result = "Found "
        if numConcepts:
            self.result += "{0} concepts".format(numConcepts)
            if numFacts: self.result += ", "
        if numFacts:
            self.result += "{0} facts".format(numFacts)
        if numRssItems:
            self.result += "{0} RSS items".format(numRssItems)
        if numMessages:
            self.result += "{0} Messages".format(numMessages)
        if numConcepts + numFacts + numRssItems + numMessages == 0:
            self.result += "no matches"
            self.foundIndex = -1
            self.modelManager.cntlr.uiThreadQueue.put(
                (self.resultText.setValue, [self.result]))
        else:
            self.foundIndex = 0 if nextIsDown else (len(self.objsList) - 1)
            self.modelManager.cntlr.uiThreadQueue.put((self.next, []))
        self.modelManager.showStatus(_("Ready..."), 2000)
Exemple #7
0
    def backgroundFind(self, expr, logViewLines):
        exprType = self.options["exprType"]
        inConceptLabel = self.options["conceptLabel"]
        inConceptName = self.options["conceptName"]
        inConceptType = self.options["conceptType"]
        inConceptSubs = self.options["conceptSubs"]
        inConceptPer = self.options["conceptPer"]
        inConceptBal = self.options["conceptBal"]
        inFactLabel = self.options["factLabel"]
        inFactName = self.options["factName"]
        inFactValue = self.options["factValue"]
        inFactCntx = self.options["factCntx"]
        inFactUnit = self.options["factUnit"]
        inMessagesLog = self.options["messagesLog"]
        nextIsDown = self.options["direction"] == "down"
        
        objsFound = set()
        
        try:
            if exprType == "text":
                # escape regex metacharacters
                pattern = re.compile(''.join(
                         [(('\\' + c) if c in reMetaChars else c) for c in expr]), 
                         re.IGNORECASE)
                isRE = True
                isXP = False
            elif exprType == "regex":
                pattern = re.compile(expr, re.IGNORECASE)
                isRE = True
                isXP = False
            elif exprType == "xpath":
                isRE = False
                isXP = True
                self.resultText.setValue(_("Compiling xpath expression..."))
                XPathParser.initializeParser(self)
                self.modelManager.showStatus(_("Compiling xpath expression..."))
                xpProg= XPathParser.parse(self, 
                                          expr, 
                                          XPathParser.staticExpressionFunctionContext(), 
                                          "find expression", 
                                          Trace.CALL)
                xpCtx = XPathContext.create(self.modelXbrl, sourceElement=None)

            else:
                return  # nothing to do
            
            if inMessagesLog:
                for lineNumber, line in enumerate(logViewLines):
                    if pattern.search(line):
                        objsFound.add(lineNumber)
            elif self.modelXbrl.modelDocument.type == ModelDocument.Type.RSSFEED:
                for rssItem in self.modelXbrl.modelDocument.items:
                    if any(pattern.search(str(value)) for name, value in rssItem.propertyView):
                        objsFound.add(rssItem)  
            else: # DTS search
                if inConceptLabel or inConceptName or inConceptType or inConceptSubs or inConceptPer or inConceptBal:
                    self.modelManager.cntlr.uiThreadQueue.put((self.resultText.setValue, [_("Matching concepts...")]))
                    self.modelManager.showStatus(_("Matching concepts..."))
                    for conceptName, concepts in self.modelXbrl.nameConcepts.items():
                        for concept in concepts:
                            if ((isXP and xpCtx.evaluateBooleanValue(xpProg, contextItem=concept.qname)) or
                                (isRE and
                                 (inConceptLabel and pattern.search(concept.label())) or
                                 (inConceptName and pattern.search(conceptName)) or
                                 (inConceptType and pattern.search(str(concept.typeQname))) or
                                 (inConceptSubs and pattern.search(str(concept.substitutionGroupQname))) or
                                 (inConceptPer and concept.periodType and pattern.search(concept.periodType)) or
                                 (inConceptBal and concept.balance and pattern.search(concept.balance))
                                 )
                                ):
                                objsFound.add(concept)  
                if inFactLabel or inFactName or inFactValue or inFactCntx or inFactUnit:
                    self.modelManager.cntlr.uiThreadQueue.put((self.resultText.setValue, [_("Matching facts...")]))
                    self.modelManager.showStatus(_("Matching facts..."))
                    for fact in self.modelXbrl.facts:
                        if ((isXP and xpCtx.evaluateBooleanValue(xpProg, contextItem=fact)) or
                            (isRE and
                             (inFactName and pattern.search(fact.concept.name) or
                             (inFactLabel and pattern.search(fact.concept.label())) or
                             (inFactValue and pattern.search(fact.value)) or
                             (inFactCntx and pattern.search(XmlUtil.innerText(fact.context.element))) or
                             (inFactUnit and pattern.search(XmlUtil.innerText(fact.unit.element))))
                             )
                            ):
                            objsFound.add(fact)
        except XPathContext.XPathException as err:
            err = _("Find expression error: {0} \n{1}").format(err.message, err.sourceErrorIndication)
            self.modelManager.addToLog(err)
            self.modelManager.cntlr.uiThreadQueue.put((self.resultText.setValue, [err]))
            self.modelManager.showStatus(_("Completed with errors"), 5000)
                            
        numConcepts = 0
        numFacts = 0
        numRssItems = 0
        numMessages = 0
        self.objsList = []
        for obj in objsFound:
            if inMessagesLog:
                numMessages += 1
                self.objsList.append( ('m', "{0:06}".format(obj), obj) )
            elif isinstance(obj,ModelConcept):
                numConcepts += 1
                self.objsList.append( ('c', obj.localName, obj.objectId()) )
            elif isinstance(obj,ModelFact):
                numFacts += 1
                self.objsList.append( ('f', obj.__hash__(), obj.objectId()) )
            elif isinstance(obj,ModelRssItem):
                numRssItems += 1
                self.objsList.append( ('r', obj.__hash__(), obj.objectId()) )
        self.objsList.sort()
        self.result = "Found "
        if numConcepts:
            self.result += "{0} concepts".format(numConcepts)
            if numFacts: self.result += ", "
        if numFacts:
            self.result += "{0} facts".format(numFacts)
        if numRssItems:
            self.result += "{0} RSS items".format(numRssItems)
        if numMessages:
            self.result += "{0} Messages".format(numMessages)
        if numConcepts + numFacts + numRssItems + numMessages == 0:
            self.result += "no matches"
            self.foundIndex = -1
            self.modelManager.cntlr.uiThreadQueue.put((self.resultText.setValue, [self.result]))
        else:
            self.foundIndex = 0 if nextIsDown else (len(self.objsList) - 1)
            self.modelManager.cntlr.uiThreadQueue.put((self.next, []))
        self.modelManager.showStatus(_("Ready..."), 2000)
 def compile(self):
     if not hasattr(self, "dimensionQnameExpressionProg"):
         self.dimensionQnameExpressionProg = XPathParser.parse(self, self.dimensionQnameExpression, self, "dimensionQnameExpressionProg", Trace.VARIABLE)
         super(ModelDimensionRelationshipDefinitionNode, self).compile()
 def compile(self):
     if not hasattr(self, "arcroleExpressionProg"):
         self.arcroleExpressionProg = XPathParser.parse(self, self.arcroleExpression, self, "arcroleExpressionProg", Trace.VARIABLE)
         self.linkQnameExpressionProg = XPathParser.parse(self, self.linkQnameExpression, self, "linkQnameExpressionProg", Trace.VARIABLE)
         self.arcQnameExpressionProg = XPathParser.parse(self, self.arcQnameExpression, self, "arcQnameExpressionProg", Trace.VARIABLE)
         super(ModelConceptRelationshipDefinitionNode, self).compile()
 def compile(self):
     if not hasattr(self, "valueProg"):
         value = self.valueExpression
         self.valueProg = XPathParser.parse(self, value, self, "value", Trace.VARIABLE)
     # duplicates formula resource for RuleAxis but not for other subclasses
     super(ModelDefinitionNode, self).compile()
 def compile(self):
     if not hasattr(self, "selectProg"):
         self.selectProg = XPathParser.parse(self, self.select, self, "select", Trace.PARAMETER)
         super(ModelSelectionDefinitionNode, self).compile()