Package gavo :: Package svcs :: Module pql :: Class PQLPar
[frames] | no frames]

Class PQLPar

source code

object --+
         |
        PQLPar
Known Subclasses:

a representation for PQL expressions.

PQLPar objects have an attribute qualifier (None or a string), and an attribute ranges, a list of PQLRange objects.

As a client, you will ususally construct PQLPar objects using the fromLiteral class method; it takes a PQL literal and a name to be used for LiteralParseErrors it may raise.

The plain PQLPar parses string ranges and does not allow steps.

Inheriting classes must override the valParser and stepParser attributes. Both take a string and have to return a typed value or raise a ValueError if the string does not contain a proper literal. The default for valParser is str, the default for stepParser a function that always raises a ValueError.

PQLPars usually support a covers(value) method that you can pass a value having the required type; it will return whether or not value would be picked up by the condition formulated in PQL. Some advanced PQLPars do not support this method and will raise a ValueError if called.

Since "PQL" is totally crazy, not even the range parser is constant. It seems string ranges were never meant to be supported, and therefore we support RangeClass. PQLRange allows the "/" syntax and is supposed to work for most things but strings. PQLNoRange is just always a simple value.

Note: valParser and stepParser must not be *methods* of the class but plain functions; since they are function-like class attributes, you will usually have to wrap them in staticmethods

Nested Classes
  valParser
str(object='') -> string
  rangeClass
a representation of a PQL range.
Instance Methods
 
__init__(self, ranges, qualifier=None, destName=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
__eq__(self, other) source code
 
__str__(self)
str(x)
source code
 
__repr__(self)
repr(x)
source code
 
getValuesAsSet(self)
returns a set of all values mentioned within the PQL expression.
source code
 
getSQL(self, colName, sqlPars, cmpExpr=None)
returns an SQL condition expressing this PQL constraint for colName.
source code
 
covers(self, value)
returns true if value is within the ranges specified by the PQL expression.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Class Methods
 
fromLiteral(cls, val, destName)
returns a parsed representation of a literal in PQL range-list syntax.
source code
Static Methods
 
stepParser(val) source code
Class Variables
  nullvalue = None
hash(x)
Properties

Inherited from object: __class__

Method Details

__init__(self, ranges, qualifier=None, destName=None)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

fromLiteral(cls, val, destName)
Class Method

source code 

returns a parsed representation of a literal in PQL range-list syntax.

val is a string containing the PQL expression, destName is a name to be used for the LiteralParseErrors the function raises when there are syntax errors in val.

getValuesAsSet(self)

source code 

returns a set of all values mentioned within the PQL expression.

This raises a ValueError if this is not possible (e.g., due to non-stepped intervals).

getSQL(self, colName, sqlPars, cmpExpr=None)

source code 

returns an SQL condition expressing this PQL constraint for colName.

The parameters necessary are added to sqlPars.

cmpExpr can be used to override the cmpExpr argument to PQLRange.getSQL; this is not really intended for user code, though, but rather for subclasses of PQLPar

covers(self, value)

source code 

returns true if value is within the ranges specified by the PQL expression.

value must be type-true, i.e., you are responsible for converting it into the type the range are in.