"""
Operator code based on DaCHS (e.g., custom grammars or pages, other helper
code, or ``<code>`` items in RDs) should just need to ``from gavo import api``
and then work with what is in here.  See
http://docs.g-vo.org/DaCHS/ref.html#api-function-reference for what is
available here.
"""

#c Copyright 2008-2025, the GAVO project <gavo@ari.uni-heidelberg.de>
#c
#c This program is free software, covered by the GNU GPL.  See the
#c COPYING file in the source distribution.


# Not checked by pyflakes: API file with gratuitous imports

from gavo import base
from gavo import rscdesc
from gavo import votable
from gavo import web

getRD = base.caches.getRD
RD = rscdesc.RD

from gavo.base import (getConfig, setConfig, getBinaryName,
	getDBConnection, DBError,	IntegrityError,
	UnmanagedQuerier, AdhocQuerier,
	getTableConn, getAdminConn, getUntrustedConn,
	getWritableTableConn, getWritableAdminConn,
	NoMetaKey, Error, StructureError, ValidationError, LiteralParseError,
	ReportableError, NotFoundError, RDNotFound, SourceParseError, DataError,
	MetaValidationError, BadUnit, BadCode,
	parseFromString,
	makeStruct,
	parseUnit,
	getMetaText,
	ui,
	resolveCrossId, getTableDefForTable,
	SERVER_SOFTWARE)

from gavo.formats import formatData, getFormatted
from gavo.formats.votablewrite import (writeAsVOTable, getAsVOTable,
	VOTableContext)

from gavo.grammars.customgrammar import CustomRowIterator, CustomGrammar

from gavo.helpers.processing import (CannotComputeHeader,
	FileProcessor, ImmediateHeaderProcessor, HeaderProcessor,
	AnetHeaderProcessor, PreviewMaker, OneDPreviewMaker,
	SpectralPreviewMaker, DLPreviewMaker, procmain)

from gavo.helpers.fitstricks import (addHistoryCard,
	updateTemplatedHeader, makeHeaderFromTemplate, getTemplateForName)

from gavo.rsc import (TableForDef, DBTable, makeData, parseValidating,
	parseNonValidating, getParseOptions, Data, makeDependentsFor,
	createDump, restoreDump)

from gavo.rscdef import (DataDescriptor, TableDef,
	getFlatName, getReferencedElement)

from gavo.stc import (dateTimeToJYear, dateTimeToJdn, dateTimeToMJD,
	jYearToDateTime, jdnToDateTime, jdnToJYear, mjdToDateTime, parseISODT, isMJD,
	JD_MJD)

from gavo.svcs import (UnknownURI, ForbiddenURI, Authenticate,
	WebRedirect, SeeOther, Core, OutputTableDef, QueryMeta)

from gavo.user.logui import LoggingUI
from gavo.user.plainui import StingyPlainUI, PlainUI

from gavo.utils import (
	loadPythonModule, formatISODT, bytify, EqualingRE,
	document,
	pyfits, cutoutFITS,
	safeReplaced,
	QuotedName,
	urlopenRemote, setUserAgent)

from gavo.votable import VOTableError, ADQLTAPJob

from gavo.web import ServiceBasedPage, renderDCErrorPage
from gavo.helpers.testtricks import getXMLTree

from gavo.rscdef.rmkfuncs import *

@document
def reloadLocal():
	"""reloads the local namespace.

	This is material an operator defines in $GAVO_CONFIG/local.py.  If that
	file is missing or unreadable, api.local will be a stub that raises
	a constant error regardless of what you try to getattr from it.
	"""
	global local
	modpath = base.getConfig("configDir") / "local"
	try:
		local, _ = loadPythonModule(modpath)
	except (FileNotFoundError, ImportError):
		class _:
			def __getattr__(self, name):
				raise ReportableError(f"No file {modpath}.py found")
		local = _()


reloadLocal()

__version__ = base.getVersion()
