| 1 | """ |
| 2 | Code to support PQL syntax (as found in various DAL protocols). |
| 3 | |
| 4 | PQL range-list syntax is |
| 5 | |
| 6 | valSep ::= "," |
| 7 | rangeSep ::= "/" |
| 8 | qualSep ::= ";" |
| 9 | step ::= somethingMagicallyDefined |
| 10 | range ::= [literal] rangeSep literal | literal rangeSep |
| 11 | steppedRange ::= range [rangeSep step] |
| 12 | qualification ::= qualSep somethingMagicallyDefined |
| 13 | listItem ::= steppedRange | literal |
| 14 | rangeList ::= listItem {valSep listItem} [qualification] |
| 15 | |
| 16 | This defines a regular language, and we're going to slaughter it using |
| 17 | REs and ad hoccing. |
| 18 | |
| 19 | Since the actually allowed grammar depends on the type of the parameter |
| 20 | (e.g., steps make no sense for strings, and have a special grammar for |
| 21 | dates), parsing is done by the specific PQLPar types (fromLiteral). See |
| 22 | the PQLPar docstring for further info. |
| 23 | """ |
| 24 | |
| 25 | #c Copyright 2008-2025, the GAVO project <[email protected]> |
| 26 | #c |
| 27 | #c This program is free software, covered by the GNU GPL. See the |
| 28 | #c COPYING file in the source distribution. |
| 29 | |
| 30 | |
| 31 | import datetimescip-python python python-stdlib 3.11 datetime/__init__: |
| 32 | import functoolsscip-python python python-stdlib 3.11 functools/__init__: |
| 33 | import rescip-python python python-stdlib 3.11 re/__init__: |
| 34 | import urllib.requestscip-python python python-stdlib 3.11 `urllib.request`/__init__:, urllib.parsescip-python python python-stdlib 3.11 `urllib.parse`/__init__:, urllib.errorscip-python python python-stdlib 3.11 `urllib.error`/__init__: |
| 35 | |
| 36 | from gavoscip-python python gavodachs 2.13 gavo/__init__: import basescip-python python gavodachs 2.13 `gavo.base`/__init__: |
| 37 | from gavoscip-python python gavodachs 2.13 gavo/__init__: import stcscip-python python gavodachs 2.13 `gavo.stc`/__init__: |
| 38 | from gavoscip-python python gavodachs 2.13 gavo/__init__: import utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__: |
| 39 | from gavo.basescip-python python gavodachs 2.13 `gavo.base`/__init__: import literalsscip-python python gavodachs 2.13 `gavo.base.literals`/__init__: |
| 40 | from gavo.basescip-python python gavodachs 2.13 `gavo.base`/__init__: import sqlmungescip-python python gavodachs 2.13 `gavo.base.sqlmunge`/__init__: |
| 41 | from gavo.basescip-python python gavodachs 2.13 `gavo.base`/__init__: import typesystemsscip-python python gavodachs 2.13 `gavo.base.typesystems`/__init__: |
| 42 | from gavo.utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__: import DEGscip-python python gavodachs 2.13 `gavo.utils.mathtricks`/DEG., pgspherescip-python python gavodachs 2.13 `gavo.utils.pgsphere`/__init__: |
| 43 | |
| 44 | |
| 45 | QUALIFIER_REscip-python python gavodachs 2.13 `gavo.svcs.pql`/QUALIFIER_RE. = rescip-python python python-stdlib 3.11 re/__init__:.compilescip-python python python-stdlib 3.11 re/compile().("([^;]*)(;[^;]*)?$") |
| 46 | LIST_REscip-python python gavodachs 2.13 `gavo.svcs.pql`/LIST_RE. = rescip-python python python-stdlib 3.11 re/__init__:.compilescip-python python python-stdlib 3.11 re/compile().("([^,]*),") |
| 47 | RANGE_REscip-python python gavodachs 2.13 `gavo.svcs.pql`/RANGE_RE. = rescip-python python python-stdlib 3.11 re/__init__:.compilescip-python python python-stdlib 3.11 re/compile().("([^/]*)(/[^/]*)?(/[^/]*)?$") |
| 48 | |
| 49 | |
| 50 | def _raiseNoStepsscip-python python gavodachs 2.13 `gavo.svcs.pql`/_raiseNoSteps().(valscip-python python gavodachs 2.13 `gavo.svcs.pql`/_raiseNoSteps().(val)): |
| 51 | raise ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#("Step/stride specification not allowed here.") |
| 52 | |
| 53 | |
| 54 | def _parsePQLValuescip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(valscip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(val), valIndscip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(valInd)=0, vpscip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(vp)=strscip-python python python-stdlib 3.11 builtins/str#): |
| 55 | if not valscip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(val) or not valscip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(val)[valIndscip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(valInd):]: |
| 56 | return None |
| 57 | else: |
| 58 | return vpscip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(vp)(urllib.parsescip-python python python-stdlib 3.11 `urllib.request`/__init__:.unquote(valscip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(val)[valIndscip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(valInd):])) |
| 59 | |
| 60 | |
| 61 | class PQLRangescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#(objectscip-python python python-stdlib 3.11 builtins/object#): |
| 62 | """a representation of a PQL range. |
| 63 | |
| 64 | PQLRanges have a value attribute that is non-None when there is |
| 65 | only a single value. |
| 66 | |
| 67 | For ranges, there is start, stop and step, all of which may be |
| 68 | None. |
| 69 | |
| 70 | The attributes contain whatever the parent's valParser (or stepParser) |
| 71 | functions return. |
| 72 | """ |
| 73 | def __init__scip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(self), valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(value)=None, startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(start)=None, stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(stop)=None, stepscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(step)=None): |
| 74 | selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start., selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop., selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(self).stepscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#step. = startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(start), stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(stop), stepscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(step) |
| 75 | selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(self).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#value. = valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(value) |
| 76 | if (selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(self).stepscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#step. is not None |
| 77 | and (selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start. is None or selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop. is None)): |
| 78 | raise ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#("Open intervals cannot have steps") |
| 79 | if (selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(self).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#value. is None |
| 80 | and (selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start. is None and selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__init__().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop. is None)): |
| 81 | raise ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#("Doubly open intervals are not allowed") |
| 82 | |
| 83 | def __eq__scip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__eq__().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__eq__().(self), otherscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__eq__().(other)): |
| 84 | return (isinstance(otherscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__eq__().(other), PQLRangescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#) |
| 85 | and selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__eq__().(self).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#value.==otherscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__eq__().(other).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#value. |
| 86 | and selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__eq__().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start.==otherscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__eq__().(other).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start. |
| 87 | and selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__eq__().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop.==otherscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__eq__().(other).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop. |
| 88 | and selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__eq__().(self).stepscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#step.==otherscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__eq__().(other).stepscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#step.) |
| 89 | |
| 90 | def __repr__scip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__repr__().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__repr__().(self)): |
| 91 | return "%s(%s, %s, %s, %s)"%(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__repr__().(self).__class__scip-python python python-stdlib 3.11 builtins/object#__class__()..__name__scip-python python python-stdlib 3.11 builtins/__name__#, |
| 92 | repr(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__repr__().(self).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#value.), |
| 93 | repr(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__repr__().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start.), |
| 94 | repr(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__repr__().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop.), |
| 95 | repr(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__repr__().(self).stepscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#step.)) |
| 96 | |
| 97 | def __str__scip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__str__().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__str__().(self)): |
| 98 | if selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__str__().(self).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#value. is not None: |
| 99 | return urllibscip-python python python-stdlib 3.11 `urllib.request`/__init__:.parse.quote(strscip-python python python-stdlib 3.11 builtins/str#(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__str__().(self).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#value.)) |
| 100 | else: |
| 101 | def escip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#e().(vscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#e().(v)): |
| 102 | if vscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#e().(v) is None: |
| 103 | return "" |
| 104 | else: |
| 105 | return urllibscip-python python python-stdlib 3.11 `urllib.request`/__init__:.parse.quote(strscip-python python python-stdlib 3.11 builtins/str#(vscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#e().(v))) |
| 106 | return "/".joinscip-python python python-stdlib 3.11 builtins/str#join().(escip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#e().(v) for v in (selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__str__().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start., selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__str__().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop., selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#__str__().(self).stepscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#step.)) |
| 107 | |
| 108 | @classmethodscip-python python python-stdlib 3.11 builtins/classmethod# |
| 109 | def fromLiteralscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(cls), literalscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(literal), destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(destName), valParserscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(valParser), stepParserscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(stepParser)): |
| 110 | """creates a PQLRange from a PQL range literal. |
| 111 | |
| 112 | For the meaning of the arguments, see PQLPar.fromLiteral. |
| 113 | """ |
| 114 | if literalscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(literal)=="": |
| 115 | return clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(cls)(value="") |
| 116 | mat = RANGE_REscip-python python gavodachs 2.13 `gavo.svcs.pql`/RANGE_RE..matchscip-python python python-stdlib 3.11 re/Pattern#match().(literalscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(literal)) |
| 117 | if not mat: |
| 118 | raise basescip-python python gavodachs 2.13 `gavo.base`/__init__:.LiteralParseErrorscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#(destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(destName), literalscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(literal), |
| 119 | hintscip-python python gavodachs 2.13 `gavo.utils.excs`/LiteralParseError#__init__().(hint)="PQL ranges roughly have the form [start][/stop[/stop]]." |
| 120 | " Literal slashes need to be escaped (as %2f).") |
| 121 | vals = mat.groupsscip-python python python-stdlib 3.11 re/Match#groups().() |
| 122 | |
| 123 | try: |
| 124 | if vals[1] is None and vals[2] is None: |
| 125 | return clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(cls)(value=_parsePQLValuescip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(vals[0], vpscip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(vp)=valParserscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(valParser))) |
| 126 | else: |
| 127 | start, stop, step = vals |
| 128 | return clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(cls)( |
| 129 | start=_parsePQLValuescip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(start, vpscip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(vp)=valParserscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(valParser)), |
| 130 | stop=_parsePQLValuescip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(stop, 1, vpscip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(vp)=valParserscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(valParser)), |
| 131 | step=_parsePQLValuescip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(step, 1, vpscip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(vp)=stepParserscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(stepParser))) |
| 132 | except ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError# as ex: |
| 133 | raise basescip-python python gavodachs 2.13 `gavo.base`/__init__:.LiteralParseErrorscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("range within %s"%destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(destName), literalscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#fromLiteral().(literal), |
| 134 | hintscip-python python gavodachs 2.13 `gavo.utils.excs`/LiteralParseError#__init__().(hint)=strscip-python python python-stdlib 3.11 builtins/str#(ex)) |
| 135 | |
| 136 | def getValuesAsSetscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getValuesAsSet().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getValuesAsSet().(self)): |
| 137 | """returns a set containing all values matching the PQL condition if |
| 138 | they form a discrete set or raises a ValueError if not. |
| 139 | """ |
| 140 | if selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getValuesAsSet().(self).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#value. is not None: |
| 141 | return setscip-python python python-stdlib 3.11 builtins/set#([selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getValuesAsSet().(self).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#value.]) |
| 142 | elif (selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getValuesAsSet().(self).stepscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#step. is not None \ |
| 143 | and selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getValuesAsSet().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start. is not None |
| 144 | and selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getValuesAsSet().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop. is not None): |
| 145 | if (selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getValuesAsSet().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop.-selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getValuesAsSet().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start.)/abs(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getValuesAsSet().(self).stepscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#step.)+1e-10>2000: |
| 146 | raise ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#("Too many steps; will not check discretely") |
| 147 | res, val = setscip-python python python-stdlib 3.11 builtins/set#(), selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getValuesAsSet().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start. |
| 148 | while val<=selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getValuesAsSet().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop.: |
| 149 | res.addscip-python python python-stdlib 3.11 builtins/set#add().(val) |
| 150 | val = val+selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getValuesAsSet().(self).stepscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#step. |
| 151 | return res |
| 152 | raise ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#("No set representation for non-stepped or open ranges.") |
| 153 | |
| 154 | def getSQLscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(self), colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(colName), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(sqlPars), cmpExprscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(cmpExpr)=None): |
| 155 | """returns an SQL boolean expression for representing this constraint. |
| 156 | |
| 157 | cmpExpr, if given, will be an expression that is compared |
| 158 | against. It defaults to colName, but this is, of course, intended |
| 159 | to allow stuff like LOWER(colName). |
| 160 | """ |
| 161 | if cmpExprscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(cmpExpr) is None: |
| 162 | cmpExprscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(cmpExpr) = colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(colName) |
| 163 | |
| 164 | # Single Value |
| 165 | if selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(self).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#value. is not None: |
| 166 | return "%s = %%(%s)s"%(cmpExprscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(cmpExpr), |
| 167 | basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getSQLKeyscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/getSQLKey().(colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(colName), selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(self).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#value., sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(sqlPars))) |
| 168 | |
| 169 | # Discrete Set |
| 170 | try: |
| 171 | return "%s IN %%(%s)s"%(cmpExprscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(cmpExpr), basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getSQLKeyscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/getSQLKey().(colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(colName), |
| 172 | selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(self).getValuesAsSetscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getValuesAsSet().(), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(sqlPars))) |
| 173 | except ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#: # Not a discrete set |
| 174 | pass |
| 175 | |
| 176 | # At least one half-open or non-stepped range |
| 177 | if selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start. is None and selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop. is not None: |
| 178 | return "%s <= %%(%s)s"%(cmpExprscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(cmpExpr), |
| 179 | basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getSQLKeyscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/getSQLKey().(colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(colName), selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop., sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(sqlPars))) |
| 180 | elif selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start. is not None and selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop. is None: |
| 181 | return "%s >= %%(%s)s"%(cmpExprscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(cmpExpr), |
| 182 | basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getSQLKeyscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/getSQLKey().(colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(colName), selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start., sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(sqlPars))) |
| 183 | else: |
| 184 | assert selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start. is not None and selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop. is not None |
| 185 | return "%s BETWEEN %%(%s)s AND %%(%s)s "%(cmpExprscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(cmpExpr), |
| 186 | basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getSQLKeyscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/getSQLKey().(colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(colName), selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start., sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(sqlPars)), |
| 187 | basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getSQLKeyscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/getSQLKey().(colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(colName), selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop., sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQL().(sqlPars))) |
| 188 | |
| 189 | def getSQLForIntervalscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQLForInterval().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQLForInterval().(self), lowerColNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQLForInterval().(lowerColName), upperColNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQLForInterval().(upperColName), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQLForInterval().(sqlPars)): |
| 190 | """returns an SQL boolean expression for representing this constraint |
| 191 | against an upper, lower interval in the DB table. |
| 192 | |
| 193 | This will silently discard any step specification. |
| 194 | """ |
| 195 | # Single Value |
| 196 | if selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQLForInterval().(self).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#value. is not None: |
| 197 | return "%%(%s)s BETWEEN %s AND %s"%( |
| 198 | basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getSQLKeyscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/getSQLKey().("val", selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQLForInterval().(self).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#value., sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQLForInterval().(sqlPars)), |
| 199 | lowerColNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQLForInterval().(lowerColName), upperColNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQLForInterval().(upperColName)) |
| 200 | else: |
| 201 | constraints = [] |
| 202 | if selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQLForInterval().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop. is not None: |
| 203 | constraints.appendscip-python python python-stdlib 3.11 builtins/list#append().("%%(%s)s>%s"%( |
| 204 | basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getSQLKeyscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/getSQLKey().("val", selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQLForInterval().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop., sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQLForInterval().(sqlPars)), |
| 205 | lowerColNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQLForInterval().(lowerColName))) |
| 206 | if selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQLForInterval().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start. is not None: |
| 207 | constraints.appendscip-python python python-stdlib 3.11 builtins/list#append().("%%(%s)s<%s"%( |
| 208 | basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getSQLKeyscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/getSQLKey().("val", selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQLForInterval().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start., sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQLForInterval().(sqlPars)), |
| 209 | upperColNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getSQLForInterval().(upperColName))) |
| 210 | return "(%s)"%" AND ".joinscip-python python python-stdlib 3.11 builtins/str#join().(constraints) |
| 211 | |
| 212 | def coversscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#covers().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#covers().(self), valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#covers().(value)): |
| 213 | """returns True if value is covered by this interval. |
| 214 | |
| 215 | value must be type-true, i.e. in whatever type value, start, and stop |
| 216 | have. |
| 217 | """ |
| 218 | # try a single value |
| 219 | if selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#covers().(self).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#value. is not None: |
| 220 | return valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#covers().(value)==selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#covers().(self).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#value. |
| 221 | |
| 222 | # try a discrete set ("step" has been specified) |
| 223 | try: |
| 224 | return valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#covers().(value) in selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#covers().(self).getValuesAsSetscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#getValuesAsSet().() |
| 225 | except ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#: # not a discrete set |
| 226 | pass |
| 227 | |
| 228 | # interval, possibly half-open |
| 229 | covers = True |
| 230 | if selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#covers().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start. is not None: |
| 231 | covers &= selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#covers().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start.<=valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#covers().(value) |
| 232 | if selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#covers().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop. is not None: |
| 233 | covers &= selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#covers().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop.>=valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#covers().(value) |
| 234 | return covers |
| 235 | |
| 236 | |
| 237 | class PQLNoRangescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#(PQLRangescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#): |
| 238 | """a stand-in for PQLRange when no ranges are to be supported |
| 239 | |
| 240 | It seems this is intended for string-typed values. We try to |
| 241 | be compatible with PQLRange in the relevant API aspects. |
| 242 | """ |
| 243 | def __init__scip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__init__().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__init__().(self), valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__init__().(value)): |
| 244 | selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__init__().(self).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#value. = valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__init__().(value) |
| 245 | selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__init__().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#start. = selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__init__().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#stop. = selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__init__().(self).stepscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#step. = None |
| 246 | |
| 247 | def __eq__scip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__eq__().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__eq__().(self), otherscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__eq__().(other)): |
| 248 | return (isinstance(otherscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__eq__().(other), PQLRangescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#) |
| 249 | and selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__eq__().(self).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#value.==otherscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__eq__().(other).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#value. |
| 250 | and selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__eq__().(self).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#start.==otherscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__eq__().(other).startscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#start. |
| 251 | and selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__eq__().(self).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#stop.==otherscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__eq__().(other).stopscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#stop. |
| 252 | and selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__eq__().(self).stepscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#step.==otherscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__eq__().(other).stepscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange#step.) |
| 253 | |
| 254 | def __str__scip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__str__().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__str__().(self)): |
| 255 | return strscip-python python python-stdlib 3.11 builtins/str#(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#__str__().(self).valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#value.) |
| 256 | |
| 257 | @classmethodscip-python python python-stdlib 3.11 builtins/classmethod# |
| 258 | def fromLiteralscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#fromLiteral().(clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#fromLiteral().(cls), literalscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#fromLiteral().(literal), destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#fromLiteral().(destName), valParserscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#fromLiteral().(valParser), stepParserscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#fromLiteral().(stepParser)): |
| 259 | """creates a PQLRange from a PQL range literal. |
| 260 | |
| 261 | For the meaning of the arguments, see PQLPar.fromLiteral. |
| 262 | """ |
| 263 | if literalscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#fromLiteral().(literal)=="": |
| 264 | return clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#fromLiteral().(cls)(value="") |
| 265 | return clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#fromLiteral().(cls)(value=_parsePQLValuescip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(literalscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#fromLiteral().(literal), vpscip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(vp)=valParserscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange#fromLiteral().(valParser))) |
| 266 | |
| 267 | |
| 268 | class PQLParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#(objectscip-python python python-stdlib 3.11 builtins/object#): |
| 269 | """a representation for PQL expressions. |
| 270 | |
| 271 | PQLPar objects have an attribute qualifier (None or a string), |
| 272 | and an attribute ranges, a list of PQLRange objects. |
| 273 | |
| 274 | As a client, you will usually construct PQLPar objects using the |
| 275 | fromLiteral class method; it takes a PQL literal and a name to be |
| 276 | used for LiteralParseErrors it may raise. |
| 277 | |
| 278 | The plain PQLPar parses string ranges and does not allow steps. |
| 279 | |
| 280 | Inheriting classes must override the valParser and stepParser attributes. |
| 281 | Both take a string and have to return a typed value or raise a |
| 282 | ValueError if the string does not contain a proper literal. |
| 283 | The default for valParser is str, the default for stepParser |
| 284 | a function that always raises a ValueError. |
| 285 | |
| 286 | PQLPars usually support a covers(value) method that you can |
| 287 | pass a value having the required type; it will return whether or |
| 288 | not value would be picked up by the condition formulated in PQL. |
| 289 | Some advanced PQLPars do not support this method and will |
| 290 | raise a ValueError if called. |
| 291 | |
| 292 | Since "PQL" is totally crazy, not even the range parser is constant. |
| 293 | It seems string ranges were never meant to be supported, and therefore |
| 294 | we support RangeClass. PQLRange allows the "/" syntax and is supposed |
| 295 | to work for most things but strings. PQLNoRange is just always a simple |
| 296 | value. |
| 297 | |
| 298 | Note: valParser and stepParser must not be *methods* of the |
| 299 | class but plain functions; since they are function-like class attributes, |
| 300 | you will usually have to wrap them in staticmethods |
| 301 | """ |
| 302 | nullvaluescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#nullvalue. = None |
| 303 | valParserscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#valParser. = strscip-python python python-stdlib 3.11 builtins/str# |
| 304 | stepParserscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#stepParser. = staticmethodscip-python python python-stdlib 3.11 builtins/staticmethod#(_raiseNoStepsscip-python python gavodachs 2.13 `gavo.svcs.pql`/_raiseNoSteps().) |
| 305 | rangeClassscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#rangeClass. = PQLRangescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLRange# |
| 306 | |
| 307 | def __init__scip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__init__().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__init__().(self), rangesscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__init__().(ranges), qualifierscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__init__().(qualifier)=None, destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__init__().(destName)=None): |
| 308 | selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__init__().(self).qualifierscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#qualifier. = qualifierscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__init__().(qualifier) |
| 309 | selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__init__().(self).rangesscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#ranges. = rangesscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__init__().(ranges) |
| 310 | selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__init__().(self).destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#destName. = destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__init__().(destName) |
| 311 | |
| 312 | def __eq__scip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__eq__().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__eq__().(self), otherscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__eq__().(other)): |
| 313 | return (isinstance(otherscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__eq__().(other), PQLParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#) |
| 314 | and selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__eq__().(self).qualifierscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#qualifier.==otherscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__eq__().(other).qualifierscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#qualifier. |
| 315 | and selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__eq__().(self).rangesscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#ranges.==otherscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__eq__().(other).rangesscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#ranges.) |
| 316 | |
| 317 | def __str__scip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__str__().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__str__().(self)): |
| 318 | res = ",".joinscip-python python python-stdlib 3.11 builtins/str#join().(strscip-python python python-stdlib 3.11 builtins/str#(r) for r in selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__str__().(self).rangesscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#ranges.) |
| 319 | if selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__str__().(self).qualifierscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#qualifier.: |
| 320 | res = res+";"+urllibscip-python python python-stdlib 3.11 `urllib.request`/__init__:.parse.quote(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__str__().(self).qualifierscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#qualifier.) |
| 321 | return res |
| 322 | |
| 323 | def __repr__scip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__repr__().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__repr__().(self)): |
| 324 | return "%s(%s)"%(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__repr__().(self).__class__scip-python python python-stdlib 3.11 builtins/object#__class__()..__name__scip-python python python-stdlib 3.11 builtins/__name__#, |
| 325 | repr(strscip-python python python-stdlib 3.11 builtins/str#(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#__repr__().(self)))) |
| 326 | |
| 327 | @staticmethodscip-python python python-stdlib 3.11 builtins/staticmethod# |
| 328 | def _parsePQLStringscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(cls), valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(val), destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(destName)): |
| 329 | # this is the implementation of the fromLiteral class method(s) |
| 330 | # It's static so the fromLiterals can upcall. |
| 331 | if valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(val) is None: |
| 332 | return None |
| 333 | |
| 334 | if valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(val)==clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(cls).nullvalue: |
| 335 | return None |
| 336 | |
| 337 | mat = QUALIFIER_REscip-python python gavodachs 2.13 `gavo.svcs.pql`/QUALIFIER_RE..matchscip-python python python-stdlib 3.11 re/Pattern#match().(valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(val)) |
| 338 | if not mat: |
| 339 | raise basescip-python python gavodachs 2.13 `gavo.base`/__init__:.LiteralParseErrorscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#(destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(destName), valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(val), hintscip-python python gavodachs 2.13 `gavo.utils.excs`/LiteralParseError#__init__().(hint)="Not more than one" |
| 340 | " semicolon is allowed in PQL expressions") |
| 341 | qualifier = _parsePQLValuescip-python python gavodachs 2.13 `gavo.svcs.pql`/_parsePQLValue().(mat.groupscip-python python python-stdlib 3.11 re/Match#group().(2), 1) |
| 342 | |
| 343 | ranges = [] |
| 344 | listLiteral = mat.groupscip-python python python-stdlib 3.11 re/Match#group().(1) |
| 345 | # harmless hack to avoid special-casing for one-element list |
| 346 | rangeMat = rescip-python python python-stdlib 3.11 re/__init__:.matchscip-python python python-stdlib 3.11 re/match().("", listLiteral) |
| 347 | for rangeMat in LIST_REscip-python python gavodachs 2.13 `gavo.svcs.pql`/LIST_RE..finditerscip-python python python-stdlib 3.11 re/Pattern#finditer().(listLiteral): |
| 348 | try: |
| 349 | ranges.appendscip-python python python-stdlib 3.11 builtins/list#append().( |
| 350 | clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(cls).rangeClass.fromLiteral(rangeMat.groupscip-python python python-stdlib 3.11 re/Match#group().(1), destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(destName), |
| 351 | clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(cls).valParser, clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(cls).stepParser)) |
| 352 | except basescip-python python gavodachs 2.13 `gavo.base`/__init__:.LiteralParseErrorscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute# as ex: |
| 353 | ex.posscip-python python gavodachs 2.13 `gavo.utils.excs`/StructureError#pos. = rangeMat.startscip-python python python-stdlib 3.11 re/Match#start().() |
| 354 | raise |
| 355 | ranges.appendscip-python python python-stdlib 3.11 builtins/list#append().( |
| 356 | clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(cls).rangeClass.fromLiteral(listLiteral[rangeMat.endscip-python python python-stdlib 3.11 re/Match#end().():], destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(destName), |
| 357 | clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(cls).valParser, clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(cls).stepParser)) |
| 358 | return clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(cls)(ranges, qualifier, destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(destName)) |
| 359 | |
| 360 | @classmethodscip-python python python-stdlib 3.11 builtins/classmethod# |
| 361 | def fromLiteralscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#fromLiteral().(clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#fromLiteral().(cls), valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#fromLiteral().(val), destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#fromLiteral().(destName)): |
| 362 | """returns a parsed representation of a literal in PQL range-list syntax. |
| 363 | |
| 364 | val is a string containing the PQL expression, destName is a name to |
| 365 | be used for the LiteralParseErrors the function raises when there are |
| 366 | syntax errors in val. |
| 367 | """ |
| 368 | return clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#fromLiteral().(cls)._parsePQLStringscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#fromLiteral().(cls), valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#fromLiteral().(val), destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#fromLiteral().(destName)) |
| 369 | |
| 370 | def getValuesAsSetscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getValuesAsSet().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getValuesAsSet().(self)): |
| 371 | """returns a set of all values mentioned within the PQL expression. |
| 372 | |
| 373 | This raises a ValueError if this is not possible (e.g., due to |
| 374 | non-stepped intervals). |
| 375 | """ |
| 376 | res = setscip-python python python-stdlib 3.11 builtins/set#() |
| 377 | for r in selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getValuesAsSet().(self).rangesscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#ranges.: |
| 378 | res.updatescip-python python python-stdlib 3.11 builtins/set#update().(r.getValuesAsSet()) |
| 379 | return res |
| 380 | |
| 381 | def getSQLscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(self), colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(colName), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(sqlPars), cmpExprscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(cmpExpr)=None): |
| 382 | """returns an SQL condition expressing this PQL constraint for colName. |
| 383 | |
| 384 | The parameters necessary are added to sqlPars. |
| 385 | |
| 386 | cmpExpr can be used to override the cmpExpr argument to PQLRange.getSQL; |
| 387 | this is not really intended for user code, though, but rather for |
| 388 | subclasses of PQLPar |
| 389 | """ |
| 390 | if cmpExprscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(cmpExpr) is None: |
| 391 | cmpExprscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(cmpExpr) = colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(colName) |
| 392 | |
| 393 | if len(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(self).rangesscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#ranges.)==1: # Special case for SQL cosmetics |
| 394 | return selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(self).rangesscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#ranges.[0].getSQL(colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(colName), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(sqlPars), cmpExpr=cmpExprscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(cmpExpr)) |
| 395 | |
| 396 | try: |
| 397 | return "%s IN %%(%s)s"%(cmpExprscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(cmpExpr), basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getSQLKeyscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/getSQLKey().(colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(colName), |
| 398 | selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(self).getValuesAsSetscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getValuesAsSet().(), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(sqlPars))) |
| 399 | except ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#: # at least one open or non-stepped range |
| 400 | return "(%s)"%" OR ".joinscip-python python python-stdlib 3.11 builtins/str#join().( |
| 401 | r.getSQL(colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(colName), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(sqlPars), cmpExpr=cmpExprscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(cmpExpr)) for r in selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(self).rangesscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#ranges.) |
| 402 | |
| 403 | def coversscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#covers().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#covers().(self), valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#covers().(value)): |
| 404 | """returns true if value is within the ranges specified by the PQL |
| 405 | expression. |
| 406 | |
| 407 | value must be type-true, i.e., you are responsible for converting it |
| 408 | into the type the range are in. |
| 409 | """ |
| 410 | for r in selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#covers().(self).rangesscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#ranges.: |
| 411 | if r.covers(valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#covers().(value)): |
| 412 | return True |
| 413 | return False |
| 414 | |
| 415 | |
| 416 | class PQLIntParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLIntPar#(PQLParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#): |
| 417 | """a PQL parameter containing an integer. |
| 418 | |
| 419 | steps in ranges are allowed. |
| 420 | """ |
| 421 | nullvaluescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLIntPar#nullvalue. = "" |
| 422 | valParserscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLIntPar#valParser. = intscip-python python python-stdlib 3.11 builtins/int# |
| 423 | stepParserscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLIntPar#stepParser. = intscip-python python python-stdlib 3.11 builtins/int# |
| 424 | |
| 425 | |
| 426 | class PQLDateParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#(PQLParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#): |
| 427 | """a PQL parameter containing a date. |
| 428 | |
| 429 | steps in ranges are allowed. |
| 430 | |
| 431 | There's an additional complication here: in the database, dates can be |
| 432 | represented in various forms. To save the day, getSQL takes an |
| 433 | additional optional parameter and transforms the input values as |
| 434 | appropriate before passing them to the database. |
| 435 | """ |
| 436 | nullvaluescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#nullvalue. = "" |
| 437 | valParserscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#valParser. = staticmethodscip-python python python-stdlib 3.11 builtins/staticmethod#(literalsscip-python python gavodachs 2.13 `gavo.base.literals`/__init__:.parseDefaultDatetimescip-python python gavodachs 2.13 `gavo.utils.texttricks`/parseDefaultDatetime().) |
| 438 | |
| 439 | @staticmethodscip-python python python-stdlib 3.11 builtins/staticmethod# |
| 440 | def stepParserscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#stepParser().(valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#stepParser().(val)): |
| 441 | return datetimescip-python python python-stdlib 3.11 datetime/__init__:.timedeltascip-python python python-stdlib 3.11 datetime/timedelta#(days=floatscip-python python python-stdlib 3.11 builtins/float#(valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#stepParser().(val))) |
| 442 | |
| 443 | def getSQLscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#getSQL().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#getSQL().(self), colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#getSQL().(colName), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#getSQL().(sqlPars), convertscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#getSQL().(convert)=None): |
| 444 | """returns an SQL condition expressing the PQL constraint for colName. |
| 445 | |
| 446 | In addition to the usual parameters, we here accept an additional |
| 447 | argument convert with possible values None (meaning timestamp, |
| 448 | which is the default) mjd, jd, and jy, which represents how the |
| 449 | datetimes are represented in the database. |
| 450 | """ |
| 451 | converter = { |
| 452 | None: utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__:.identityscip-python python gavodachs 2.13 `gavo.utils.algotricks`/identity()., |
| 453 | "mjd": stcscip-python python gavodachs 2.13 `gavo.stc`/__init__:.dateTimeToMJD, |
| 454 | "jd": stcscip-python python gavodachs 2.13 `gavo.stc`/__init__:.dateTimeToJdn, |
| 455 | "jy": stcscip-python python gavodachs 2.13 `gavo.stc`/__init__:.dateTimeToJYear,}[convertscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#getSQL().(convert)] |
| 456 | |
| 457 | oldKeys = setscip-python python python-stdlib 3.11 builtins/set#(sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#getSQL().(sqlPars).keys()) |
| 458 | res = PQLParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#.getSQLscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#getSQL().(self), colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#getSQL().(colName), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#getSQL().(sqlPars)) |
| 459 | |
| 460 | # now update all keys we are responsible for |
| 461 | if converter: |
| 462 | for key in sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#getSQL().(sqlPars): |
| 463 | if key not in oldKeys: |
| 464 | if sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#getSQL().(sqlPars)[key] is not None: |
| 465 | sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#getSQL().(sqlPars)[key] = converter(sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#getSQL().(sqlPars)[key]) |
| 466 | return res |
| 467 | |
| 468 | |
| 469 | class PQLPositionParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#(PQLParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#): |
| 470 | """a PQL position parameter, as for SSA. |
| 471 | |
| 472 | Cones and intervals or real lists do not mix; we support STC-S |
| 473 | identifiers as qualifiers. |
| 474 | |
| 475 | The literals here are basically two-float lists. |
| 476 | """ |
| 477 | valParserscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#valParser. = floatscip-python python python-stdlib 3.11 builtins/float# |
| 478 | nullvaluescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#nullvalue. = "" |
| 479 | |
| 480 | @classmethodscip-python python python-stdlib 3.11 builtins/classmethod# |
| 481 | def fromLiteralscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#fromLiteral().(clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#fromLiteral().(cls), valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#fromLiteral().(val), destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#fromLiteral().(destName)): |
| 482 | # Hack: allow encodeded commas; this has been seen in the |
| 483 | # wild and would be the saner way to encode this. |
| 484 | if valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#fromLiteral().(val) is not None: |
| 485 | valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#fromLiteral().(val) = valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#fromLiteral().(val).upper().replace("%2C", ",") |
| 486 | return clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#fromLiteral().(cls)._parsePQLStringscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#_parsePQLString().(clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#fromLiteral().(cls), valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#fromLiteral().(val), destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#fromLiteral().(destName)) |
| 487 | |
| 488 | def getSQLscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getSQL().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getSQL().(self), colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getSQL().(colName), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getSQL().(sqlPars)): |
| 489 | raise NotImplementedErrorscip-python python python-stdlib 3.11 builtins/NotImplementedError#("Ranges for PQL POS not implemented yet.") |
| 490 | |
| 491 | def _iterICRSPositionsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#_iterICRSPositions().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#_iterICRSPositions().(self)): |
| 492 | """yields pairs of ICRS (ra, dec) from this condition. |
| 493 | """ |
| 494 | if selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#_iterICRSPositions().(self).qualifierscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#qualifier. and selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#_iterICRSPositions().(self).qualifierscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#qualifier.!='ICRS': |
| 495 | # XXX TODO: implement at least a couple of common frames |
| 496 | raise basescip-python python gavodachs 2.13 `gavo.base`/__init__:.ValidationErrorscip-python python gavodachs 2.13 `gavo.base.structure`/Structure#("Cannot match against coordinates" |
| 497 | " given in %s frame"%selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#_iterICRSPositions().(self).qualifierscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#qualifier., selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#_iterICRSPositions().(self).destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#destName.) |
| 498 | |
| 499 | if len(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#_iterICRSPositions().(self).rangesscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#ranges.)%2: |
| 500 | raise basescip-python python gavodachs 2.13 `gavo.base`/__init__:.ValidationErrorscip-python python gavodachs 2.13 `gavo.base.structure`/Structure#("PQL position values must be lists of" |
| 501 | " length divisible by 2.", selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#_iterICRSPositions().(self).destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#destName.) |
| 502 | lastCoo = None |
| 503 | for r in selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#_iterICRSPositions().(self).rangesscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#ranges.: |
| 504 | if r.value is None: |
| 505 | raise basescip-python python gavodachs 2.13 `gavo.base`/__init__:.ValidationErrorscip-python python gavodachs 2.13 `gavo.base.structure`/Structure#("Ranges are not allowed as cone centers", |
| 506 | selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#_iterICRSPositions().(self).destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#destName.) |
| 507 | if lastCoo is None: |
| 508 | lastCoo = r.value |
| 509 | else: |
| 510 | yield (lastCoo, r.value) |
| 511 | lastCoo = None |
| 512 | |
| 513 | def getConeSQLscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getConeSQL().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getConeSQL().(self), colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getConeSQL().(colName), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getConeSQL().(sqlPars), coneSizescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getConeSQL().(coneSize)): |
| 514 | """returns SQL to compute the constraint against a pgsphere point column. |
| 515 | """ |
| 516 | sizeName = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getSQLKeyscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/getSQLKey().("size", coneSizescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getConeSQL().(coneSize)*DEGscip-python python gavodachs 2.13 `gavo.utils.mathtricks`/DEG., sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getConeSQL().(sqlPars)) |
| 517 | parts = [] |
| 518 | for ra, dec in selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getConeSQL().(self)._iterICRSPositionsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#_iterICRSPositions().(): |
| 519 | parts.appendscip-python python python-stdlib 3.11 builtins/list#append().("%s <@ scircle(%%(%s)s, %%(%s)s)"%(colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getConeSQL().(colName), |
| 520 | basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getSQLKeyscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/getSQLKey().("pos", pgspherescip-python python gavodachs 2.13 `gavo.utils.pgsphere`/__init__:.SPointscip-python python gavodachs 2.13 `gavo.utils.pgsphere`/SPoint#.fromDegreesscip-python python gavodachs 2.13 `gavo.utils.pgsphere`/SPoint#fromDegrees().(ra, dec), |
| 521 | sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getConeSQL().(sqlPars)), sizeName)) |
| 522 | return "(%s)"%" OR ".joinscip-python python python-stdlib 3.11 builtins/str#join().(parts) |
| 523 | |
| 524 | def getQ3CSQLscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getQ3CSQL().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getQ3CSQL().(self), raColscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getQ3CSQL().(raCol), decColscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getQ3CSQL().(decCol), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getQ3CSQL().(sqlPars), coneSizescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getQ3CSQL().(coneSize)): |
| 525 | """returns SQL to compute the constraint against a pgsphere point column. |
| 526 | """ |
| 527 | sizeName = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getSQLKeyscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/getSQLKey().("size", coneSizescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getQ3CSQL().(coneSize), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getQ3CSQL().(sqlPars)) |
| 528 | parts = [] |
| 529 | for ra, dec in selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getQ3CSQL().(self)._iterICRSPositionsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#_iterICRSPositions().(): |
| 530 | parts.appendscip-python python python-stdlib 3.11 builtins/list#append().("q3c_radial_query({}, {}, %({})s, %({})s, %({})s)".format( |
| 531 | raColscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getQ3CSQL().(raCol), decColscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getQ3CSQL().(decCol), |
| 532 | basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getSQLKeyscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/getSQLKey().("ra", ra, sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getQ3CSQL().(sqlPars)), |
| 533 | basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getSQLKeyscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/getSQLKey().("dec", dec, sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#getQ3CSQL().(sqlPars)), |
| 534 | sizeName)) |
| 535 | return "(%s)"%" OR ".joinscip-python python python-stdlib 3.11 builtins/str#join().(parts) |
| 536 | |
| 537 | def coversscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#covers().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#covers().(self), valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#covers().(value)): |
| 538 | raise ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#("%s do not support PQL covers yet. Complain." |
| 539 | " This is fairly easy to fix."%selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPositionPar#covers().(self).__class__scip-python python python-stdlib 3.11 builtins/object#__class__()..__name__scip-python python python-stdlib 3.11 builtins/__name__#) |
| 540 | |
| 541 | |
| 542 | class PQLFloatParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLFloatPar#(PQLParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#): |
| 543 | """a PQL float parameter. |
| 544 | |
| 545 | This has a special getSQLForInterval method for cases like SSA's |
| 546 | BAND. |
| 547 | """ |
| 548 | valParserscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLFloatPar#valParser. = floatscip-python python python-stdlib 3.11 builtins/float# |
| 549 | nullvaluescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLFloatPar#nullvalue. = "" |
| 550 | |
| 551 | def getSQLForIntervalscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLFloatPar#getSQLForInterval().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLFloatPar#getSQLForInterval().(self), lowerColNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLFloatPar#getSQLForInterval().(lowerColName), upperColNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLFloatPar#getSQLForInterval().(upperColName), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLFloatPar#getSQLForInterval().(sqlPars)): |
| 552 | """returns an SQL phrase against an interval in a table. |
| 553 | """ |
| 554 | if len(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLFloatPar#getSQLForInterval().(self).rangesscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#ranges.)==1: # Special case for SQL cosmetics |
| 555 | return selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLFloatPar#getSQLForInterval().(self).rangesscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#ranges.[0].getSQLForInterval( |
| 556 | lowerColNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLFloatPar#getSQLForInterval().(lowerColName), upperColNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLFloatPar#getSQLForInterval().(upperColName), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLFloatPar#getSQLForInterval().(sqlPars)) |
| 557 | else: |
| 558 | return "(%s)"%" OR ".joinscip-python python python-stdlib 3.11 builtins/str#join().( |
| 559 | r.getSQLForInterval(lowerColNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLFloatPar#getSQLForInterval().(lowerColName), upperColNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLFloatPar#getSQLForInterval().(upperColName), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLFloatPar#getSQLForInterval().(sqlPars)) |
| 560 | for r in selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLFloatPar#getSQLForInterval().(self).rangesscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#ranges.) |
| 561 | |
| 562 | |
| 563 | class PQLCaselessParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLCaselessPar#(PQLParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#): |
| 564 | """a PQL string parameter that's compared with case folding. |
| 565 | |
| 566 | Don't count on case folding to work outside of ASCII. |
| 567 | """ |
| 568 | valParserscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLCaselessPar#valParser. = staticmethodscip-python python python-stdlib 3.11 builtins/staticmethod#(lambda val: val and val.lower()) |
| 569 | |
| 570 | def getSQLscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLCaselessPar#getSQL().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLCaselessPar#getSQL().(self), colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLCaselessPar#getSQL().(colName), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLCaselessPar#getSQL().(sqlPars), cmpExprscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLCaselessPar#getSQL().(cmpExpr)=None): |
| 571 | """Overridden to change cmpExpr. |
| 572 | """ |
| 573 | return PQLParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#.getSQLscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getSQL().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLCaselessPar#getSQL().(self), colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLCaselessPar#getSQL().(colName), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLCaselessPar#getSQL().(sqlPars), "LOWER(%s)"%colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLCaselessPar#getSQL().(colName)) |
| 574 | |
| 575 | def coversscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLCaselessPar#covers().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLCaselessPar#covers().(self), valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLCaselessPar#covers().(value)): |
| 576 | if valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLCaselessPar#covers().(value) is None: |
| 577 | return False |
| 578 | return PQLParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#.coversscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#covers().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLCaselessPar#covers().(self), valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLCaselessPar#covers().(value).lower()) |
| 579 | |
| 580 | |
| 581 | class PQLShellPatternParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#(PQLParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#): |
| 582 | """a PQL shell pattern parameter. |
| 583 | |
| 584 | These are posix shell patterns, where no PQL metacharacters are evaluated |
| 585 | at all. |
| 586 | """ |
| 587 | _reOperatorscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#_reOperator. = "~" |
| 588 | |
| 589 | @classmethodscip-python python python-stdlib 3.11 builtins/classmethod# |
| 590 | def fromLiteralscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#fromLiteral().(clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#fromLiteral().(cls), valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#fromLiteral().(val), destNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#fromLiteral().(destName)): |
| 591 | if valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#fromLiteral().(val) is None: |
| 592 | return None |
| 593 | valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#fromLiteral().(val) = getREForShPatscip-python python gavodachs 2.13 `gavo.svcs.pql`/getREForShPat().(valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#fromLiteral().(val)) |
| 594 | return clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#fromLiteral().(cls)([clsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#fromLiteral().(cls).rangeClassscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#rangeClass.(valscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#fromLiteral().(val))]) |
| 595 | |
| 596 | def getSQLscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#getSQL().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#getSQL().(self), colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#getSQL().(colName), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#getSQL().(sqlPars)): |
| 597 | """returns an RE-based query equivalent to the input shell pattern. |
| 598 | """ |
| 599 | return "ssa_targname %s %%(%s)s"%(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#getSQL().(self)._reOperatorscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#_reOperator., |
| 600 | basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getSQLKeyscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/getSQLKey().(colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#getSQL().(colName), selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#getSQL().(self).rangesscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#ranges.[0].value, sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#getSQL().(sqlPars))) |
| 601 | |
| 602 | def coversscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#covers().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#covers().(self), valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#covers().(value)): |
| 603 | raise ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#("%s do not support PQL covers yet. Complain." |
| 604 | " This is easy to fix."%selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#covers().(self).__class__scip-python python python-stdlib 3.11 builtins/object#__class__()..__name__scip-python python python-stdlib 3.11 builtins/__name__#) |
| 605 | |
| 606 | |
| 607 | class PQLNocaseShellPatternParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNocaseShellPatternPar#(PQLShellPatternParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLShellPatternPar#): |
| 608 | """a shell-pattern matching parameter, ignoring case. |
| 609 | """ |
| 610 | _reOperatorscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNocaseShellPatternPar#_reOperator. = "~*" |
| 611 | |
| 612 | |
| 613 | class PQLStringParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLStringPar#(PQLParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#): |
| 614 | """a PQL normal string parameter. |
| 615 | |
| 616 | "normal" means that range expressions are not supported. |
| 617 | """ |
| 618 | rangeClassscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLStringPar#rangeClass. = PQLNoRangescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange# |
| 619 | |
| 620 | |
| 621 | class PQLTextParIRscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLTextParIR#(PQLParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#): |
| 622 | """a PQL string parameter matching "google-like", "Information Retrieval". |
| 623 | |
| 624 | Basically, this matches the input and the database column as document |
| 625 | vectors. Correspondingly, ranges are disallowed. |
| 626 | """ |
| 627 | nullvaluescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLTextParIR#nullvalue. = "" |
| 628 | rangeClassscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLTextParIR#rangeClass. = PQLNoRangescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLNoRange# |
| 629 | |
| 630 | def getSQLscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLTextParIR#getSQL().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLTextParIR#getSQL().(self), colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLTextParIR#getSQL().(colName), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLTextParIR#getSQL().(sqlPars)): |
| 631 | docs = selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLTextParIR#getSQL().(self).getValuesAsSetscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#getValuesAsSet().() |
| 632 | keys = [] |
| 633 | for doc in sortedscip-python python python-stdlib 3.11 builtins/sorted().(docs): |
| 634 | keys.appendscip-python python python-stdlib 3.11 builtins/list#append().(basescip-python python gavodachs 2.13 `gavo.base`/__init__:.getSQLKeyscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/getSQLKey().(colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLTextParIR#getSQL().(colName), doc, sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLTextParIR#getSQL().(sqlPars))) |
| 635 | |
| 636 | return "(%s)"%" OR ".joinscip-python python python-stdlib 3.11 builtins/str#join().( |
| 637 | "to_tsvector('english', %s) @@ plainto_tsquery('english', %%(%s)s)"%( |
| 638 | colNamescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLTextParIR#getSQL().(colName), |
| 639 | keyName) |
| 640 | for keyName in keys) |
| 641 | |
| 642 | def coversscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLTextParIR#covers().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLTextParIR#covers().(self), valuescip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLTextParIR#covers().(value)): |
| 643 | raise ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#("%s do not support PQL covers."%selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLTextParIR#covers().(self).__class__scip-python python python-stdlib 3.11 builtins/object#__class__()..__name__scip-python python python-stdlib 3.11 builtins/__name__#) |
| 644 | |
| 645 | |
| 646 | ######## posix shell patterns hacking (find some better place?) |
| 647 | def _mungeEnumSequencescip-python python gavodachs 2.13 `gavo.svcs.pql`/_mungeEnumSequence().(sscip-python python gavodachs 2.13 `gavo.svcs.pql`/_mungeEnumSequence().(s), pscip-python python gavodachs 2.13 `gavo.svcs.pql`/_mungeEnumSequence().(p), tscip-python python gavodachs 2.13 `gavo.svcs.pql`/_mungeEnumSequence().(t)): |
| 648 | """a pyparsing handler for transforming shell character enumerations to |
| 649 | pcre character enumerations. |
| 650 | |
| 651 | (this is a helper for _getShPatGrammar) |
| 652 | """ |
| 653 | seq = "".joinscip-python python python-stdlib 3.11 builtins/str#join().(tscip-python python gavodachs 2.13 `gavo.svcs.pql`/_mungeEnumSequence().(t)) |
| 654 | # metacharacters in seq are troublesome: ! vs. ^, and we need to |
| 655 | # defuse hyphens, brackets, and backslashes |
| 656 | negate = seq.startswithscip-python python python-stdlib 3.11 builtins/str#startswith().("!") |
| 657 | if negate: |
| 658 | seq = seq[1:] |
| 659 | seq = seq.replacescip-python python python-stdlib 3.11 builtins/str#replace().("]", "\\]" |
| 660 | ).replacescip-python python python-stdlib 3.11 builtins/str#replace().("\\", "\\\\" |
| 661 | ).replacescip-python python python-stdlib 3.11 builtins/str#replace().("-", "\\-") |
| 662 | |
| 663 | if negate: |
| 664 | return "[^%s]"%seq |
| 665 | else: |
| 666 | return "[%s]"%seq |
| 667 | |
| 668 | |
| 669 | @functoolsscip-python python python-stdlib 3.11 functools/__init__:.lru_cachescip-python python python-stdlib 3.11 functools/lru_cache().(1) |
| 670 | def _getShPatGrammarscip-python python gavodachs 2.13 `gavo.svcs.pql`/_getShPatGrammar().(): |
| 671 | """returns a grammar to translate posix shell patterns to posix regular |
| 672 | expressions. |
| 673 | |
| 674 | This is different from fnmatch.translate in that it handles escaping |
| 675 | correctly. |
| 676 | """ |
| 677 | from gavo.utils.parsetricksscip-python python gavodachs 2.13 `gavo.utils.parsetricks`/__init__: import ( |
| 678 | Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#, Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#, CharsNotInscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CharsNotIn#, ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#, QuotedStringscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/QuotedString#, pyparsingWhitecharsscip-python python gavodachs 2.13 `gavo.utils.parsetricks`/pyparsingWhitechars().) |
| 679 | |
| 680 | with pyparsingWhitecharsscip-python python gavodachs 2.13 `gavo.utils.parsetricks`/pyparsingWhitechars().(""): |
| 681 | enumChars = QuotedStringscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/QuotedString#(quoteCharscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/QuotedString#__init__().(quoteChar)="[", endQuoteCharscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/QuotedString#__init__().(endQuoteChar)="]", escCharscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/QuotedString#__init__().(escChar)="\\" |
| 682 | ).addParseActionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#addParseAction().(_mungeEnumSequencescip-python python gavodachs 2.13 `gavo.svcs.pql`/_mungeEnumSequence().) |
| 683 | noEnum = Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#("[").addParseActionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#addParseAction().(lambda s, p, t: "\\[") |
| 684 | star = Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#("*").addParseActionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#addParseAction().(lambda s, p, t: ".*") |
| 685 | questionmark = Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#("?").addParseActionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#addParseAction().(lambda s, p, t: ".") |
| 686 | escSeq = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#(r"\\(.)").addParseActionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#addParseAction().(lambda s, p, t: rescip-python python python-stdlib 3.11 re/__init__:.escapescip-python python python-stdlib 3.11 re/escape().(t[0][1])) |
| 687 | normalStuff = CharsNotInscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CharsNotIn#(r"*?[\\").addParseActionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#addParseAction().(lambda s, p, t: |
| 688 | rescip-python python python-stdlib 3.11 re/__init__:.escapescip-python python python-stdlib 3.11 re/escape().("".joinscip-python python python-stdlib 3.11 builtins/str#join().(t))) |
| 689 | shPat = ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#(escSeq | enumChars | noEnum |
| 690 | | star | questionmark | normalStuff) |
| 691 | return shPat |
| 692 | |
| 693 | |
| 694 | def getREForShPatscip-python python gavodachs 2.13 `gavo.svcs.pql`/getREForShPat().(shPatscip-python python gavodachs 2.13 `gavo.svcs.pql`/getREForShPat().(shPat)): |
| 695 | r"""returns a POSIX RE for a POSIX shell pattern. |
| 696 | |
| 697 | >>> getREForShPat(r"ZU?\*[!A-Z]*") |
| 698 | 'ZU.\\*[^A\\-Z].*' |
| 699 | >>> getREForShPat("no[*") |
| 700 | 'no\\[.*' |
| 701 | """ |
| 702 | return "".joinscip-python python python-stdlib 3.11 builtins/str#join().(utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__:.pyparseStringscip-python python gavodachs 2.13 `gavo.utils.parsetricks`/pyparseString().(_getShPatGrammarscip-python python gavodachs 2.13 `gavo.svcs.pql`/_getShPatGrammar().(), shPatscip-python python gavodachs 2.13 `gavo.svcs.pql`/getREForShPat().(shPat), parseAll=True)) |
| 703 | |
| 704 | ######### end posix shell patterns |
| 705 | |
| 706 | def _makeFactoryscip-python python gavodachs 2.13 `gavo.svcs.pql`/_makeFactory().(parTypescip-python python gavodachs 2.13 `gavo.svcs.pql`/_makeFactory().(parType)): |
| 707 | def factoryscip-python python gavodachs 2.13 `gavo.svcs.pql`/_makeFactory().factory().(fieldscip-python python gavodachs 2.13 `gavo.svcs.pql`/_makeFactory().factory().(field), valscip-python python gavodachs 2.13 `gavo.svcs.pql`/_makeFactory().factory().(val), sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/_makeFactory().factory().(sqlPars)): |
| 708 | try: |
| 709 | return parTypescip-python python gavodachs 2.13 `gavo.svcs.pql`/_makeFactory().(parType).fromLiteral(valscip-python python gavodachs 2.13 `gavo.svcs.pql`/_makeFactory().factory().(val), fieldscip-python python gavodachs 2.13 `gavo.svcs.pql`/_makeFactory().factory().(field).name).getSQL(fieldscip-python python gavodachs 2.13 `gavo.svcs.pql`/_makeFactory().factory().(field).name, sqlParsscip-python python gavodachs 2.13 `gavo.svcs.pql`/_makeFactory().factory().(sqlPars)) |
| 710 | except ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#: |
| 711 | raise basescip-python python gavodachs 2.13 `gavo.base`/__init__:.uiscip-python python gavodachs 2.13 `gavo.base`/ui..logOldExcscip-python python gavodachs 2.13 `gavo.base.events`/EventDispatcher#logOldExc().(utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__:.ValidationErrorscip-python python gavodachs 2.13 `gavo.utils.excs`/Error#( |
| 712 | "Invalid input for type %s" |
| 713 | " (valid PQL literals are described in the help)"%fieldscip-python python gavodachs 2.13 `gavo.svcs.pql`/_makeFactory().factory().(field).type, |
| 714 | fieldscip-python python gavodachs 2.13 `gavo.svcs.pql`/_makeFactory().factory().(field).name)) |
| 715 | return factoryscip-python python gavodachs 2.13 `gavo.svcs.pql`/_makeFactory().factory(). |
| 716 | |
| 717 | |
| 718 | sqlmungescip-python python gavodachs 2.13 `gavo.base.sqlmunge`/__init__:.registerSQLFactoryscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/registerSQLFactory().("pql-int", _makeFactoryscip-python python gavodachs 2.13 `gavo.svcs.pql`/_makeFactory().(PQLIntParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLIntPar#)) |
| 719 | sqlmungescip-python python gavodachs 2.13 `gavo.base.sqlmunge`/__init__:.registerSQLFactoryscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/registerSQLFactory().("pql-float", _makeFactoryscip-python python gavodachs 2.13 `gavo.svcs.pql`/_makeFactory().(PQLFloatParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLFloatPar#)) |
| 720 | sqlmungescip-python python gavodachs 2.13 `gavo.base.sqlmunge`/__init__:.registerSQLFactoryscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/registerSQLFactory().("pql-string", _makeFactoryscip-python python gavodachs 2.13 `gavo.svcs.pql`/_makeFactory().(PQLParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLPar#)) |
| 721 | sqlmungescip-python python gavodachs 2.13 `gavo.base.sqlmunge`/__init__:.registerSQLFactoryscip-python python gavodachs 2.13 `gavo.base.sqlmunge`/registerSQLFactory().("pql-date", _makeFactoryscip-python python gavodachs 2.13 `gavo.svcs.pql`/_makeFactory().(PQLDateParscip-python python gavodachs 2.13 `gavo.svcs.pql`/PQLDatePar#)) |
| 722 | |
| 723 | |
| 724 | class ToPQLTypeConverterscip-python python gavodachs 2.13 `gavo.svcs.pql`/ToPQLTypeConverter#(typesystemsscip-python python gavodachs 2.13 `gavo.base.typesystems`/__init__:.FromSQLConverterscip-python python gavodachs 2.13 `gavo.utils.typeconversions`/FromSQLConverter#): |
| 725 | typeSystemscip-python python gavodachs 2.13 `gavo.svcs.pql`/ToPQLTypeConverter#typeSystem. = "pqlexpr" |
| 726 | simpleMapscip-python python gavodachs 2.13 `gavo.svcs.pql`/ToPQLTypeConverter#simpleMap. = { |
| 727 | "smallint": "pql-int", |
| 728 | "integer": "pql-int", |
| 729 | "int": "pql-int", |
| 730 | "bigint": "pql-int", |
| 731 | "real": "pql-float", |
| 732 | "float": "pql-float", |
| 733 | "double precision": "pql-float", |
| 734 | "double": "pql-float", |
| 735 | "text": "pql-string", |
| 736 | "char": "pql-string", |
| 737 | "date": "pql-date", |
| 738 | "timestamp": "pql-date", |
| 739 | "pql-date": "pql-date", |
| 740 | "pql-float": "pql-float", |
| 741 | "pql-string": "pql-string", |
| 742 | } |
| 743 | |
| 744 | def mapComplexscip-python python gavodachs 2.13 `gavo.svcs.pql`/ToPQLTypeConverter#mapComplex().(selfscip-python python gavodachs 2.13 `gavo.svcs.pql`/ToPQLTypeConverter#mapComplex().(self), sqlTypescip-python python gavodachs 2.13 `gavo.svcs.pql`/ToPQLTypeConverter#mapComplex().(sqlType), lengthscip-python python gavodachs 2.13 `gavo.svcs.pql`/ToPQLTypeConverter#mapComplex().(length)): |
| 745 | if sqlTypescip-python python gavodachs 2.13 `gavo.svcs.pql`/ToPQLTypeConverter#mapComplex().(sqlType)=="char": |
| 746 | return "pql-string" |
| 747 | if sqlTypescip-python python gavodachs 2.13 `gavo.svcs.pql`/ToPQLTypeConverter#mapComplex().(sqlType)=="varchar": |
| 748 | return "pql-string" |
| 749 | |
| 750 | |
| 751 | getPQLTypeForscip-python python gavodachs 2.13 `gavo.svcs.pql`/getPQLTypeFor. = ToPQLTypeConverterscip-python python gavodachs 2.13 `gavo.svcs.pql`/ToPQLTypeConverter#().convertscip-python python gavodachs 2.13 `gavo.utils.typeconversions`/FromSQLConverter#convert(). |
| 752 | |
| 753 | |
| 754 | def adaptInputKeyscip-python python gavodachs 2.13 `gavo.svcs.pql`/adaptInputKey().(inputKeyscip-python python gavodachs 2.13 `gavo.svcs.pql`/adaptInputKey().(inputKey)): |
| 755 | """returns inputKey changed to generate SQL for PQL-like expressions. |
| 756 | |
| 757 | This is used for buildFrom on CondDescs and renderers having |
| 758 | parameterStyle pql. |
| 759 | """ |
| 760 | try: |
| 761 | return inputKeyscip-python python gavodachs 2.13 `gavo.svcs.pql`/adaptInputKey().(inputKey).change( |
| 762 | type=getPQLTypeForscip-python python gavodachs 2.13 `gavo.svcs.pql`/getPQLTypeFor.(inputKeyscip-python python gavodachs 2.13 `gavo.svcs.pql`/adaptInputKey().(inputKey).type), |
| 763 | parent_=None) |
| 764 | except basescip-python python gavodachs 2.13 `gavo.base`/__init__:.ConversionErrorscip-python python gavodachs 2.13 `gavo.base.typesystems`/sqltypeToPG().: # No vexpr type, leave things |
| 765 | pass |
| 766 | return inputKeyscip-python python gavodachs 2.13 `gavo.svcs.pql`/adaptInputKey().(inputKey) |
| 767 | |
| 768 | |
| 769 | # Make the whole thing available to procDefs and such |
| 770 | import sysscip-python python python-stdlib 3.11 sys/__init__: |
| 771 | from gavoscip-python python gavodachs 2.13 gavo/__init__: import rscdefscip-python python gavodachs 2.13 `gavo.rscdef`/__init__: |
| 772 | rscdefscip-python python gavodachs 2.13 `gavo.rscdef`/__init__:.addProcDefObjectscip-python python gavodachs 2.13 `gavo.rscdef.rmkfuncs`/addProcDefObject().("pql", sysscip-python python python-stdlib 3.11 sys/__init__:.modulesscip-python python python-stdlib 3.11 sys/modules.modules.[__name__scip-python python gavodachs 2.13 `gavo.svcs.pql`/]) |
| 773 | |
| 774 | |
| 775 | def _testscip-python python gavodachs 2.13 `gavo.svcs.pql`/_test().(): # pragma: no cover |
| 776 | import doctestscip-python python python-stdlib 3.11 doctest/__init__: |
| 777 | doctestscip-python python python-stdlib 3.11 doctest/__init__:.testmodscip-python python python-stdlib 3.11 doctest/testmod().() |