def relativeUri(self, uri): # return uri relative to this modelDocument uri return UrlUtil.relativeUri(self.uri, uri)
def logArguments(self, codes, msg, codedArgs): # determine logCode messageCode = None for argCode in codes if isinstance(codes,tuple) else (codes,): if (isinstance(argCode, ModelValue.QName) or (self.modelManager.disclosureSystem.EFM and argCode.startswith("EFM")) or (self.modelManager.disclosureSystem.GFM and argCode.startswith("GFM")) or (self.modelManager.disclosureSystem.HMRC and argCode.startswith("HMRC")) or (self.modelManager.disclosureSystem.SBRNL and argCode.startswith("SBR.NL")) or argCode[0:3] not in ("EFM", "GFM", "HMR", "SBR")): messageCode = argCode break # determine message and extra arguments fmtArgs = {} extras = {"messageCode":messageCode} for argName, argValue in codedArgs.items(): if argName in ("modelObject", "modelXbrl", "modelDocument"): try: entryUrl = self.modelDocument.uri except AttributeError: entryUrl = self.entryLoadingUrl try: objectUrl = argValue.modelDocument.uri except AttributeError: try: objectUrl = self.modelDocument.uri except AttributeError: objectUrl = self.entryLoadingUrl refs = [] for arg in (argValue if isinstance(argValue, (tuple,list)) else (argValue,)): if arg is not None: file = UrlUtil.relativeUri(entryUrl, objectUrl) ref = {} if isinstance(arg,ModelObject): ref["href"] = file + "#" + XmlUtil.elementFragmentIdentifier(arg) ref["sourceLine"] = arg.sourceline ref["objectId"] = arg.objectId() else: ref["href"] = file refs.append(ref) extras["refs"] = refs elif argName == "sourceLine": if isinstance(argValue, _INT_TYPES): # must be sortable with int's in logger extras["sourceLine"] = argValue elif argName != "exc_info": if isinstance(argValue, (ModelValue.QName, ModelObject, bool, FileNamedStringIO)): fmtArgs[argName] = str(argValue) elif isinstance(argValue, _INT_TYPES): # need locale-dependent formatting fmtArgs[argName] = format_string(self.modelManager.locale, '%i', argValue) elif isinstance(argValue,float): # need locale-dependent formatting fmtArgs[argName] = format_string(self.modelManager.locale, '%f', argValue) else: fmtArgs[argName] = argValue if "refs" not in extras: try: file = os.path.basename(self.modelDocument.uri) except AttributeError: try: file = os.path.basename(self.entryLoadingUrl) except: file = "" extras["refs"] = [{"href": file}] return (messageCode, (msg, fmtArgs) if fmtArgs else (msg,), extras)
def logArguments(self, codes, msg, codedArgs): # determine logCode messageCode = None for argCode in codes if isinstance(codes, tuple) else (codes, ): if (isinstance(argCode, ModelValue.QName) or (self.modelManager.disclosureSystem.EFM and argCode.startswith("EFM")) or (self.modelManager.disclosureSystem.GFM and argCode.startswith("GFM")) or (self.modelManager.disclosureSystem.HMRC and argCode.startswith("HMRC")) or (self.modelManager.disclosureSystem.SBRNL and argCode.startswith("SBR.NL")) or argCode[0:3] not in ("EFM", "GFM", "HMR", "SBR")): messageCode = argCode break # determine message and extra arguments fmtArgs = {} extras = {"messageCode": messageCode} for argName, argValue in codedArgs.items(): if argName in ("modelObject", "modelXbrl", "modelDocument"): try: entryUrl = self.modelDocument.uri except AttributeError: entryUrl = self.entryLoadingUrl refs = [] for arg in (argValue if isinstance(argValue, (tuple, list)) else (argValue, )): if arg is not None: if isinstance(arg, _STR_BASE): objectUrl = arg else: try: objectUrl = arg.modelDocument.uri except AttributeError: try: objectUrl = self.modelDocument.uri except AttributeError: objectUrl = self.entryLoadingUrl file = UrlUtil.relativeUri(entryUrl, objectUrl) ref = {} if isinstance(arg, ModelObject): ref["href"] = file + "#" + XmlUtil.elementFragmentIdentifier( arg) ref["sourceLine"] = arg.sourceline ref["objectId"] = arg.objectId() else: ref["href"] = file refs.append(ref) extras["refs"] = refs elif argName == "sourceLine": if isinstance( argValue, _INT_TYPES): # must be sortable with int's in logger extras["sourceLine"] = argValue elif argName != "exc_info": if isinstance( argValue, (ModelValue.QName, ModelObject, bool, FileNamedStringIO)): fmtArgs[argName] = str(argValue) elif isinstance(argValue, _INT_TYPES): # need locale-dependent formatting fmtArgs[argName] = format_string(self.modelManager.locale, '%i', argValue) elif isinstance(argValue, float): # need locale-dependent formatting fmtArgs[argName] = format_string(self.modelManager.locale, '%f', argValue) else: fmtArgs[argName] = argValue if "refs" not in extras: try: file = os.path.basename(self.modelDocument.uri) except AttributeError: try: file = os.path.basename(self.entryLoadingUrl) except: file = "" extras["refs"] = [{"href": file}] return (messageCode, (msg, fmtArgs) if fmtArgs else (msg, ), extras)
def relativeUri(self, uri): # return uri relative to this modelDocument uri return UrlUtil.relativeUri(self.uri, uri)
def logArguments(self, codes, msg, codedArgs): """ Prepares arguments for logger function as per info() below. If codes includes EFM, GFM, HMRC, or SBR-coded error then the code chosen (if a sequence) corresponds to whether EFM, GFM, HMRC, or SBR validation is in effect. """ def propValues(properties): # deref objects in properties return [(p[0],str(p[1])) if len(p) == 2 else (p[0],str(p[1]),propValues(p[2])) for p in properties if 2 <= len(p) <= 3] # determine logCode messageCode = None for argCode in codes if isinstance(codes,tuple) else (codes,): if (isinstance(argCode, ModelValue.QName) or (self.modelManager.disclosureSystem.EFM and argCode.startswith("EFM")) or (self.modelManager.disclosureSystem.GFM and argCode.startswith("GFM")) or (self.modelManager.disclosureSystem.HMRC and argCode.startswith("HMRC")) or (self.modelManager.disclosureSystem.SBRNL and argCode.startswith("SBR.NL")) or argCode[0:3] not in ("EFM", "GFM", "HMR", "SBR")): messageCode = argCode break # determine message and extra arguments fmtArgs = {} extras = {"messageCode":messageCode} logHrefObjectProperties = getattr(self.logger, "logHrefObjectProperties", False) for argName, argValue in codedArgs.items(): if argName in ("modelObject", "modelXbrl", "modelDocument"): try: entryUrl = self.modelDocument.uri except AttributeError: entryUrl = self.entryLoadingUrl refs = [] for arg in (argValue if isinstance(argValue, (tuple,list,set)) else (argValue,)): if arg is not None: if isinstance(arg, _STR_BASE): objectUrl = arg else: try: objectUrl = arg.modelDocument.uri except AttributeError: try: objectUrl = self.modelDocument.uri except AttributeError: objectUrl = self.entryLoadingUrl file = UrlUtil.relativeUri(entryUrl, objectUrl) ref = {} if isinstance(arg,ModelObject): ref["href"] = file + "#" + XmlUtil.elementFragmentIdentifier(arg) ref["sourceLine"] = arg.sourceline ref["objectId"] = arg.objectId() if logHrefObjectProperties: try: ref["properties"] = propValues(arg.propertyView) except AttributeError: pass # is a default properties entry appropriate or needed? else: ref["href"] = file try: ref["sourceLine"] = arg.sourceline except AttributeError: pass # arg may not have sourceline, ignore if so refs.append(ref) extras["refs"] = refs elif argName == "sourceLine": if isinstance(argValue, _INT_TYPES): # must be sortable with int's in logger extras["sourceLine"] = argValue elif argName != "exc_info": if isinstance(argValue, (ModelValue.QName, ModelObject, bool, FileNamedStringIO, # might be a set of lxml objects not dereferencable at shutdown tuple, list, set)): fmtArgs[argName] = str(argValue) elif argValue is None: fmtArgs[argName] = "(none)" elif isinstance(argValue, _INT_TYPES): # need locale-dependent formatting fmtArgs[argName] = format_string(self.modelManager.locale, '%i', argValue) elif isinstance(argValue,float): # need locale-dependent formatting fmtArgs[argName] = format_string(self.modelManager.locale, '%f', argValue) else: fmtArgs[argName] = argValue if "refs" not in extras: try: file = os.path.basename(self.modelDocument.uri) except AttributeError: try: file = os.path.basename(self.entryLoadingUrl) except: file = "" extras["refs"] = [{"href": file}] return (messageCode, (msg, fmtArgs) if fmtArgs else (msg,), extras)
def logArguments(self, codes, msg, codedArgs): # determine logCode messageCode = None for argCode in codes if isinstance(codes,tuple) else (codes,): if ((self.modelManager.disclosureSystem.EFM and argCode.startswith("EFM")) or (self.modelManager.disclosureSystem.GFM and argCode.startswith("GFM")) or (self.modelManager.disclosureSystem.HMRC and argCode.startswith("HMRC")) or (self.modelManager.disclosureSystem.SBRNL and argCode.startswith("SBR.NL")) or argCode[0:3] not in ("EFM", "GFM", "HMR", "SBR")): messageCode = argCode break # determine message and extra arguments fmtArgs = {} extras = {"messageCode":messageCode} for argName, argValue in codedArgs.items(): if argName in ("modelObject", "modelXbrl", "modelDocument"): try: entryUrl = self.modelDocument.uri except AttributeError: entryUrl = self.entryLoadingUrl try: objectUrl = argValue.modelDocument.uri except AttributeError: try: objectUrl = self.modelDocument.uri except AttributeError: objectUrl = self.entryLoadingUrl file = UrlUtil.relativeUri(entryUrl, objectUrl) extras["file"] = file if isinstance(argValue,ModelObject): extras["href"] = file + "#" + XmlUtil.elementFragmentIdentifier(argValue) extras["sourceLine"] = argValue.sourceline extras["objectId"] = argValue.objectId() else: extras["href"] = file extras["sourceLine"] = "" elif argName == "sourceLine": extras["sourceLine"] = argValue elif argName != "exc_info": if isinstance(argValue, (ModelValue.QName, ModelObject, bool)): fmtArgs[argName] = str(argValue) elif isinstance(argValue,int): # need locale-dependent formatting fmtArgs[argName] = format_string(self.modelManager.locale, '%i', argValue) elif isinstance(argValue,float): # need locale-dependent formatting fmtArgs[argName] = format_string(self.modelManager.locale, '%f', argValue) else: fmtArgs[argName] = argValue if "href" not in extras: try: file = os.path.basename(self.modelDocument.uri) except AttributeError: try: file = os.path.basename(self.entryLoadingUrl) except: file = "" extras["file"] = file extras["href"] = file extras["sourceLine"] = "" return (messageCode, (msg, fmtArgs) if fmtArgs else (msg,), extras)