コード例 #1
0
def _iterResourceMeta(ctx, dataSet):
	"""adds resource metadata to the Resource parent.
	"""
	yield V.DESCRIPTION[base.getMetaText(dataSet, "description", 
		macroPackage=dataSet.dd.rd, propagate=False)]
	for el in  itertools.chain(
			_iterInfoInfos(dataSet), _iterWarningInfos(dataSet)):
		yield el

	sourcesSeen, citeLinksSeen = set(), set()
	for table in dataSet.tables.values():
		for m in table.iterMeta("source", propagate="True"):
			src = m.getContent("text")
			if src not in sourcesSeen:
				yield V.INFO(name="source", value=src)[
					"This resource contains data associated with the publication"
					" %s."%src]
			sourcesSeen.add(src)

		for m in table.iterMeta("howtociteLink"):
			link = m.getContent("text")
			if link not in citeLinksSeen:
				yield V.INFO(name="howtocite", value=link)[
					"For advice on how to cite the resource(s)"
					" that contributed to this result, see %s"%link]
			citeLinksSeen.add(link)
コード例 #2
0
def _iterWarningInfos(dataSet):
	"""yields INFO items containing warnings from the tables in dataSet.
	"""
	for table in dataSet.tables.values():
		for warning in table.getMeta("_warning", propagate=False, default=[]):
			yield V.INFO(name="warning", value="In table %s: %s"%(
				table.tableDef.id, warning.getContent("text", macroPackage=table)))
コード例 #3
0
 def _writeErrorTable(self, ctx, msg, code=200, queryStatus="ERROR"):
     request = inevow.IRequest(ctx)
     request.setHeader("content-type", base.votableType)
     votable.write(
         V.VOTABLE11[
             V.DESCRIPTION[base.getMetaText(self.service, "description")],
             V.INFO(ID="Error",
                    name="Error",
                    value=str(msg).replace('"', '\\"'))], request)
     request.write("\n")
     return ""
コード例 #4
0
def _iterToplevelMeta(ctx, dataSet):
	"""yields meta elements for the entire VOTABLE from dataSet's RD.
	"""
	rd = dataSet.dd.rd
	if rd is None:
		return
	yield V.DESCRIPTION[base.getMetaText(rd, "description",
		macroPackage=dataSet.dd.rd)]

	for infoItem in rd.iterMeta("copyright"):
		yield V.INFO(name="legal", value=infoItem.getContent("text",
			macroPackage=dataSet.dd.rd))
コード例 #5
0
def _iterInfoInfos(dataSet):
	"""returns a sequence of V.INFO items from the info meta of dataSet.
	"""
	for infoItem in dataSet.getMeta("info", default=[]):
		name, value, id = infoItem.infoName, infoItem.infoValue, infoItem.infoId
		yield V.INFO(name=name, value=value, ID=id)[infoItem.getContent()]
コード例 #6
0
    def _run_queryData(self, service, inputTable, queryMeta):
        format = inputTable.getParam("FORMAT") or ""
        if format.lower() == "metadata":
            return self._makeMetadata(service)

        limits = [
            q for q in (inputTable.getParam("MAXREC", None),
                        inputTable.getParam("TOP")) if q
        ]
        if not limits:
            limits = [base.getConfig("ivoa", "dalDefaultLimit")]
        limit = min(min(limits), base.getConfig("ivoa", "dalHardLimit"))
        queryMeta["dbLimit"] = limit

        res = svcs.DBCore.run(self, service, inputTable, queryMeta)
        if len(res) == limit:
            queryStatus = "OVERFLOW"
            queryStatusBody = (
                "Exactly %s rows were returned.  This means your"
                " query probably reached the match limit.  Increase MAXREC." %
                limit)
        else:
            queryStatus = "OK"
            queryStatusBody = ""

        self._addPreviewLinks(res)

        # We wrap our result into a data instance since we need to set the
        #	result type
        data = rsc.wrapTable(res)
        data.setMeta("_type", "results")
        data.addMeta("_votableRootAttributes",
                     'xmlns:ssa="http://www.ivoa.net/xml/DalSsap/v1.0"')

        # The returnRaw property is a hack, mainly for unit testing;
        # The renderer would have to add the QUERY_STATUS here.
        if service.getProperty("returnData", False):
            return data

        # we fix tablecoding to td for now since nobody seems to like
        # binary tables and we don't have huge tables here.
        votCtx = votablewrite.VOTableContext(tablecoding="td")

        vot = votablewrite.makeVOTable(data, votCtx)
        pubDIDId = votCtx.getIdFor(res.tableDef.getColumnByName("ssa_pubDID"))
        resElement = vot.getChildDict()["RESOURCE"][0]
        resElement[
            V.INFO(name="SERVICE_PROTOCOL", value=self.ssapVersion)["SSAP"],
            V.INFO(name="QUERY_STATUS", value=queryStatus)[queryStatusBody]]

        datalinkId = service.getProperty("datalink", None)
        if datalinkId and res:
            dlService = self.rd.getById(datalinkId)
            dlCore = getDatalinkCore(dlService, res)

            # new and shiny datalink (keep)
            # (we're just using endpoint 0; it should a the sync service)
            dlEndpoint = dlCore.datalinkEndpoints[0]
            vot[dlEndpoint.asVOT(votCtx,
                                 dlService.getURL(dlEndpoint.rendName),
                                 linkIdTo=pubDIDId)]

            # Also point to the dl metadata service
            vot[V.RESOURCE(type="meta", utype="adhoc:service")[
                V.PARAM(name="standardID",
                        datatype="char",
                        arraysize="*",
                        value="ivo://ivoa.net/std/DataLink#links-1.0"),
                V.PARAM(name="accessURL",
                        datatype="char",
                        arraysize="*",
                        value=self.rd.getById(datalinkId).getURL("dlmeta")),
                V.GROUP(name="inputParams")[V.PARAM(
                    name="ID",
                    datatype="char",
                    arraysize="*",
                    ref=pubDIDId,
                    ucd="meta.id;meta.main"
                )[V.LINK(content_role="ddl:id-source", value="#" +
                         pubDIDId)]]]]

        return "application/x-votable+xml", votable.asString(vot)
コード例 #7
0
 def _makeErrorTable(self, ctx, msg, queryStatus="ERROR"):
     # FatalFault, DefaultFault
     return V.VOTABLE[V.RESOURCE(type="results")[V.INFO(
         name="QUERY_STATUS", value=queryStatus)[str(msg)]]]