form.parser.grammar

Attributes

_T

printables

text

numeric

Functions

text_without(→ pyparsing.Word)

Returns all printable text without the given characters.

matches(→ Callable[[ParseResults], bool])

Returns true if the given character matches the token.

literal(→ Callable[[ParseResults], _T])

" Returns the given value, ignoring the tokens alltogether.

as_int(→ int | None)

Converts the token to int if possible.

as_joined_string(→ str)

Joins the given tokens into a single string.

as_decimal(→ decimal.Decimal | None)

Converts the token to decimal if possible.

as_uppercase(→ str | None)

Converts the token to uppercase if possible.

as_integer_range(→ range | None)

Converts the token to an integer range if possible.

as_decimal_range(→ onegov.form.utils.decimal_range | None)

Converts the token to a decimal range if possible.

as_regex(→ Pattern[str] | None)

Converts the token to a working regex if possible.

as_date(→ datetime.date | None)

Converts the token to a date if possible.

approximate_total_days(→ float)

Computes an approximate day delta from a relativedelta.

is_valid_date_range(→ pyparsing.results.ParseResults)

Checks if the date range is valid

as_relative_delta(...)

unwrap(→ Any | None)

Unwraps grouped tokens.

tag(→ Callable[[ParseResults], None])

Takes the given tags and applies them to the token.

with_whitespace_inside(→ pyparsing.Combine)

Returns an expression that allows for whitespace inside, but not

enclosed_in(→ pyparsing.ParserElement)

Wraps the given expression in the given characters.

number_enclosed_in(→ pyparsing.ParserElement)

Wraps numers in the given characters, making sure the result is an int.

choices_enclosed_in(→ pyparsing.ParserElement)

Wraps the given choices in the given characters, making sure only

mark_enclosed_in(→ pyparsing.MatchFirst)

Returns a mark (x) inclosed in the given characters. For example,

textfield(→ pyparsing.ParserElement)

Returns a textfield parser.

textarea(→ pyparsing.ParserElement)

Returns a textarea parser.

code(→ pyparsing.ParserElement)

Returns a code textfield with a specified syntax.

password(→ pyparsing.ParserElement)

Returns a password field parser.

email(→ pyparsing.ParserElement)

Returns an email field parser.

url(→ pyparsing.ParserElement)

Returns an url field parser.

video_url(→ pyparsing.ParserElement)

Returns an video url field parser.

absolute_date(→ pyparsing.ParserElement)

Returns an absolute date parser.

relative_delta(→ pyparsing.ParserElement)

Returns a relative delta parser.

valid_date_range(→ pyparsing.ParserElement)

Returns a valid date range parser.

date(→ pyparsing.ParserElement)

Returns a date parser.

datetime(→ pyparsing.ParserElement)

Returns a datetime parser.

time(→ pyparsing.ParserElement)

Returns a time parser.

stdnum(→ pyparsing.ParserElement)

Returns an stdnum parser.

fileinput(→ pyparsing.ParserElement)

Returns a fileinput parser.

decimal(→ pyparsing.ParserElement)

Returns a decimal parser.

range_field(→ pyparsing.ParserElement)

Generic range field parser.

integer_range_field(→ pyparsing.ParserElement)

Returns an integer range parser.

decimal_range_field(→ pyparsing.ParserElement)

Returns a decimal range parser.

currency(→ pyparsing.ParserElement)

Returns a currency parser.

pricing(→ pyparsing.ParserElement)

Returns a pricing parser.

marker_box(→ pyparsing.ParserElement)

Returns a marker box:

radio(→ pyparsing.ParserElement)

Returns a radio parser:

checkbox(→ pyparsing.ParserElement)

Returns a checkbox parser:

fieldset_title(→ pyparsing.ParserElement)

A fieldset title parser. Fieldset titles are just like headings in

field_identifier(→ pyparsing.ParserElement)

Returns a field identifier parser:

field_help_identifier(→ pyparsing.ParserElement)

Returns parser for a field help comment following a field/fieldset:

Module Contents

form.parser.grammar._T[source]
form.parser.grammar.printables[source]
form.parser.grammar.text[source]
form.parser.grammar.numeric[source]
form.parser.grammar.text_without(characters: str) pyparsing.Word[source]

Returns all printable text without the given characters.

form.parser.grammar.matches(character: str) Callable[[ParseResults], bool][source]

Returns true if the given character matches the token.

form.parser.grammar.literal(value: _T) Callable[[ParseResults], _T][source]

“ Returns the given value, ignoring the tokens alltogether.

form.parser.grammar.as_int(tokens: pyparsing.results.ParseResults) int | None[source]

Converts the token to int if possible.

form.parser.grammar.as_joined_string(tokens: pyparsing.results.ParseResults) str[source]

Joins the given tokens into a single string.

form.parser.grammar.as_decimal(tokens: pyparsing.results.ParseResults) decimal.Decimal | None[source]

Converts the token to decimal if possible.

form.parser.grammar.as_uppercase(tokens: pyparsing.results.ParseResults) str | None[source]

Converts the token to uppercase if possible.

form.parser.grammar.as_integer_range(tokens: pyparsing.results.ParseResults) range | None[source]

Converts the token to an integer range if possible.

form.parser.grammar.as_decimal_range(tokens: pyparsing.results.ParseResults) onegov.form.utils.decimal_range | None[source]

Converts the token to a decimal range if possible.

form.parser.grammar.as_regex(tokens: pyparsing.results.ParseResults) Pattern[str] | None[source]

Converts the token to a working regex if possible.

form.parser.grammar.as_date(instring: str, loc: int, tokens: pyparsing.results.ParseResults) datetime.date | None[source]

Converts the token to a date if possible.

