| 1 |
""" |
| 2 |
Miscellaneous helper modules for DACHS' python modules. |
| 3 |
|
| 4 |
This comprises helpers and wrappers that do not need gavo.base but for some |
| 5 |
reason or another should be within the dc package. |
| 6 |
""" |
| 7 |
|
| 8 |
#c Copyright 2008-2025, the GAVO project <[email protected]> |
| 9 |
#c |
| 10 |
#c This program is free software, covered by the GNU GPL. See the |
| 11 |
#c COPYING file in the source distribution. |
| 12 |
|
| 13 |
|
| 14 |
# Not checked by pyflakes: API file with gratuitous imports |
| 15 |
|
| 16 |
|
| 17 |
import os |
| 18 |
|
| 19 |
# do any necessary monkeypatching before doing anything else |
| 20 |
import gavo.utils.monkeypatch |
| 21 |
|
| 22 |
from gavo.utils.algotricks import ( |
| 23 |
chunk, identity, topoSort, commonPrefixLength, uniqueItems) |
| 24 |
|
| 25 |
from gavo.utils.autonode import AutoNode |
| 26 |
|
| 27 |
from gavo.utils.codetricks import (silence, ensureExpression, compileFunction, |
| 28 |
loadPythonModule, DeferredImport, |
| 29 |
memoized, identity, document, |
| 30 |
buildClassResolver, CachedGetter, intToFunnyWord, |
| 31 |
IdManagerMixin, |
| 32 |
addDefaults, iterDerivedClasses, iterDerivedObjects, iterConsecutivePairs, |
| 33 |
importModule, loadInternalObject, printFrames, memoizeOn, forgetMemoized, |
| 34 |
sandbox, devnull, |
| 35 |
in_dir, getTracebackAsString, |
| 36 |
Infimum, Supremum, NullObject, |
| 37 |
stealVar, |
| 38 |
AllEncompassingSet, |
| 39 |
bytelist, intlist, floatlist, complexlist, |
| 40 |
EqualingRE, NocaseString, |
| 41 |
NS) |
| 42 |
from builtins import list |
| 43 |
|
| 44 |
from gavo.utils.excs import * |
| 45 |
|
| 46 |
# We reliably want the numpy version of pyfits. Thus, always use |
| 47 |
# from gavo.utils import pyfits rather than a direct import; the |
| 48 |
# "master import" is in fitstools, and we get pyfits from there. |
| 49 |
|
| 50 |
from gavo.utils.fitstools import (readPrimaryHeaderQuick, pyfits, |
| 51 |
parseESODescriptors, shrinkWCSHeader, cutoutFITS, iterScaledRows, |
| 52 |
fitsLock, getWCSAxis) |
| 53 |
|
| 54 |
from gavo.utils.mathtricks import * |
| 55 |
|
| 56 |
from gavo.utils.misctricks import (Undefined, UndefinedType, |
| 57 |
NotGiven, NotGivenType, |
| 58 |
QuotedName, getfirst, |
| 59 |
logOldExc, sendUIEvent, |
| 60 |
getWithCache, |
| 61 |
rstxToHTML, rstxToHTMLWithWarning, |
| 62 |
couldBeABibcode, |
| 63 |
parseKVLine, makeKVLine, |
| 64 |
StreamBuffer, CaseSemisensitiveDict, |
| 65 |
grouped, |
| 66 |
getCleanBytes, getDirtyBytes, |
| 67 |
RateLimiter) |
| 68 |
|
| 69 |
from gavo.utils.ostricks import (safeclose, |
| 70 |
urlopenRemote, setUserAgent, |
| 71 |
fgetmtime, cat, ensureDir, safeReplaced, |
| 72 |
Arg, exposedFunction, makeCLIParser, StatusDisplay) |
| 73 |
|
| 74 |
from gavo.utils.parsetricks import ( |
| 75 |
ParserElement, pyparseString, pyparseTransform) |
| 76 |
|
| 77 |
from gavo.utils.plainxml import StartEndHandler, iterparse, traverseETree |
| 78 |
|
| 79 |
from gavo.utils.serializers import (defaultMFRegistry, registerDefaultMF) |
| 80 |
|
| 81 |
from gavo.utils.stanxml import (ElementTree, xmlrender, xmlwrite, |
| 82 |
escapeAttrVal, escapePCDATA, registerPrefix, getPrefixInfo) |
| 83 |
|
| 84 |
from gavo.utils.texttricks import (formatSize, formatFloat, |
| 85 |
spinner, |
| 86 |
makeEllipsis, makeLeftEllipsis, makeSourceEllipsis, |
| 87 |
floatRE, dateRE, datetimeRE, identifierPattern, looksLikeURLPat, |
| 88 |
datetimeToRFC2616, |
| 89 |
parseDefaultDatetime, parseDefaultDate, parseDefaultTime, |
| 90 |
parseMediaType, parseAccept, |
| 91 |
isoTimestampFmt, isoTimestampFmtNoTZ, parseISODT, formatISODT, |
| 92 |
formatRFC2616Date, parseRFC2616Date, roundToSeconds, |
| 93 |
getFileStem, |
| 94 |
fixIndentation, parsePercentExpression, hmsToDeg, dmsToDeg, |
| 95 |
makeIAUId, |
| 96 |
fracHoursToDeg, degToHms, degToDms, hoursToHms, |
| 97 |
getRelativePath, parseAssignments, |
| 98 |
NameMap, formatSimpleTable, replaceXMLEntityRefs, |
| 99 |
ensureOneSlash, getRandomString, |
| 100 |
safe_str, defuseFileName, bytify, debytify, iterSimpleText, |
| 101 |
isSQLTextLiteral) |