本文整理汇总了Python中arelle.UrlUtil类的典型用法代码示例。如果您正苦于以下问题:Python UrlUtil类的具体用法?Python UrlUtil怎么用?Python UrlUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UrlUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: base_uri
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 ''
示例2: resolveUri
def resolveUri(self, hrefObject=None, uri=None, dtsModelXbrl=None):
if dtsModelXbrl is None:
dtsModelXbrl = self.modelXbrl
doc = None
if hrefObject:
hrefElt,doc,id = hrefObject
elif uri:
from arelle import UrlUtil
url, id = UrlUtil.splitDecodeFragment(uri)
if url == "":
doc = self.modelDocument
else:
normalizedUrl = self.modelXbrl.modelManager.cntlr.webCache.normalizeUrl(
url,
self.modelDocument.baseForElement(self))
doc = dtsModelXbrl.urlDocs.get(normalizedUrl)
from arelle import ModelDocument
if isinstance(doc, ModelDocument.ModelDocument):
if id is None:
return doc
elif id in doc.idObjects:
return doc.idObjects[id]
else:
from arelle.XmlUtil import xpointerElement
xpointedElement = xpointerElement(doc,id)
# find element
for docModelObject in doc.modelObjects:
if docModelObject == xpointedElement:
doc.idObjects[id] = docModelObject # cache for reuse
return docModelObject
return None
示例3: checkConcept
def checkConcept(val, concept):
if concept.element.hasAttributeNS(XbrlConst.xbrldt, "typedDomainRef"):
if concept.isDimensionItem:
typedDomainElement = concept.typedDomainElement
if typedDomainElement is None:
url, id = UrlUtil.splitDecodeFragment(concept.element.getAttributeNS(XbrlConst.xbrldt, "typedDomainRef"))
if len(id) == 0:
val.modelXbrl.error(
_("Concept {0} typedDomainRef has no fragment identifier").format(
concept.qname),
"err", "xbrldte:TypedDimensionURIError")
else:
val.modelXbrl.error(
_("Concept {0} typedDomainRef is not resolved").format(
concept.qname),
"err", "xbrldte:OutOfDTSSchemaError")
elif not isinstance(typedDomainElement, ModelObject.ModelConcept) or \
not typedDomainElement.isGlobalDeclaration or \
typedDomainElement.abstract == "true":
val.modelXbrl.error(
_("Concept {0} typedDomainRef must identify a non-abstract element").format(
concept.qname),
"err", "xbrldte:TypedDimensionError")
else:
val.modelXbrl.error(
_("Concept {0} is not a dimension item but has a typedDomainRef").format(
concept.qname),
"err", "xbrldte:TypedDomainRefError")
示例4: loadStandardTaxonomiesDict
def loadStandardTaxonomiesDict(self):
if self.selection:
self.standardTaxonomiesDict = {}
self.standardLocalHrefs = set()
self.standardAuthorities = set()
if not self.standardTaxonomiesUrl:
return
basename = os.path.basename(self.standardTaxonomiesUrl)
self.modelManager.cntlr.showStatus(_("parsing {0}").format(basename))
try:
for file in (self.modelManager.cntlr.webCache.getfilename(self.standardTaxonomiesUrl),
os.path.join(self.modelManager.cntlr.configDir,"xbrlschemafiles.xml")):
xmldoc = etree.parse(file)
for locElt in xmldoc.iter(tag="Loc"):
href = None
localHref = None
namespaceUri = None
attType = None
family = None
for childElt in locElt.iterchildren():
ln = childElt.tag
value = childElt.text.strip()
if ln == "Href":
href = value
elif ln == "LocalHref":
localHref = value
elif ln == "Namespace":
namespaceUri = value
elif ln == "AttType":
attType = value
elif ln == "Family":
family = value
if href:
if namespaceUri and (attType == "SCH" or attType == "ENT"):
if namespaceUri not in self.standardTaxonomiesDict:
self.standardTaxonomiesDict[namespaceUri] = (href, localHref)
authority = UrlUtil.authority(namespaceUri)
self.standardAuthorities.add(authority)
if family == "BASE":
self.baseTaxonomyNamespaces.add(namespaceUri)
if href not in self.standardTaxonomiesDict:
self.standardTaxonomiesDict[href] = "Allowed" + attType
if localHref:
self.standardLocalHrefs.add(localHref)
elif attType == "SCH" and family == "BASE":
self.baseTaxonomyNamespaces.add(namespaceUri)
except (EnvironmentError,
etree.LxmlError) as err:
self.modelManager.cntlr.addToLog("{0}: import error: {1}".format(basename,err))
etree.clear_error_log()
示例5: discoverHref
def discoverHref(self, element, nonDTS=False):
if element.hasAttributeNS(XbrlConst.xlink, "href"):
url, id = UrlUtil.splitDecodeFragment(element.getAttributeNS(XbrlConst.xlink, "href"))
if url == "":
doc = self
else:
doc = load(self.modelXbrl, url, base=self.baseForElement(element))
if not nonDTS and doc is not None and self.referencesDocument.get(doc) is None:
self.referencesDocument[doc] = "href"
doc.inDTS = doc.type != Type.Unknown # non-XBRL document is not in DTS
href = (element, doc, id if len(id) > 0 else None)
self.hrefObjects.append(href)
return href
return None
示例6: insertFiling
def insertFiling(self, rssItem, g):
self.showStatus("insert filing")
# accession graph -> document vertices
new_filing = {'documents': []}
if self.modelXbrl.modelDocument.creationSoftwareComment:
new_filing['creation_software'] = self.modelXbrl.modelDocument.creationSoftwareComment
datetimeNow = datetime.datetime.now()
datetimeNowStr = XmlUtil.dateunionValue(datetimeNow)
entryUri = modelObjectDocumentUri(self.modelXbrl)
if rssItem is not None: # sec accession
# set self.
new_filing['filingType'] = "SEC filing"
# for an RSS Feed entry from SEC, use rss item's accession information
new_filing['filingNumber'] = filingNumber = rssItem.accessionNumber
new_filing['acceptedTimestamp'] = XmlUtil.dateunionValue(rssItem.acceptanceDatetime)
new_filing['filingDate'] = XmlUtil.dateunionValue(rssItem.filingDate)
new_filing['entityId'] = rssItem.cikNumber
new_filing['entityName'] = rssItem.companyName
new_filing['SICCode'] = rssItem.assignedSic
new_filing['SECHtmlUrl'] = rssItem.htmlUrl
new_filing['entryUrl'] = rssItem.url
self.filingURI = rssItem.htmlUrl
else:
# not an RSS Feed item, make up our own accession ID (the time in seconds of epoch)
intNow = int(time.time())
new_filing['filingNumber'] = filingNumber = str(intNow)
self.filingId = int(time.time()) # only available if entered from an SEC filing
new_filing['filingType'] = "independent filing"
new_filing['acceptedTimestamp'] = datetimeNowStr
new_filing['filingDate'] = datetimeNowStr
new_filing['entryUrl'] = UrlUtil.ensureUrl(self.modelXbrl.fileSource.url)
self.filingURI = filingNumber
g[FILINGS][self.filingURI] = new_filing
self.filing = new_filing
# for now only one report per filing (but SEC may have multiple in future, such as form SD)
self.reportURI = modelObjectDocumentUri(self.modelXbrl)
self.report = {'filing': self.filingURI,
'aspectProxies': {},
'relationshipSets': {},
'dataPoints': {},
'messages': {}}
new_filing['reports'] = {self.reportURI: self.report}
# relationshipSets are a dts property
self.relationshipSets = [(arcrole, ELR, linkqname, arcqname)
for arcrole, ELR, linkqname, arcqname in self.modelXbrl.baseSets.keys()
if ELR and (arcrole.startswith("XBRL-") or (linkqname and arcqname))]
示例7: resolveHtmlUri
def resolveHtmlUri(elt, name, value):
if name == "archive": # URILIST
return " ".join(resolveHtmlUri(elt, None, v) for v in value.split(" "))
if not UrlUtil.isAbsolute(value) and not value.startswith("/"):
if elt.modelDocument.htmlBase is not None:
value = elt.modelDocument.htmlBase + value
# canonicalize ../ and ./
scheme, sep, pathpart = value.rpartition("://")
if sep:
pathpart = pathpart.replace('\\','/')
endingSep = '/' if pathpart[-1] == '/' else '' # normpath drops ending directory separator
_uri = scheme + "://" + posixpath.normpath(pathpart) + endingSep
else:
_uri = posixpath.normpath(value)
return _uri # .replace(" ", "%20") requirement for this is not yet clear
示例8: loadStandardTaxonomiesDict
def loadStandardTaxonomiesDict(self):
if self.selection:
self.standardTaxonomiesDict = {}
self.standardAuthorities = set()
if not self.standardTaxonomiesUrl:
return
basename = os.path.basename(self.standardTaxonomiesUrl)
self.modelManager.cntlr.showStatus(_("parsing {0}").format(basename))
try:
for file in (self.modelManager.cntlr.webCache.getfilename(self.standardTaxonomiesUrl),
os.path.join(self.modelManager.cntlr.configDir,"xbrlschemafiles.xml")):
xmldoc = xml.dom.minidom.parse(file)
for locElt in xmldoc.getElementsByTagName("Loc"):
href = None
localHref = None
namespaceUri = None
attType = None
family = None
for childElt in locElt.childNodes:
if childElt.nodeType == 1: #element
ln = childElt.localName
value = XmlUtil.innerText(childElt)
if ln == "Href":
href = value
elif ln == "LocalHref":
localHref = value
elif ln == "Namespace":
namespaceUri = value
elif ln == "AttType":
attType = value
elif ln == "Family":
family = value
if href:
if namespaceUri and (attType == "SCH" or attType == "ENT"):
if namespaceUri not in self.standardTaxonomiesDict:
self.standardTaxonomiesDict[namespaceUri] = (href, localHref)
authority = UrlUtil.authority(namespaceUri)
self.standardAuthorities.add(authority)
if family == "BASE":
self.baseTaxonomyNamespaces.add(namespaceUri)
if href not in self.standardTaxonomiesDict:
self.standardTaxonomiesDict[href] = "Allowed" + attType
except (EnvironmentError,
xml.parsers.expat.ExpatError,
xml.dom.DOMException) as err:
self.modelManager.cntlr.addToLog("{0}: import error: {1}".format(basename,err))
示例9: discoverHref
def discoverHref(self, element, nonDTS=False):
href = element.get("{http://www.w3.org/1999/xlink}href")
if href:
url, id = UrlUtil.splitDecodeFragment(href)
if url == "":
doc = self
else:
# href discovery only can happein within a DTS
doc = load(self.modelXbrl, url, isDiscovered=not nonDTS, base=self.baseForElement(element), referringElement=element)
if not nonDTS and doc is not None and self.referencesDocument.get(doc) is None:
self.referencesDocument[doc] = "href"
if not doc.inDTS and doc.type != Type.Unknown: # non-XBRL document is not in DTS
doc.inDTS = True # now known to be discovered
if doc.type == Type.SCHEMA: # schema coming newly into DTS
doc.schemaDiscoverChildElements(doc.xmlRootElement)
href = (element, doc, id if len(id) > 0 else None)
self.hrefObjects.append(href)
return href
return None
示例10: doc
def doc(xc, p, contextItem, args):
if len(args) != 1: raise XPathContext.FunctionNumArgs()
uri = stringArg(xc, args, 0, "xs:string", emptyFallback=None)
if uri is None:
return ()
if xc.progHeader is None or xc.progHeader.element is None:
raise XPathContext.XPathException(p, 'err:FODC0005', _('Function xf:doc no formula resource element for {0}').format(uri))
if not UrlUtil.isValid(uri):
raise XPathContext.XPathException(p, 'err:FODC0005', _('Function xf:doc $uri is not valid {0}').format(uri))
normalizedUri = xc.modelXbrl.modelManager.cntlr.webCache.normalizeUrl(
uri,
xc.progHeader.element.modelDocument.baseForElement(xc.progHeader.element))
if normalizedUri in xc.modelXbrl.urlDocs:
return xc.modelXbrl.urlDocs[normalizedUri].xmlDocument
modelDocument = ModelDocument.load(xc.modelXbrl, normalizedUri)
if modelDocument is None:
raise XPathContext.XPathException(p, 'err:FODC0005', _('Function xf:doc $uri not successfully loaded {0}').format(uri))
# assure that document is validated
XmlValidate.validate(xc.modelXbrl, modelDocument.xmlRootElement)
return modelDocument.xmlDocument
示例11: resolveUri
def resolveUri(self, hrefObject=None, uri=None, dtsModelXbrl=None):
"""Returns the modelObject within modelDocment that resolves a URI based on arguments relative
to this element
:param hrefObject: an optional tuple of (hrefElement, modelDocument, id), or
:param uri: An (element scheme pointer), and dtsModelXbrl (both required together if for a multi-instance href)
:type uri: str
:param dtsModelXbrl: DTS of href resolution (default is the element's own modelXbrl)
:type dtsModelXbrl: ModelXbrl
:returns: ModelObject -- Document node corresponding to the href or resolved uri
"""
if dtsModelXbrl is None:
dtsModelXbrl = self.modelXbrl
doc = None
if hrefObject:
hrefElt,doc,id = hrefObject
elif uri:
from arelle import UrlUtil
url, id = UrlUtil.splitDecodeFragment(uri)
if url == "":
doc = self.modelDocument
else:
normalizedUrl = self.modelXbrl.modelManager.cntlr.webCache.normalizeUrl(
url,
self.modelDocument.baseForElement(self))
doc = dtsModelXbrl.urlDocs.get(normalizedUrl)
from arelle import ModelDocument
if isinstance(doc, ModelDocument.ModelDocument):
if id is None:
return doc
elif id in doc.idObjects:
return doc.idObjects[id]
else:
from arelle.XmlUtil import xpointerElement
xpointedElement = xpointerElement(doc,id)
# find element
for docModelObject in doc.xmlRootElement.iter():
if docModelObject == xpointedElement:
doc.idObjects[id] = docModelObject # cache for reuse
return docModelObject
return None
示例12: identifyPreexistingDocuments
def identifyPreexistingDocuments(self):
self.existingDocumentUris = set()
if not self.isJsonFile:
docFilters = []
for modelDocument in self.modelXbrl.urlDocs.values():
if modelDocument.type == Type.SCHEMA:
docFilters.append('STR(?doc) = "{}"'.format(UrlUtil.ensureUrl(modelDocument.uri)))
results = self.execute(
# TBD: fix up for Mongo DB query
"select",
query="""
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX DTS: <http://xbrl.org/2013/rdf/DTS/>
SELECT distinct ?doc WHERE { ?doc rdf:type DTS:Document
FILTER( """ + '\n|| '.join(docFilters) + ") .}")
try:
for result in results['results']['bindings']:
doc = result['doc']
if doc.get('type') == 'uri':
self.existingDocumentUris.add(doc['value'])
except KeyError:
pass # no existingDocumentUris
示例13: checkConcept
def checkConcept(val, concept):
if concept.get("{http://xbrl.org/2005/xbrldt}typedDomainRef"):
if concept.isDimensionItem:
typedDomainElement = concept.typedDomainElement
if typedDomainElement is None:
url, id = UrlUtil.splitDecodeFragment(concept.get("{http://xbrl.org/2005/xbrldt}typedDomainRef"))
if len(id) == 0:
val.modelXbrl.error(
"xbrldte:TypedDimensionURIError",
_("Concept %(concept)s typedDomainRef has no fragment identifier"),
modelObject=concept,
concept=concept.qname,
)
else:
val.modelXbrl.error(
"xbrldte:OutOfDTSSchemaError",
_("Concept %(concept)s typedDomainRef is not resolved"),
modelObject=concept,
concept=concept.qname,
)
elif (
not isinstance(typedDomainElement, ModelConcept)
or not typedDomainElement.isGlobalDeclaration
or typedDomainElement.abstract == "true"
):
val.modelXbrl.error(
"xbrldte:TypedDimensionError",
_("Concept %(concept)s typedDomainRef must identify a non-abstract element"),
modelObject=concept,
concept=concept.qname,
)
else:
val.modelXbrl.error(
"xbrldte:TypedDomainRefError",
_("Concept %(concept)s is not a dimension item but has a typedDomainRef"),
modelObject=concept,
concept=concept.qname,
)
示例14: relativeUri
def relativeUri(self, uri): # return uri relative to this modelDocument uri
return UrlUtil.relativeUri(self.uri, uri)
示例15: checkDTS
def checkDTS(val, modelDocument, visited):
global targetNamespaceDatePattern, efmFilenamePattern, roleTypePattern, arcroleTypePattern, \
arcroleDefinitionPattern, namePattern, linkroleDefinitionBalanceIncomeSheet, \
namespacesConflictPattern
if targetNamespaceDatePattern is None:
targetNamespaceDatePattern = re.compile(r"/([12][0-9]{3})-([01][0-9])-([0-3][0-9])|"
r"/([12][0-9]{3})([01][0-9])([0-3][0-9])|")
efmFilenamePattern = re.compile(r"^[a-z0-9][a-z0-9_\.\-]*(\.xsd|\.xml)$")
roleTypePattern = re.compile(r"^.*/role/[^/\s]+$")
arcroleTypePattern = re.compile(r"^.*/arcrole/[^/\s]+$")
arcroleDefinitionPattern = re.compile(r"^.*[^\\s]+.*$") # at least one non-whitespace character
namePattern = re.compile("[][()*+?\\\\/^{}|@#%^=~`\"';:,<>&$\u00a3\u20ac]") # u20ac=Euro, u00a3=pound sterling
linkroleDefinitionBalanceIncomeSheet = re.compile(r"[^-]+-\s+Statement\s+-\s+.*(income|balance|financial\W+position)",
re.IGNORECASE)
namespacesConflictPattern = re.compile(r"http://(xbrl\.us|fasb\.org|xbrl\.sec\.gov)/(dei|us-types|us-roles|rr)/([0-9]{4}-[0-9]{2}-[0-9]{2})$")
nonDomainItemNameProblemPattern = re.compile(
r"({0})|(FirstQuarter|SecondQuarter|ThirdQuarter|FourthQuarter|[1-4]Qtr|Qtr[1-4]|ytd|YTD|HalfYear)(?:$|[A-Z\W])"
.format(re.sub(r"\W", "", (val.entityRegistrantName or "").title())))
visited.append(modelDocument)
definesLabelLinkbase = False
for referencedDocument in modelDocument.referencesDocument.items():
#6.07.01 no includes
if referencedDocument[1] == "include":
val.modelXbrl.error(("EFM.6.07.01", "GFM.1.03.01", "SBR.NL.2.2.0.18"),
_("Taxonomy schema %(schema)s includes %(include)s, only import is allowed"),
modelObject=modelDocument,
schema=os.path.basename(modelDocument.uri),
include=os.path.basename(referencedDocument[0].uri))
if referencedDocument[0] not in visited:
checkDTS(val, referencedDocument[0], visited)
if val.disclosureSystem.standardTaxonomiesDict is None:
pass
if val.validateEFM:
if modelDocument.uri in val.disclosureSystem.standardTaxonomiesDict:
if modelDocument.targetNamespace:
# check for duplicates of us-types, dei, and rr taxonomies
match = namespacesConflictPattern.match(modelDocument.targetNamespace)
if match is not None:
val.standardNamespaceConflicts[match.group(2)].add(modelDocument)
else:
if len(modelDocument.basename) > 32:
val.modelXbrl.error("EFM.5.01.01.tooManyCharacters",
_("Document file name %(filename)s must not exceed 32 characters."),
modelObject=modelDocument, filename=modelDocument.basename)
if not efmFilenamePattern.match(modelDocument.basename):
val.modelXbrl.error("EFM.5.01.01",
_("Document file name %(filename)s must start with a-z or 0-9, contain lower case letters, ., -, _, and end with .xsd or .xml."),
modelObject=modelDocument, filename=modelDocument.basename)
if (modelDocument.type == ModelDocument.Type.SCHEMA and
modelDocument.targetNamespace not in val.disclosureSystem.baseTaxonomyNamespaces and
modelDocument.uri.startswith(val.modelXbrl.uriDir)):
# check schema contents types
if val.validateSBRNL:
definesLinkroles = False
definesArcroles = False
definesLinkParts = False
definesAbstractItems = False
definesNonabstractItems = False
definesConcepts = False
definesTuples = False
definesPresentationTuples = False
definesSpecificationTuples = False
definesTypes = False
definesEnumerations = False
definesDimensions = False
definesDomains = False
definesHypercubes = False
# 6.7.3 check namespace for standard authority
targetNamespaceAuthority = UrlUtil.authority(modelDocument.targetNamespace)
if targetNamespaceAuthority in val.disclosureSystem.standardAuthorities:
val.modelXbrl.error(("EFM.6.07.03", "GFM.1.03.03"),
_("Taxonomy schema %(schema)s namespace %(targetNamespace)s is a disallowed authority"),
modelObject=modelDocument, schema=os.path.basename(modelDocument.uri), targetNamespace=modelDocument.targetNamespace, targetNamespaceAuthority=targetNamespaceAuthority)
# 6.7.4 check namespace format
if modelDocument.targetNamespace is None or not modelDocument.targetNamespace.startswith("http://"):
match = None
elif val.validateEFMorGFM:
targetNamespaceDate = modelDocument.targetNamespace[len(targetNamespaceAuthority):]
match = targetNamespaceDatePattern.match(targetNamespaceDate)
else:
match = None
if match is not None:
try:
if match.lastindex == 3:
date = datetime.date(int(match.group(1)),int(match.group(2)),int(match.group(3)))
elif match.lastindex == 6:
date = datetime.date(int(match.group(4)),int(match.group(5)),int(match.group(6)))
else:
match = None
except ValueError:
match = None
if match is None:
#.........这里部分代码省略.........