Checks if a value is either None or an instance of the specified type.
Use with isinstance() as in:
isinstance(X, maybe(T))
Checks if a value is an instance of one of the specified types.
Use with isinstance() as in:
isinstance(X, oneof(T1, T2, ...))
Checks if a value is a list containing elements of the specified type.
Use with isinstance() as in:
isinstance(X, listof(T))
Checks if a value is a set containing elements of the specified type.
Use with isinstance() as in:
isinstance(X, setof(T))
Checks if a value is a tuple with the fixed number of elements of the specified types.
Use with isinstance() as in:
isinstance(X, tupleof(T1, T2, ..., TN))
Checks if a value is a dictionary with keys and elements of the specified types.
Use with isinstance() as in:
isinstance(X, dictof(T1, T2))
Checks if a value is an omap object with elements of the specified type.
Use with isinstance() as in:
isinstance(X, omapof(T))
Checks if a value is a subclass of the specified class.
Use with isinstance() as in:
isinstance(X, subclassof(T))
Checks if a value is a file or a file-like object.
Usage:
isinstance(X, filelike())
Takes two lists; checks if each element of the first list is a subclass of the corresponding element in the second list.
Verifies that the given value is a finite number.
Strips indentation from a docstring; also removes leading and trailing blank lines.
Converts a string to a valid HTSQL identifier.
The given text value is transformed as follows:
Replaces non-printable and reserved characters with %XX sequences.
Converts the text value to a valid string literal.
This function escapes all non-printable characters and wraps the text value in single quotes.
Checks if model is similar to sample.
Use for error reporting to suggest alternatives for an unknown model identifier.
Reads the input text in blocks matching some regular expressions.
Rewinds to the beginning of the text.
Checks if the head of the buffer matches the given pattern.
Reads a text block matching the given pattern from the head of the buffer.
pull() skips whitespace characters and comments at the head of the buffer.
Generates an exception with a fragment of the buffer at the current position included in the error message.
Returns: RuntimeError instance
Sorts elements with respect to the given partial order.
Takes a list of elements and a partial order relation. Returns the elements reordered to satisfy the given order.
This function raises RuntimeError if order is not a valid partial order (contains loops) or when is_total is set and order is not a valid total order.
Implements a cached property decorator.
The decorator calls the getter function on the first access to the property and saves the result. Any subsequent access to the property returns the saved value.
Usage:
class C(object):
@cachedproperty
def field(self):
# Called once to calculate the field value.
# [...]
return value
An ordered immutable mapping.
This container behaves like an immutable dict object with one exception: iterating over the container produces values (rather than keys) in the order they were added to the container.
An ordered mutable mapping.
This container behaves like a dict object with one exception: iterating over the container produces values (rather than keys) in the order they were added to the container.
Overriding an entry does not change its position; delete and insert the entry to move it to the end.
A clonable object.
Subclasses of Clonable can use clone() and clone_to() methods to create a clone of the given object with a specified set of attributes replaced.
Subclasses of Clonable must follow the following conventions:
Clones the object assigning new values to selected attributes.
Clones the object changing its type and assigning new values to selected attributes.
An immutable object with by-value comparison semantics.
A subclass of Hashable should reimplement __basis__() to produce a tuple of all object attributes which uniquely identify the object.
Two Hashable instances are considered equal if they are of the same type and their basis vectors are equal.
An object with default string representation.
A subclass of Printable is expected to reimplement the __unicode__() method.
Parameters of a database connection.
Parses a connection URI and returns a corresponding DB instance.
value: str, unicode, dict or DB
Returns: DB
A connection URI is a string of the form:
engine://username:password@host:port/database?options
The engine and database fragments are mandatory; the others could be omitted.
If a fragment contains separator characters which cannot be represented literally (such as :, /, @ or ?), the characters should be escaped using %-encoding.
If the connection URI is not in a valid format, ValueError is raised.
parse() also accepts:
Imports all modules (including subpackages) in a package.
An exception as an HTTP response.
An instance of HTTPError serves as a simple WSGI application generating an appropriate HTTP error code and displaying the error message.
HTTP status line.
Represents 400 Bad Request.
Represents 403 Forbidden.
Represents 404 Not Found.
Represents 409 Conflict.
Represents 500 Internal Server Error.
Represents 501 Not Implemented.
An error generated by the database driver.
An error caused by lack of read or write permissions.
A fragment of an HTSQL query.
A Mark object represents a fragment of an HTSQL query to be used as an error context for error reporting.
Generates a new Mark object as a cover for a fragment collection.
Returns a list of lines that forms an excerpt of the original query string with ^ characters underlining the marked fragment.
The htsql.core.syn package defines the grammar of HTSQL and implements the HTSQL parser. Call parse.parse() to convert a raw query string to a syntax tree. This conversion is performed in three steps:
A lexical token.
A syntax node.
Represents a syntax node with no meaning.
Use when a syntax node is required structurally, but no regular nodes are available.
A skip symbol.
/
Assignment expression.
<larm> := <rarm>
Left-hand side of an assignment expression.
<larm>
<larm> . <larm> ...
<larm> . <larm> ... (<rarm>, ...)
Function or operator application.
This is an abstract class; concrete subclasses correspond to different syntax forms of functions and operators.
Function call notation.
<identifier> (<arm>, ...)
Pipe notation for function application.
<larm> :<identifier>
<larm> :<identifier> <rarm>
<larm> :<identifier> (<rarm>, ...)
<larm> /:<identifier> (<rarm>, ...)
Binary operator.
<larm> <symbol> <rarm>
Unary operator.
<symbol> <arm>
Filtering operator.
<larm> ? <rarm>
Projection operator.
<larm> ^ <rarm>
Linking operator (deprecated).
<larm> -> <rarm>
Attachment operator.
<larm> @ <rarm>
Detachment operator.
@ <arm>
Collection operator.
/ <arm>
Sorting direction indicator.
<arm> +
<arm> -
Composition expression.
<larm> . <rarm>
Unpacking expression.
*
* <index>
* (<index>)
The lift symbol.
^
An expression in parentheses.
(<arm>)
Selection operator.
<larm> {...}
Location operator.
<larm> [...]
Record constructor.
{<arm>, ...}
List constructor.
(<arm>, ...)
Identity constructor.
[<arm> . ...]
(<arm> . ...)
Reference expression.
$ <identifier>
An identifier.
<text>
A literal expression.
This is an abstract class; concrete subclasses for different forms of literal expressions.
A string literal.
A string literal is a sequence of characters enclosed in single quotes.
A label literal.
A label literal is a sequence of alphanumeric characters or - in an identity constructor.
A number literal.
An integer literal.
A decimal literal.
A decimal literal is a number with a decimal point.
A float literal.
A float literal is a number in exponential notation.
Removes transmission artefacts.
%-encoded octets are decoded; the input text is converted to Unicode.
Returns a lexical scanner for HTSQL grammar.
Tokenizes the input query string.
Returns a syntax parser for HTSQL grammar.
Defines a lexical grammar and generates a tokenizer.
Adds and returns a new tokenizer rule.
Adds and returns a signal rule.
A signal rule injects a signal token in front of a matched sequence of tokens.
A string of the form:
<name>: <pattern>
where <name> is the name of a defined signal token, <pattern> is a regular expression for matching a sequence of tokens.
Tokenizer context for a lexical grammar.
Adds a token pattern.
A string of the form:
<name>: <pattern>
where <name> is the token code, <pattern> is a regular expression for matching input characters.
Defines a syntax grammar and generates a parser.
Adds and returns a production rule.
A string of the form:
<name>: <pattern>
where <name> is the production name, <pattern> is a regular expression for matching tokens and other productions.
An HTSQL data type.
A domain specifies the type of a value. Most HTSQL domains correspond to SQL data types, others represent HTSQL containers (record, list) or used only in special circumstances.
A value of a specific domain could be represented in two forms:
Methods parse() and dump() translate values from one form to the other.
Converts an HTSQL literal to a native Python object.
Raises ValueError if the literal is not in a valid format.
Converts a native Python object to an HTSQL literal.
Represents data and its type.
Instances of Value are iterable and permit len() operator when the data type is ListDomain.
In Boolean context, an instance of Value evaluates to False if and only if data is None.
Describes the structure of data.
Represents data and associated metadata.
A domain with no values (except null).
This is an abstract class.
A domain without any valid values.
This domain is could be used when a domain object is required structurally, but has no semantics.
The type of class entities.
Since class entities are not observable directly in HTSQL model, this domain does not support any values.
Represents a yet undetermined type.
This domain is assigned to HTSQL literals temporarily until the actual domain could be derived from the context.
A Boolean data type.
Valid literals: 'true', 'false'.
Valid native objects: bool values.
A numeric data type.
This is an abstract superclass for integer, float and decimal numbers.
Class attributes:
A binary integer data type.
Valid literals: integers (in base 10) with an optional sign.
Valid native objects: int or long values.
An IEEE 754 float data type.
Valid literals: floating-point numbers in decimal or exponential format.
Valid native objects: float values.
An exact decimal data type.
Valid literals: floating-point numbers in decimal or exponential format.
Valid native objects: decimal.Decimal objects.
A text data type.
Valid literals: any.
Valid native object: unicode values; the NUL character is not allowed.
An enumeration data type.
An enumeration domain has a predefined finite set of valid text values.
A date data type.
Valid literals: valid dates in the form YYYY-MM-DD.
Valid native objects: datetime.date values.
A time data type.
Valid literals: valid time values in the form HH:MM[:SS[.SSSSSS]].
Valid native objects: datetime.time values.
A date+time data type.
Valid literals: valid date+time values in the form YYYY-MM-DD HH:MM[:SS[.SSSSSS]].
Valid native objects: datetime.datetime values.
An unsupported SQL data type.
This domain is used for SQL data types not supported by HTSQL.
Valid literals: any.
Valid native objects: any.
A record value.
Record is implemented as a tuple with named fields.
Generates a Record subclass with the given fields.
List of desired field names (None for a field to have no name).
A field may get no or another name assigned if the desired field name is not available for some reason; e.g., if it is is already taked by another field or if it coincides with a Python keyword.
A container type.
This is an abstract superclass for container domains.
A variable-size collection of homogenous entries.
Valid literals: quoted entries, comma-separated and wrapped in ( and ).
Valid native objects: list values.
A fixed-size collection of heterogenous entries.
Valid literals: quoted entries, comma-separated and wrapped in { and }.
Valid native objects: tuple values.
An identity value.
ID is a tuple with a string representation that produces the identity value in literal form.
A unique identifier of a database entity.
Valid literals: identity constructors as in HTSQL grammar; outer brackets are optional and always stripped.
Valid native objects: tuple values.