form.parser.grammar.approximate_total_days(delta: dateutil.relativedelta.relativedelta) float[source]

Computes an approximate day delta from a relativedelta.

form.parser.grammar.is_valid_date_range(instring: str, loc: int, tokens: pyparsing.results.ParseResults) pyparsing.results.ParseResults[source]

Checks if the date range is valid

form.parser.grammar.as_relative_delta(tokens: pyparsing.results.ParseResults) dateutil.relativedelta.relativedelta | None[source]
form.parser.grammar.unwrap(tokens: pyparsing.results.ParseResults) Any | None[source]

Unwraps grouped tokens.

form.parser.grammar.tag(**tags: str) Callable[[ParseResults], None][source]

Takes the given tags and applies them to the token.

form.parser.grammar.with_whitespace_inside(expr: pyparsing.ParserElement) pyparsing.Combine[source]

Returns an expression that allows for whitespace inside, but not outside the expression.

form.parser.grammar.enclosed_in(expr: pyparsing.ParserElement, characters: str) pyparsing.ParserElement[source]

Wraps the given expression in the given characters.

form.parser.grammar.number_enclosed_in(characters: str) pyparsing.ParserElement[source]

Wraps numers in the given characters, making sure the result is an int.

form.parser.grammar.choices_enclosed_in(characters: str, choices: Sequence[str]) pyparsing.ParserElement[source]

Wraps the given choices in the given characters, making sure only valid choices are possible.

form.parser.grammar.mark_enclosed_in(characters: str) pyparsing.MatchFirst[source]

Returns a mark (x) inclosed in the given characters. For example, mark_enclosed_in('[]') creates an expression that accepts any of these and sets the result of the ‘x’ value to True, the others to False:

[x]
[ ]
form.parser.grammar.textfield() pyparsing.ParserElement[source]

Returns a textfield parser.

Example:

____[50]

The number defines the maximum length.

Additionally, a regex may be specified to validate the field:

___/[0-9]{4}
form.parser.grammar.textarea() pyparsing.ParserElement[source]

Returns a textarea parser.

Example:

...[5]

The number defines the number of rows.

form.parser.grammar.code() pyparsing.ParserElement[source]

Returns a code textfield with a specified syntax.

Currently only markdown is supported.

Example:

<markdown>
form.parser.grammar.password() pyparsing.ParserElement[source]

Returns a password field parser.

Example:

***
form.parser.grammar.email() pyparsing.ParserElement[source]

Returns an email field parser.

Example:

@@@
form.parser.grammar.url() pyparsing.ParserElement[source]

Returns an url field parser.

Example:

http://
https://
form.parser.grammar.video_url() pyparsing.ParserElement[source]

Returns an video url field parser.

Example:

video-url
form.parser.grammar.absolute_date() pyparsing.ParserElement[source]

Returns an absolute date parser.

Example:

2020.10.10
form.parser.grammar.relative_delta() pyparsing.ParserElement[source]

Returns a relative delta parser.

Example:

+1 days
-4 weeks
0 years
form.parser.grammar.valid_date_range() pyparsing.ParserElement[source]

Returns a valid date range parser.

Example:

(..today)
(2010.01.01..2020.01.01)
(-2 weeks..+4 months)
form.parser.grammar.date() pyparsing.ParserElement[source]

Returns a date parser.

Example:

YYYY.MM.DD
form.parser.grammar.datetime() pyparsing.ParserElement[source]

Returns a datetime parser.

Example:

YYYY.MM.DD HH:MM
form.parser.grammar.time() pyparsing.ParserElement[source]

Returns a time parser.

Example:

HH:MM
form.parser.grammar.stdnum() pyparsing.ParserElement[source]

Returns an stdnum parser.

Example:

# iban
form.parser.grammar.fileinput() pyparsing.ParserElement[source]

Returns a fileinput parser.

For all kindes of files:

*.*

For specific files:

*.pdf|*.doc

For multiple file upload:

*.pdf (multiple)
form.parser.grammar.decimal() pyparsing.ParserElement[source]

Returns a decimal parser.

Decimal point is ‘.’.

For example:

0.00 123 11.1 -10.0

form.parser.grammar.range_field(value_expression: pyparsing.ParserElement, parse_action: Callable[[ParseResults], Any], type: str) pyparsing.ParserElement[source]

Generic range field parser.

form.parser.grammar.integer_range_field() pyparsing.ParserElement[source]

Returns an integer range parser.

form.parser.grammar.decimal_range_field() pyparsing.ParserElement[source]

Returns a decimal range parser.

form.parser.grammar.currency() pyparsing.ParserElement[source]

Returns a currency parser.

For example:

chf USD Cny

form.parser.grammar.pricing() pyparsing.ParserElement[source]

Returns a pricing parser.

For example:

(10.0 CHF) (0 usd!) (-0.50 Cny)

form.parser.grammar.marker_box(characters: str) pyparsing.ParserElement[source]

Returns a marker box:

Example:

(x) Male
[x] Female
{x} What?
form.parser.grammar.radio() pyparsing.ParserElement[source]

Returns a radio parser:

Example::

(x) Male ( ) Female

form.parser.grammar.checkbox() pyparsing.ParserElement[source]

Returns a checkbox parser:

Example::

[x] Male [ ] Female

form.parser.grammar.fieldset_title() pyparsing.ParserElement[source]

A fieldset title parser. Fieldset titles are just like headings in markdown:

# My header

It’s possible to have an empty fieldset title (to disable a fieldset):

# …

form.parser.grammar.field_identifier() pyparsing.ParserElement[source]

Returns a field identifier parser:

Example:

My field *
form.parser.grammar.field_help_identifier() pyparsing.ParserElement[source]

Returns parser for a field help comment following a field/fieldset:

General Example:

<< Help text for My Field >>