| 1 | """ |
| 2 | The DALI sync renderer. |
| 3 | |
| 4 | This is, in principle, trivial and could just go into vodal. |
| 5 | |
| 6 | But then there's sufficiently many hacks in the vicinity of this that |
| 7 | a module of its own seems warranted. Also, we're for now keeping |
| 8 | DALIRenderer here, which for now is a no-op only used for registration. |
| 9 | This *could* later become some sort of alias for allowed="sync,async" |
| 10 | defaultRenderer="info". But let's see how the caproles discussion works out. |
| 11 | """ |
| 12 | |
| 13 | #c Copyright 2008-2025, the GAVO project <[email protected]> |
| 14 | #c |
| 15 | #c This program is free software, covered by the GNU GPL. See the |
| 16 | #c COPYING file in the source distribution. |
| 17 | |
| 18 | |
| 19 | from twisted.pythonscip-python python gavodachs 2.13 `twisted.python`/__init__: import failure |
| 20 | from twisted.webscip-python python gavodachs 2.13 `twisted.web`/__init__: import server |
| 21 | |
| 22 | from gavoscip-python python gavodachs 2.13 gavo/__init__: import basescip-python python gavodachs 2.13 `gavo.base`/__init__: |
| 23 | from gavoscip-python python gavodachs 2.13 gavo/__init__: import utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__: |
| 24 | from gavo.protocolsscip-python python gavodachs 2.13 `gavo.protocols`/__init__: import daliscip-python python gavodachs 2.13 `gavo.protocols.dali`/__init__: |
| 25 | from gavo.protocolsscip-python python gavodachs 2.13 `gavo.protocols`/__init__: import tapscip-python python gavodachs 2.13 `gavo.protocols.tap`/__init__: |
| 26 | from gavo.svcsscip-python python gavodachs 2.13 `gavo.svcs`/__init__: import streamingscip-python python gavodachs 2.13 `gavo.svcs.streaming`/__init__: |
| 27 | from gavo.webscip-python python gavodachs 2.13 `gavo.web`/__init__: import grendscip-python python gavodachs 2.13 `gavo.web.grend`/__init__: |
| 28 | from gavo.webscip-python python gavodachs 2.13 `gavo.web`/__init__: import vosiscip-python python gavodachs 2.13 `gavo.web.vosi`/__init__: |
| 29 | |
| 30 | |
| 31 | class DALIRendererscip-python python gavodachs 2.13 `gavo.web.syncrender`/DALIRenderer#(grendscip-python python gavodachs 2.13 `gavo.web.grend`/__init__:.ServiceBasedPagescip-python python gavodachs 2.13 `gavo.web.grend`/ServiceBasedPage#): |
| 32 | """A meta-renderer for DALI-like multi-renderer services (sync, async, ...) |
| 33 | |
| 34 | This, for now, can only be used for creating registry records. |
| 35 | """ |
| 36 | namescip-python python gavodachs 2.13 `gavo.web.syncrender`/DALIRenderer#name. = "dali" |
| 37 | |
| 38 | def renderscip-python python gavodachs 2.13 `gavo.web.syncrender`/DALIRenderer#render().(selfscip-python python gavodachs 2.13 `gavo.web.syncrender`/DALIRenderer#render().(self), requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/DALIRenderer#render().(request)): |
| 39 | raise NotImplementedErrorscip-python python python-stdlib 3.11 builtins/NotImplementedError#("DALI renderers do not render." |
| 40 | " I'm not joking.") |
| 41 | |
| 42 | @classmethodscip-python python python-stdlib 3.11 builtins/classmethod# |
| 43 | def makeAccessURLscip-python python gavodachs 2.13 `gavo.web.syncrender`/DALIRenderer#makeAccessURL().(selfscip-python python gavodachs 2.13 `gavo.web.syncrender`/DALIRenderer#makeAccessURL().(self), basePathscip-python python gavodachs 2.13 `gavo.web.syncrender`/DALIRenderer#makeAccessURL().(basePath)): |
| 44 | return basePathscip-python python gavodachs 2.13 `gavo.web.syncrender`/DALIRenderer#makeAccessURL().(basePath) |
| 45 | |
| 46 | |
| 47 | class SyncRendererscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#(grendscip-python python gavodachs 2.13 `gavo.web.grend`/__init__:.ServiceBasedPagescip-python python gavodachs 2.13 `gavo.web.grend`/ServiceBasedPage#): |
| 48 | """a DALI sync renderer. |
| 49 | |
| 50 | In principle, this is just a shallow parser of the input parameter |
| 51 | and renders tables as VOTables. |
| 52 | |
| 53 | In practice, there are a few legacy hacks making this a bit more complicated |
| 54 | after all. |
| 55 | """ |
| 56 | namescip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#name. = "sync" |
| 57 | resultTypescip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#resultType. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.votableTypescip-python python gavodachs 2.13 `gavo.base`/votableType. |
| 58 | urlUsescip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#urlUse. = "base" |
| 59 | parameterStylescip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#parameterStyle. = "dali" |
| 60 | |
| 61 | def renderscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(selfscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(self), requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(request)): |
| 62 | # We need a bit of extra behaviour for TAP support, which isn't |
| 63 | # quite DALI sync |
| 64 | try: |
| 65 | if selfscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(self).servicescip-python python gavodachs 2.13 `gavo.web.grend`/ServiceBasedPage#service..core.name_=="tapCore": |
| 66 | requestValue = requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(request).strargs.get("REQUEST", [""])[0].lower() |
| 67 | if requestValue=="getcapabilities": |
| 68 | return vosiscip-python python gavodachs 2.13 `gavo.web.vosi`/__init__:.VOSICapabilityRendererscip-python python gavodachs 2.13 `gavo.web.vosi`/VOSICapabilityRenderer#(requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(request), selfscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(self).servicescip-python python gavodachs 2.13 `gavo.web.grend`/ServiceBasedPage#service. |
| 69 | ).renderscip-python python gavodachs 2.13 `gavo.web.vosi`/VOSICapabilityRenderer#render().(requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(request)) |
| 70 | tapscip-python python gavodachs 2.13 `gavo.protocols.tap`/__init__:.mangleUploadsscip-python python gavodachs 2.13 `gavo.protocols.tap`/mangleUploads().(requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(request)) |
| 71 | |
| 72 | else: |
| 73 | # Not TAP: use DALI standard upload mangling. |
| 74 | daliscip-python python gavodachs 2.13 `gavo.protocols.dali`/__init__:.mangleUploadsscip-python python gavodachs 2.13 `gavo.protocols.dali`/mangleUploads().(requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(request)) |
| 75 | |
| 76 | selfscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(self).runAsyncscip-python python gavodachs 2.13 `gavo.web.grend`/ServiceBasedPage#runAsync().(requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(request).strargs |
| 77 | ).addCallback(selfscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(self)._formatOutputscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_formatOutput()., requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(request) |
| 78 | ).addErrback(selfscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(self)._handleFailurescip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_handleFailure()., requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(request) |
| 79 | ).addErrback(requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(request).finishCallback) |
| 80 | |
| 81 | except Exceptionscip-python python python-stdlib 3.11 builtins/Exception#: |
| 82 | return selfscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(self)._handleFailurescip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_handleFailure().(failure.Failure(), requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#render().(request)) |
| 83 | |
| 84 | return server.NOT_DONE_YET |
| 85 | |
| 86 | def _formatOutputscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_formatOutput().(selfscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_formatOutput().(self), resultscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_formatOutput().(result), requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_formatOutput().(request)): |
| 87 | f, typescip-python python python-stdlib 3.11 builtins/type# = resultscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_formatOutput().(result) |
| 88 | |
| 89 | def writeTablescip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#writeTable().(outputFilescip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#writeTable().(outputFile)): |
| 90 | utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__:.catscip-python python gavodachs 2.13 `gavo.utils.ostricks`/cat().(f, outputFilescip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#writeTable().(outputFile)) |
| 91 | |
| 92 | requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_formatOutput().(request).setHeader("content-type", strscip-python python python-stdlib 3.11 builtins/str#(typescip-python python python-stdlib 3.11 builtins/type#)) |
| 93 | # if request has an accumulator, we're testing; this might be sync, |
| 94 | # so we're shortcutting. |
| 95 | if hasattr(requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_formatOutput().(request), "accumulator"): |
| 96 | writeTablescip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#writeTable().(requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_formatOutput().(request)) |
| 97 | requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_formatOutput().(request).finish() |
| 98 | else: |
| 99 | return streamingscip-python python gavodachs 2.13 `gavo.svcs.streaming`/__init__:.streamOutscip-python python gavodachs 2.13 `gavo.svcs.streaming`/streamOut().(writeTablescip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#writeTable()., requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_formatOutput().(request)) |
| 100 | |
| 101 | def _handleFailurescip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_handleFailure().(selfscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_handleFailure().(self), flrscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_handleFailure().(flr), requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_handleFailure().(request)): |
| 102 | if not isinstance(flrscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_handleFailure().(flr).value, basescip-python python gavodachs 2.13 `gavo.base`/__init__:.Errorscip-python python gavodachs 2.13 `gavo.base.structure`/Structure#): |
| 103 | basescip-python python gavodachs 2.13 `gavo.base`/__init__:.uiscip-python python gavodachs 2.13 `gavo.base`/ui..notifyFailurescip-python python gavodachs 2.13 `gavo.base.events`/EventDispatcher#notifyFailure().(flrscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_handleFailure().(flr)) |
| 104 | return daliscip-python python gavodachs 2.13 `gavo.protocols.dali`/__init__:.serveDALIErrorscip-python python gavodachs 2.13 `gavo.protocols.dali`/serveDALIError().(requestscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_handleFailure().(request), flrscip-python python gavodachs 2.13 `gavo.web.syncrender`/SyncRenderer#_handleFailure().(flr).value) |