form.parser.grammar =================== .. py:module:: form.parser.grammar Attributes ---------- .. autoapisummary:: form.parser.grammar.printables form.parser.grammar.text form.parser.grammar.numeric form.parser.grammar.word_re form.parser.grammar.no_printable_or_whitespace_re Classes ------- .. autoapisummary:: form.parser.grammar.RelativeDate Functions --------- .. autoapisummary:: form.parser.grammar.text_without_re form.parser.grammar.text_without form.parser.grammar.matches form.parser.grammar.literal form.parser.grammar.as_int form.parser.grammar.as_joined_string form.parser.grammar.as_decimal form.parser.grammar.as_uppercase form.parser.grammar.as_integer_range form.parser.grammar.as_decimal_range form.parser.grammar.as_regex form.parser.grammar.as_date form.parser.grammar.is_valid_date_range form.parser.grammar.is_valid_currency form.parser.grammar.as_relative_date form.parser.grammar.unwrap form.parser.grammar.tag form.parser.grammar.with_whitespace_inside form.parser.grammar.enclosed_in form.parser.grammar.number_enclosed_in form.parser.grammar.choices_enclosed_in form.parser.grammar.mark_enclosed_in form.parser.grammar.textfield form.parser.grammar.textarea form.parser.grammar.code form.parser.grammar.password form.parser.grammar.email form.parser.grammar.url form.parser.grammar.video_url form.parser.grammar.absolute_date form.parser.grammar.relative_date form.parser.grammar.valid_date_range form.parser.grammar.date form.parser.grammar.datetime form.parser.grammar.time form.parser.grammar.stdnum form.parser.grammar.chip_nr form.parser.grammar.fileinput form.parser.grammar.decimal form.parser.grammar.range_field form.parser.grammar.integer_range_field form.parser.grammar.decimal_range_field form.parser.grammar.currency form.parser.grammar.pricing form.parser.grammar.discount form.parser.grammar.marker_box form.parser.grammar.radio form.parser.grammar.checkbox form.parser.grammar.fieldset_title form.parser.grammar.field_identifier form.parser.grammar.field_help_identifier Module Contents --------------- .. py:data:: printables .. py:data:: text .. py:data:: numeric .. py:data:: word_re :value: '[]+' .. py:data:: no_printable_or_whitespace_re :value: '[^]' .. py:function:: text_without_re(characters: str) -> str Returns a re group for text without the given characters. .. py:function:: text_without(characters: str) -> pyparsing.Word Returns all printable text without the given characters. .. py:function:: matches(character: str) -> collections.abc.Callable[[pyparsing.results.ParseResults], bool] Returns true if the given character matches the token. .. py:function:: literal[T](value: T) -> collections.abc.Callable[[pyparsing.results.ParseResults], T] " Returns the given value, ignoring the tokens alltogether. .. py:function:: as_int(tokens: pyparsing.results.ParseResults) -> int | None Converts the token to int if possible. .. py:function:: as_joined_string(tokens: pyparsing.results.ParseResults) -> str Joins the given tokens into a single string. .. py:function:: as_decimal(tokens: pyparsing.results.ParseResults) -> decimal.Decimal | None Converts the token to decimal if possible. .. py:function:: as_uppercase(tokens: pyparsing.results.ParseResults) -> str | None Converts the token to uppercase if possible. .. py:function:: as_integer_range(tokens: pyparsing.results.ParseResults) -> range | None Converts the token to an integer range if possible. .. py:function:: as_decimal_range(tokens: pyparsing.results.ParseResults) -> onegov.form.utils.decimal_range | None Converts the token to a decimal range if possible. .. py:function:: as_regex(tokens: pyparsing.results.ParseResults) -> re.Pattern[str] | None Converts the token to a working regex if possible. .. py:function:: as_date(instring: str, loc: int, tokens: pyparsing.results.ParseResults) -> datetime.date | None Converts the token to a date if possible. .. py:function:: is_valid_date_range(instring: str, loc: int, tokens: pyparsing.results.ParseResults) -> pyparsing.results.ParseResults Checks if the date range is valid .. py:function:: is_valid_currency(instring: str, loc: int, tokens: pyparsing.results.ParseResults) -> str | None .. py:class:: RelativeDate(grain: Literal['days', 'weeks', 'months', 'years'] | None = None, offset: int = 0) Bases: :py:obj:`dateutil.relativedelta.relativedelta` The relativedelta type is designed to be applied to an existing datetime and can replace specific components of that datetime, or represents an interval of time. It is based on the specification of the excellent work done by M.-A. Lemburg in his `mx.DateTime `_ extension. However, notice that this type does *NOT* implement the same algorithm as his work. Do *NOT* expect it to behave like mx.DateTime's counterpart. There are two different ways to build a relativedelta instance. The first one is passing it two date/datetime classes:: relativedelta(datetime1, datetime2) The second one is passing it any number of the following keyword arguments:: relativedelta(arg1=x,arg2=y,arg3=z...) year, month, day, hour, minute, second, microsecond: Absolute information (argument is singular); adding or subtracting a relativedelta with absolute information does not perform an arithmetic operation, but rather REPLACES the corresponding value in the original datetime with the value(s) in relativedelta. years, months, weeks, days, hours, minutes, seconds, microseconds: Relative information, may be negative (argument is plural); adding or subtracting a relativedelta with relative information performs the corresponding arithmetic operation on the original datetime value with the information in the relativedelta. weekday: One of the weekday instances (MO, TU, etc) available in the relativedelta module. These instances may receive a parameter N, specifying the Nth weekday, which could be positive or negative (like MO(+1) or MO(-2)). Not specifying it is the same as specifying +1. You can also use an integer, where 0=MO. This argument is always relative e.g. if the calculated date is already Monday, using MO(1) or MO(-1) won't change the day. To effectively make it absolute, use it in combination with the day argument (e.g. day=1, MO(1) for first Monday of the month). leapdays: Will add given days to the date found, if year is a leap year, and the date found is post 28 of february. yearday, nlyearday: Set the yearday or the non-leap year day (jump leap days). These are converted to day/month/leapdays information. There are relative and absolute forms of the keyword arguments. The plural is relative, and the singular is absolute. For each argument in the order below, the absolute form is applied first (by setting each attribute to that value) and then the relative form (by adding the value to the attribute). The order of attributes considered when this relativedelta is added to a datetime is: 1. Year 2. Month 3. Day 4. Hours 5. Minutes 6. Seconds 7. Microseconds Finally, weekday is applied, using the rule described above. For example >>> from datetime import datetime >>> from dateutil.relativedelta import relativedelta, MO >>> dt = datetime(2018, 4, 9, 13, 37, 0) >>> delta = relativedelta(hours=25, day=1, weekday=MO(1)) >>> dt + delta datetime.datetime(2018, 4, 2, 14, 37) First, the day is set to 1 (the first of the month), then 25 hours are added, to get to the 2nd day and 14th hour, finally the weekday is applied, but since the 2nd is already a Monday there is no effect. .. py:attribute:: grain :value: None .. py:attribute:: offset :value: 0 .. py:method:: serialize() -> dict[str, Any] .. py:property:: approximate_total_days :type: float .. py:method:: __lt__(other: RelativeDate) -> bool .. py:method:: __format__(format_spec: str) -> str .. py:method:: __str__() -> str .. py:method:: __get_pydantic_core_schema__(source_type: Any, handler: pydantic.GetCoreSchemaHandler) -> pydantic_core.CoreSchema :classmethod: .. py:method:: __get_pydantic_json_schema__(_schema: pydantic_core.CoreSchema, handler: pydantic.GetJsonSchemaHandler) -> pydantic.json_schema.JsonSchemaValue :classmethod: .. py:function:: as_relative_date(tokens: pyparsing.results.ParseResults) -> RelativeDate | None .. py:function:: unwrap(tokens: pyparsing.results.ParseResults) -> Any | None Unwraps grouped tokens. .. py:function:: tag(**tags: str) -> collections.abc.Callable[[pyparsing.results.ParseResults], None] Takes the given tags and applies them to the token. .. py:function:: with_whitespace_inside(expr: pyparsing.ParserElement) -> pyparsing.Combine Returns an expression that allows for whitespace inside, but not outside the expression. .. py:function:: enclosed_in(expr: pyparsing.ParserElement, characters: str) -> pyparsing.ParserElement Wraps the given expression in the given characters. .. py:function:: number_enclosed_in(characters: str) -> pyparsing.ParserElement Wraps numers in the given characters, making sure the result is an int. .. py:function:: choices_enclosed_in(characters: str, choices: collections.abc.Sequence[str]) -> pyparsing.ParserElement Wraps the given choices in the given characters, making sure only valid choices are possible. .. py:function:: mark_enclosed_in(characters: str) -> pyparsing.MatchFirst 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] [ ] .. py:function:: textfield() -> pyparsing.ParserElement 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} .. py:function:: textarea() -> pyparsing.ParserElement Returns a textarea parser. Example:: ...[5] The number defines the number of rows. .. py:function:: code() -> pyparsing.ParserElement Returns a code textfield with a specified syntax. Currently only markdown is supported. Example:: .. py:function:: password() -> pyparsing.ParserElement Returns a password field parser. Example:: *** .. py:function:: email() -> pyparsing.ParserElement Returns an email field parser. Example:: @@@ .. py:function:: url() -> pyparsing.ParserElement Returns an url field parser. Example:: http:// https:// .. py:function:: video_url() -> pyparsing.ParserElement Returns an video url field parser. Example:: video-url .. py:function:: absolute_date() -> pyparsing.ParserElement Returns an absolute date parser. Example:: 2020.10.10 .. py:function:: relative_date() -> pyparsing.ParserElement Returns a relative date parser. Example:: +1 days -4 weeks 0 years .. py:function:: valid_date_range() -> pyparsing.ParserElement Returns a valid date range parser. Example:: (..today) (2010.01.01..2020.01.01) (-2 weeks..+4 months) .. py:function:: date() -> pyparsing.ParserElement Returns a date parser. Example:: YYYY.MM.DD .. py:function:: datetime() -> pyparsing.ParserElement Returns a datetime parser. Example:: YYYY.MM.DD HH:MM .. py:function:: time() -> pyparsing.ParserElement Returns a time parser. Example:: HH:MM .. py:function:: stdnum() -> pyparsing.ParserElement Returns an stdnum parser. Example:: # iban .. py:function:: chip_nr() -> pyparsing.ParserElement Returns a chip number parser. Example:: chip-nr .. py:function:: fileinput() -> pyparsing.ParserElement Returns a fileinput parser. For all kindes of files:: *.* For specific files:: *.pdf|*.doc For multiple file upload:: *.pdf (multiple) .. py:function:: decimal() -> pyparsing.ParserElement Returns a decimal parser. Decimal point is '.'. For example: 0.00 123 11.1 -10.0 .. py:function:: range_field(value_expression: pyparsing.ParserElement, parse_action: collections.abc.Callable[[pyparsing.results.ParseResults], Any], type: str) -> pyparsing.ParserElement Generic range field parser. .. py:function:: integer_range_field() -> pyparsing.ParserElement Returns an integer range parser. .. py:function:: decimal_range_field() -> pyparsing.ParserElement Returns a decimal range parser. .. py:function:: currency() -> pyparsing.ParserElement Returns a currency parser. For example: chf USD Cny .. py:function:: pricing() -> pyparsing.ParserElement Returns a pricing parser. For example: (10.0 CHF) (0 usd!) (-0.50 Cny) .. py:function:: discount() -> pyparsing.ParserElement Returns a discount parser. For example: (100%) (-25 %) (33.3%) .. py:function:: marker_box(characters: str) -> pyparsing.ParserElement Returns a marker box: Example:: (x) Male [x] Female {x} What? .. py:function:: radio() -> pyparsing.ParserElement Returns a radio parser: Example:: (x) Male ( ) Female .. py:function:: checkbox() -> pyparsing.ParserElement Returns a checkbox parser: Example:: [x] Male [ ] Female .. py:function:: fieldset_title() -> pyparsing.ParserElement 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): # ... .. py:function:: field_identifier() -> pyparsing.ParserElement Returns a field identifier parser: Example:: My field * .. py:function:: field_help_identifier() -> pyparsing.ParserElement Returns parser for a field help comment following a field/fieldset: General Example: << Help text for My Field >>