Debian Codegraph @

gavo/web/serviceresults.py

raw symbols SCIP
1 """
2 "Output drivers" for various formats, for the use of form-like renderers.
3
4 TODO: Tar and the output format widget should go somewhere else; the
5 rest should be done by RESPONSEFORMAT and formats. Then this module
6 should die.
7 """
8
9 #c Copyright 2008-2025, the GAVO project <[email protected]>
10 #c
11 #c This program is free software, covered by the GNU GPL. See the
12 #c COPYING file in the source distribution.
13
14
15 import osscip-python python python-stdlib 3.11 os/__init__:
16
17 from twisted.internetscip-python python gavodachs 2.13 `twisted.internet`/__init__: import threads
18 from twisted.web.templatescip-python python gavodachs 2.13 `twisted.web.template`/__init__: import tags as T
19
20 from gavoscip-python python gavodachs 2.13 gavo/__init__: import basescip-python python gavodachs 2.13 `gavo.base`/__init__:
21 from gavoscip-python python gavodachs 2.13 gavo/__init__: import formatsscip-python python gavodachs 2.13 `gavo.formats`/__init__:
22 from gavoscip-python python gavodachs 2.13 gavo/__init__: import utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__:
23 from gavo.formatsscip-python python gavodachs 2.13 `gavo.formats`/__init__: import csvtablescip-python python gavodachs 2.13 `gavo.formats.csvtable`/__init__: #noflake: format registration
24 from gavo.formatsscip-python python gavodachs 2.13 `gavo.formats`/__init__: import jsontablescip-python python gavodachs 2.13 `gavo.formats.jsontable`/__init__: #noflake: format registration
25 from gavo.formatsscip-python python gavodachs 2.13 `gavo.formats`/__init__: import fitstablescip-python python gavodachs 2.13 `gavo.formats.fitstable`/__init__: #noflake: format registration
26 from gavo.formatsscip-python python gavodachs 2.13 `gavo.formats`/__init__: import texttablescip-python python gavodachs 2.13 `gavo.formats.texttable`/__init__: #noflake: format registration
27 from gavo.formatsscip-python python gavodachs 2.13 `gavo.formats`/__init__: import geojsonscip-python python gavodachs 2.13 `gavo.formats.geojson`/__init__: #noflake: format registration
28 from gavo.formalscip-python python gavodachs 2.13 `gavo.formal`/__init__: import types as formaltypesscip-python python gavodachs 2.13 `gavo.formal.types`/String#
29 from gavo.formal.utilscip-python python gavodachs 2.13 `gavo.formal.util`/__init__: import render_cssidscip-python python gavodachs 2.13 `gavo.formal.util`/render_cssid().
30 from gavo.protocolsscip-python python gavodachs 2.13 `gavo.protocols`/__init__: import productsscip-python python gavodachs 2.13 `gavo.protocols.products`/__init__:
31 from gavo.svcsscip-python python gavodachs 2.13 `gavo.svcs`/__init__: import customwidgetsscip-python python gavodachs 2.13 `gavo.svcs.customwidgets`/__init__:
32 from gavo.svcsscip-python python gavodachs 2.13 `gavo.svcs`/__init__: import streamingscip-python python gavodachs 2.13 `gavo.svcs.streaming`/__init__:
33 from gavo.webscip-python python gavodachs 2.13 `gavo.web`/__init__: import producttarscip-python python gavodachs 2.13 `gavo.web.producttar`/__init__:
34
35 __docformat__scip-python python gavodachs 2.13 `gavo.web.serviceresults`/__docformat__. = "restructuredtext en"
36
37
38 class ServiceResultscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#(objectscip-python python python-stdlib 3.11 builtins/object#):
39 """A base class for objects producing formatted output.
40
41 They are basically wrappers for _formatOutput, which
42 will usually be used as sources for streaming.streamOut.
43
44 All methods on these objects are class methods -- they are never
45 instantiated.
46
47 Deriving classes can override
48
49 - _formatOutput(result, request, queryMeta) -- receives the service result
50 and arranges for it to be written.
51 - canWrite(colSeq) -- a that returns true when a seq of columns
52 can be serialized by this service result.
53 - code -- an identifier used in HTTP query strings to select the format
54 - label (optional) -- a string that is used in HTML forms to select
55 the format (defaults to label).
56 - compute -- if False, at least the form renderer will not run
57 the service (this is when you just return a container).
58 """
59
60 computescip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#compute. = True
61 codescip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#code. = None
62 labelscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#label. = None
63
64 @classmethodscip-python python python-stdlib 3.11 builtins/classmethod#
65 def _formatOutputscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#_formatOutput().(clsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#_formatOutput().(cls), resscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#_formatOutput().(res), requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#_formatOutput().(request), queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#_formatOutput().(queryMeta)):
66 return b""
67
68 @classmethodscip-python python python-stdlib 3.11 builtins/classmethod#
69 def getLabelscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#getLabel().(clsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#getLabel().(cls)):
70 if clsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#getLabel().(cls).labelscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#label. is not None:
71 return clsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#getLabel().(cls).labelscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#label.
72 return clsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#getLabel().(cls).codescip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#code.
73
74 @classmethodscip-python python python-stdlib 3.11 builtins/classmethod#
75 def canWritescip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#canWrite().(clsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#canWrite().(cls), colSeqscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#canWrite().(colSeq)):
76 return True
77
78
79 class VOTableResultscip-python python gavodachs 2.13 `gavo.web.serviceresults`/VOTableResult#(ServiceResultscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#):
80 """A ResultFormatter for VOTables.
81
82 The VOTables come as attachments, i.e., if all goes well the form
83 will just stand as it is.
84 """
85 codescip-python python gavodachs 2.13 `gavo.web.serviceresults`/VOTableResult#code. = "VOTable"
86
87 @classmethodscip-python python python-stdlib 3.11 builtins/classmethod#
88 def _formatOutputscip-python python gavodachs 2.13 `gavo.web.serviceresults`/VOTableResult#_formatOutput().(clsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/VOTableResult#_formatOutput().(cls), datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/VOTableResult#_formatOutput().(data), requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/VOTableResult#_formatOutput().(request), queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/VOTableResult#_formatOutput().(queryMeta)):
89 if basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getMetaTextscip-python python gavodachs 2.13 `gavo.base.meta`/getMetaText().(datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/VOTableResult#_formatOutput().(data).getPrimaryTable(), "_queryStatus"
90 )=="OVERFLOW":
91 fName = "truncated_votable.xml"
92 else:
93 fName = "votable.xml"
94 requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/VOTableResult#_formatOutput().(request).setHeader("content-type", basescip-python python gavodachs 2.13 `gavo.base`/__init__:.votableTypescip-python python gavodachs 2.13 `gavo.base`/votableType.)
95 requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/VOTableResult#_formatOutput().(request).setHeader('content-disposition',
96 'attachment; filename=%s'%fName)
97 return streamingscip-python python gavodachs 2.13 `gavo.svcs.streaming`/__init__:.streamVOTablescip-python python gavodachs 2.13 `gavo.svcs.streaming`/streamVOTable().(requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/VOTableResult#_formatOutput().(request), datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/VOTableResult#_formatOutput().(data), queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/VOTableResult#_formatOutput().(queryMeta))
98
99
100 class FITSTableResultscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#(ServiceResultscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#):
101 """returns data as a FITS binary table.
102 """
103 codescip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#code. = "FITS"
104 labelscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#label. = "FITS table"
105
106 @classmethodscip-python python python-stdlib 3.11 builtins/classmethod#
107 def getTargetNamescip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#getTargetName().(clsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#getTargetName().(cls), datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#getTargetName().(data)):
108 if basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getMetaTextscip-python python gavodachs 2.13 `gavo.base.meta`/getMetaText().(datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#getTargetName().(data).getPrimaryTable(), "_queryStatus"
109 )=="OVERFLOW":
110 return "truncated_data.fits", "application/x-fits"
111 else:
112 return "data.fits", "application/x-fits"
113
114 @classmethodscip-python python python-stdlib 3.11 builtins/classmethod#
115 def _formatOutputscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_formatOutput().(clsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_formatOutput().(cls), datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_formatOutput().(data), requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_formatOutput().(request), queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_formatOutput().(queryMeta)):
116 return threads.deferToThread(fitstablescip-python python gavodachs 2.13 `gavo.formats.fitstable`/__init__:.makeFITSTableFilescip-python python gavodachs 2.13 `gavo.formats.fitstable`/makeFITSTableFile()., datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_formatOutput().(data)
117 ).addCallback(clsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_formatOutput().(cls)._serveFilescip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_serveFile()., datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_formatOutput().(data), requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_formatOutput().(request))
118
119 @classmethodscip-python python python-stdlib 3.11 builtins/classmethod#
120 def _serveFilescip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_serveFile().(clsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_serveFile().(cls), filePathscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_serveFile().(filePath), datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_serveFile().(data), requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_serveFile().(request)):
121 name, mime = clsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_serveFile().(cls).getTargetNamescip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#getTargetName().(datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_serveFile().(data))
122 requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_serveFile().(request).setHeader("content-type", mime)
123 requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_serveFile().(request).setHeader('content-disposition',
124 'attachment; filename=%s'%name)
125
126 def writeDatascip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#writeData().(destscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#writeData().(dest)):
127 try:
128 with openscip-python python python-stdlib 3.11 builtins/open().(filePathscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_serveFile().(filePath), "rb") as f:
129 utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__:.catscip-python python gavodachs 2.13 `gavo.utils.ostricks`/cat().(f, destscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#writeData().(dest))
130 finally:
131 osscip-python python python-stdlib 3.11 os/__init__:.unlinkscip-python python python-stdlib 3.11 os/unlink().(filePathscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_serveFile().(filePath))
132
133 return streamingscip-python python gavodachs 2.13 `gavo.svcs.streaming`/__init__:.streamOutscip-python python gavodachs 2.13 `gavo.svcs.streaming`/streamOut().(writeDatascip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#writeData()., requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/FITSTableResult#_serveFile().(request))
134
135
136 class TSVResponsescip-python python gavodachs 2.13 `gavo.web.serviceresults`/TSVResponse#(ServiceResultscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#):
137 codescip-python python gavodachs 2.13 `gavo.web.serviceresults`/TSVResponse#code. = "TSV"
138 labelscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TSVResponse#label. = "Text (with Tabs)"
139
140 @classmethodscip-python python python-stdlib 3.11 builtins/classmethod#
141 def _formatOutputscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TSVResponse#_formatOutput().(clsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TSVResponse#_formatOutput().(cls), datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/TSVResponse#_formatOutput().(data), requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TSVResponse#_formatOutput().(request), queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/TSVResponse#_formatOutput().(queryMeta)):
142 requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TSVResponse#_formatOutput().(request).setHeader("content-type", "text/tab-separated-values")
143
144 def produceDatascip-python python gavodachs 2.13 `gavo.web.serviceresults`/TSVResponse#produceData().(destFilescip-python python gavodachs 2.13 `gavo.web.serviceresults`/TSVResponse#produceData().(destFile)):
145 content = texttablescip-python python gavodachs 2.13 `gavo.formats.texttable`/__init__:.getAsTextscip-python python gavodachs 2.13 `gavo.formats.texttable`/getAsText().(datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/TSVResponse#_formatOutput().(data))
146 destFilescip-python python gavodachs 2.13 `gavo.web.serviceresults`/TSVResponse#produceData().(destFile).write(content)
147
148 return streamingscip-python python gavodachs 2.13 `gavo.svcs.streaming`/__init__:.streamOutscip-python python gavodachs 2.13 `gavo.svcs.streaming`/streamOut().(produceDatascip-python python gavodachs 2.13 `gavo.web.serviceresults`/TSVResponse#produceData()., requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TSVResponse#_formatOutput().(request), queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/TSVResponse#_formatOutput().(queryMeta))
149
150
151 class TextResponsescip-python python gavodachs 2.13 `gavo.web.serviceresults`/TextResponse#(ServiceResultscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#):
152 codescip-python python gavodachs 2.13 `gavo.web.serviceresults`/TextResponse#code. = "txt"
153 labelscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TextResponse#label. = "Text (fixed columns)"
154
155 @classmethodscip-python python python-stdlib 3.11 builtins/classmethod#
156 def _formatOutputscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TextResponse#_formatOutput().(clsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TextResponse#_formatOutput().(cls), datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/TextResponse#_formatOutput().(data), requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TextResponse#_formatOutput().(request), queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/TextResponse#_formatOutput().(queryMeta)):
157 requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TextResponse#_formatOutput().(request).setHeader("content-type", "text/plain")
158
159 def produceDatascip-python python gavodachs 2.13 `gavo.web.serviceresults`/TextResponse#produceData().(destFilescip-python python gavodachs 2.13 `gavo.web.serviceresults`/TextResponse#produceData().(destFile)):
160 formatsscip-python python gavodachs 2.13 `gavo.formats`/__init__:.formatDatascip-python python gavodachs 2.13 `gavo.formats.common`/formatData().("txt", datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/TextResponse#_formatOutput().(data),
161 requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TextResponse#_formatOutput().(request), acquireSamplesscip-python python gavodachs 2.13 `gavo.formats.common`/formatData().(acquireSamples)=False)
162
163 return streamingscip-python python gavodachs 2.13 `gavo.svcs.streaming`/__init__:.streamOutscip-python python gavodachs 2.13 `gavo.svcs.streaming`/streamOut().(produceDatascip-python python gavodachs 2.13 `gavo.web.serviceresults`/TextResponse#produceData()., requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TextResponse#_formatOutput().(request), queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/TextResponse#_formatOutput().(queryMeta))
164
165
166
167 class CSVResponsescip-python python gavodachs 2.13 `gavo.web.serviceresults`/CSVResponse#(ServiceResultscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#):
168 codescip-python python gavodachs 2.13 `gavo.web.serviceresults`/CSVResponse#code. = "CSV"
169 labelscip-python python gavodachs 2.13 `gavo.web.serviceresults`/CSVResponse#label. = "CSV"
170
171 @classmethodscip-python python python-stdlib 3.11 builtins/classmethod#
172 def _formatOutputscip-python python gavodachs 2.13 `gavo.web.serviceresults`/CSVResponse#_formatOutput().(clsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/CSVResponse#_formatOutput().(cls), datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/CSVResponse#_formatOutput().(data), requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/CSVResponse#_formatOutput().(request), queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/CSVResponse#_formatOutput().(queryMeta)):
173 requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/CSVResponse#_formatOutput().(request).setHeader('content-disposition',
174 'attachment; filename=table.csv')
175 requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/CSVResponse#_formatOutput().(request).setHeader("content-type", "text/csv;header=present")
176
177 def produceDatascip-python python gavodachs 2.13 `gavo.web.serviceresults`/CSVResponse#produceData().(destFilescip-python python gavodachs 2.13 `gavo.web.serviceresults`/CSVResponse#produceData().(destFile)):
178 formatsscip-python python gavodachs 2.13 `gavo.formats`/__init__:.formatDatascip-python python gavodachs 2.13 `gavo.formats.common`/formatData().("csv", datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/CSVResponse#_formatOutput().(data),
179 requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/CSVResponse#_formatOutput().(request), acquireSamplesscip-python python gavodachs 2.13 `gavo.formats.common`/formatData().(acquireSamples)=False)
180
181 return streamingscip-python python gavodachs 2.13 `gavo.svcs.streaming`/__init__:.streamOutscip-python python gavodachs 2.13 `gavo.svcs.streaming`/streamOut().(produceDatascip-python python gavodachs 2.13 `gavo.web.serviceresults`/CSVResponse#produceData()., requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/CSVResponse#_formatOutput().(request), queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/CSVResponse#_formatOutput().(queryMeta))
182
183
184 class JsonResponsescip-python python gavodachs 2.13 `gavo.web.serviceresults`/JsonResponse#(ServiceResultscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#):
185 codescip-python python gavodachs 2.13 `gavo.web.serviceresults`/JsonResponse#code. = "JSON"
186 labelscip-python python gavodachs 2.13 `gavo.web.serviceresults`/JsonResponse#label. = "JSON"
187
188 @classmethodscip-python python python-stdlib 3.11 builtins/classmethod#
189 def _formatOutputscip-python python gavodachs 2.13 `gavo.web.serviceresults`/JsonResponse#_formatOutput().(clsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/JsonResponse#_formatOutput().(cls), datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/JsonResponse#_formatOutput().(data), requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/JsonResponse#_formatOutput().(request), queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/JsonResponse#_formatOutput().(queryMeta)):
190 requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/JsonResponse#_formatOutput().(request).setHeader('content-disposition',
191 'attachment; filename=table.json')
192 requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/JsonResponse#_formatOutput().(request).setHeader("content-type", "application/json")
193
194 def produceDatascip-python python gavodachs 2.13 `gavo.web.serviceresults`/JsonResponse#produceData().(destFilescip-python python gavodachs 2.13 `gavo.web.serviceresults`/JsonResponse#produceData().(destFile)):
195 formatsscip-python python gavodachs 2.13 `gavo.formats`/__init__:.formatDatascip-python python gavodachs 2.13 `gavo.formats.common`/formatData().("json", datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/JsonResponse#_formatOutput().(data),
196 requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/JsonResponse#_formatOutput().(request), acquireSamplesscip-python python gavodachs 2.13 `gavo.formats.common`/formatData().(acquireSamples)=False)
197
198 return streamingscip-python python gavodachs 2.13 `gavo.svcs.streaming`/__init__:.streamOutscip-python python gavodachs 2.13 `gavo.svcs.streaming`/streamOut().(produceDatascip-python python gavodachs 2.13 `gavo.web.serviceresults`/JsonResponse#produceData()., requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/JsonResponse#_formatOutput().(request), queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/JsonResponse#_formatOutput().(queryMeta))
199
200
201 class TarResponsescip-python python gavodachs 2.13 `gavo.web.serviceresults`/TarResponse#(ServiceResultscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#):
202 """delivers a tar of products requested.
203 """
204 codescip-python python gavodachs 2.13 `gavo.web.serviceresults`/TarResponse#code. = "tar"
205
206 @classmethodscip-python python python-stdlib 3.11 builtins/classmethod#
207 def _formatOutputscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TarResponse#_formatOutput().(clsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TarResponse#_formatOutput().(cls), datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/TarResponse#_formatOutput().(data), requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TarResponse#_formatOutput().(request), queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/TarResponse#_formatOutput().(queryMeta)):
208 return producttarscip-python python gavodachs 2.13 `gavo.web.producttar`/__init__:.getTarMakerscip-python python gavodachs 2.13 `gavo.web.producttar`/getTarMaker().().deliverProductTarscip-python python gavodachs 2.13 `gavo.web.producttar`/ProductTarMaker#deliverProductTar().(
209 datascip-python python gavodachs 2.13 `gavo.web.serviceresults`/TarResponse#_formatOutput().(data), requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TarResponse#_formatOutput().(request), queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/TarResponse#_formatOutput().(queryMeta))
210
211 @classmethodscip-python python python-stdlib 3.11 builtins/classmethod#
212 def canWritescip-python python gavodachs 2.13 `gavo.web.serviceresults`/TarResponse#canWrite().(clsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TarResponse#canWrite().(cls), colSeqscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TarResponse#canWrite().(colSeq)):
213 if productsscip-python python gavodachs 2.13 `gavo.protocols.products`/__init__:.getProductColumnsscip-python python gavodachs 2.13 `gavo.protocols.products`/getProductColumns().(colSeqscip-python python gavodachs 2.13 `gavo.web.serviceresults`/TarResponse#canWrite().(colSeq)):
214 return True
215 return False
216
217
218 ################# Helpers
219
220
221 _getFormatscip-python python gavodachs 2.13 `gavo.web.serviceresults`/_getFormat. = utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__:.buildClassResolverscip-python python gavodachs 2.13 `gavo.utils.codetricks`/buildClassResolver().(ServiceResultscip-python python gavodachs 2.13 `gavo.web.serviceresults`/ServiceResult#,
222 listscip-python python python-stdlib 3.11 builtins/list#(globals().valuesscip-python python python-stdlib 3.11 builtins/dict#values().()), keyscip-python python gavodachs 2.13 `gavo.utils.codetricks`/buildClassResolver().(key)=lambda obj: obj.code)
223
224
225 def getFormatscip-python python gavodachs 2.13 `gavo.web.serviceresults`/getFormat().(formatNamescip-python python gavodachs 2.13 `gavo.web.serviceresults`/getFormat().(formatName)):
226 try:
227 return _getFormatscip-python python gavodachs 2.13 `gavo.web.serviceresults`/_getFormat.(formatNamescip-python python gavodachs 2.13 `gavo.web.serviceresults`/getFormat().(formatName))
228 except KeyErrorscip-python python python-stdlib 3.11 builtins/KeyError#:
229 raise basescip-python python gavodachs 2.13 `gavo.base`/__init__:.ValidationErrorscip-python python gavodachs 2.13 `gavo.base.structure`/Structure#("Unknown format '%s'."%formatNamescip-python python gavodachs 2.13 `gavo.web.serviceresults`/getFormat().(formatName),
230 "_OUTPUT")
231
232
233 class OutputFormatscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#(objectscip-python python python-stdlib 3.11 builtins/object#):
234 """A widget that offers various output options in close cooperation
235 with gavo.js and QueryMeta.
236
237 The javascript provides options for customizing output that non-javascript
238 users will not see. Also, formal doesn't see any of these. See gavo.js
239 for details.
240
241 This widget probably only makes sense in the Form renderer and thus
242 should probably go there.
243 """
244 def __init__scip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#__init__().(selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#__init__().(self), typeObscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#__init__().(typeOb), servicescip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#__init__().(service), queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#__init__().(queryMeta)):
245 selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#__init__().(self).servicescip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#service. = servicescip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#__init__().(service)
246 selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#__init__().(self).typeObscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#typeOb. = typeObscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#__init__().(typeOb)
247 selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#__init__().(self)._computeAvailableFieldsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_computeAvailableFields().(queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#__init__().(queryMeta))
248 selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#__init__().(self)._computeAvailableFormatsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_computeAvailableFormats().(queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#__init__().(queryMeta))
249
250 def _computeAvailableFormatsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_computeAvailableFormats().(selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_computeAvailableFormats().(self), queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_computeAvailableFormats().(queryMeta)):
251 """sets the availableFormats property.
252
253 This is a helper for the constructor, inspecting serviceresults' globals().
254 """
255 outputFields = selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_computeAvailableFormats().(self).servicescip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#service..getCurOutputFields(
256 queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_computeAvailableFormats().(queryMeta),
257 raiseOnUnknown=False)
258 selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_computeAvailableFormats().(self).availableFormatsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#availableFormats. = [
259 (code, format.getLabel())
260 for code, format in _getFormatscip-python python gavodachs 2.13 `gavo.web.serviceresults`/_getFormat..registry.items()
261 if format.canWrite(outputFields)]
262
263 def _computeAvailableFieldsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_computeAvailableFields().(selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_computeAvailableFields().(self), queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_computeAvailableFields().(queryMeta)):
264 """computes the fields a Core provides but are not output by
265 the service by default.
266
267 This of course only works if the core defines its output table.
268 Otherwise, availableFields is an empty list.
269 """
270 selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_computeAvailableFields().(self).availableFieldsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#availableFields. = []
271 core = selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_computeAvailableFields().(self).servicescip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#service..core
272 if (not core.outputTable
273 or selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_computeAvailableFields().(self).servicescip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#service..getProperty("noAdditionals", False)):
274 return
275 coreNames = setscip-python python python-stdlib 3.11 builtins/set#(f.name for f in core.outputTable)
276 defaultNames = setscip-python python python-stdlib 3.11 builtins/set#([f.name
277 for f in selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_computeAvailableFields().(self).servicescip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#service..getHTMLOutputFields(
278 queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_computeAvailableFields().(queryMeta),
279 ignoreAdditionals=True,
280 raiseOnUnknown=False)])
281
282 for key in coreNames-defaultNames:
283 try:
284 selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_computeAvailableFields().(self).availableFieldsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#availableFields..appendscip-python python python-stdlib 3.11 builtins/list#append().((core.outputTable.getColumnByName(key),
285 key in queryMetascip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_computeAvailableFields().(queryMeta)["additionalFields"]))
286 except KeyErrorscip-python python python-stdlib 3.11 builtins/KeyError#: # Core returns fields not in its table,
287 # probably computes them
288 pass
289
290 def _makeAdditionalSelectorscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_makeAdditionalSelector().(selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_makeAdditionalSelector().(self)):
291 """returns an ul element containing form material for additional output
292 columns.
293 """
294 checkLiterals = {True: "checked", False: None}
295 fields = []
296 for column, checked in sortedscip-python python python-stdlib 3.11 builtins/sorted().(
297 selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_makeAdditionalSelector().(self).availableFieldsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#availableFields., keyscip-python python python-stdlib 3.11 builtins/sorted().(key)=lambda p:p[0].name):
298 fields.appendscip-python python python-stdlib 3.11 builtins/list#append().(T.tr[
299 T.td[
300 T.input(type="checkbox", name="_ADDITEM", value=column.key,
301 style="width:auto",
302 checked=checkLiterals[checked])],
303 T.td(style="vertical-align:middle")[
304 " %s -- %s"%(column.name, column.description)]])
305 return T.table(id="addSelection")[fields]
306
307 def renderscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#render().(selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#render().(self), requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#render().(request), keyscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#render().(key), argsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#render().(args), errorsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#render().(errors)):
308 res = T.div(id=render_cssidscip-python python gavodachs 2.13 `gavo.formal.util`/render_cssid().("_OUTPUT"), style="position:relative")[
309 customwidgetsscip-python python gavodachs 2.13 `gavo.svcs.customwidgets`/__init__:.SelectChoicescip-python python gavodachs 2.13 `gavo.formal.widget`/SelectChoice#(formaltypesscip-python python gavodachs 2.13 `gavo.formal.types`/String#.Stringscip-python python gavodachs 2.13 `gavo.formal.types`/String#(),
310 optionsscip-python python gavodachs 2.13 `gavo.formal.widget`/ChoiceBase#__init__().(options)=selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#render().(self).availableFormatsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#availableFormats.,
311 noneOptionscip-python python gavodachs 2.13 `gavo.formal.widget`/ChoiceBase#__init__().(noneOption)=("HTML", "HTML")).renderscip-python python gavodachs 2.13 `gavo.formal.widget`/SelectChoice#render().(requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#render().(request), "_FORMAT", argsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#render().(args), errorsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#render().(errors))(
312 onchange="output_broadcast(this.value)")]
313
314 if selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#render().(self).availableFieldsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#availableFields.:
315 res[
316 T.div(title="Additional output column selector",
317 id=render_cssidscip-python python gavodachs 2.13 `gavo.formal.util`/render_cssid().("_ADDITEMS"),
318 style="display:none")[
319 selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#render().(self)._makeAdditionalSelectorscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#_makeAdditionalSelector().()]]
320 return res
321
322 renderImmutablescip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#renderImmutable. = renderscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#render(). # This is a lost case
323
324 def processInputscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#processInput().(selfscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#processInput().(self), requestscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#processInput().(request), keyscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#processInput().(key), argsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#processInput().(args)):
325 return argsscip-python python gavodachs 2.13 `gavo.web.serviceresults`/OutputFormat#processInput().(args).get("_FORMAT", ["HTML"])[0]