OpenQuizz
Une application de gestion des contenus pédagogiques
flask_restx.inputs Namespace Reference

Data Structures

class  email
 
class  int_range
 
class  regex
 
class  URL
 

Functions

def ipv4 (value)
 
def ipv6 (value)
 
def ip (value)
 
def iso8601interval (value, argument="argument")
 
def date (value)
 
def natural (value, argument="argument")
 
def positive (value, argument="argument")
 
def boolean (value)
 
def datetime_from_rfc822 (value)
 
def datetime_from_iso8601 (value)
 
def date_from_iso8601 (value)
 

Variables

 START_OF_DAY = time(0, 0, 0, tzinfo=pytz.UTC)
 
 END_OF_DAY = time(23, 59, 59, 999999, tzinfo=pytz.UTC)
 
 netloc_regex
 
 email_regex
 
 time_regex = re.compile(r"\d{2}:\d{2}")
 
 url
 

Function Documentation

◆ boolean()

def flask_restx.inputs.boolean (   value)
Parse the string ``"true"`` or ``"false"`` as a boolean (case insensitive).

Also accepts ``"1"`` and ``"0"`` as ``True``/``False`` (respectively).

If the input is from the request JSON body, the type is already a native python boolean,
and will be passed through without further parsing.

:raises ValueError: if the boolean value is invalid

◆ date()

def flask_restx.inputs.date (   value)
Parse a valid looking date in the format YYYY-mm-dd

◆ date_from_iso8601()

def flask_restx.inputs.date_from_iso8601 (   value)
Turns an ISO8601 formatted date into a date object.

Example::

    inputs.date_from_iso8601("2012-01-01")



:param str value: The ISO8601-complying string to transform
:return: A date
:rtype: date
:raises ValueError: if value is an invalid date literal

◆ datetime_from_iso8601()

def flask_restx.inputs.datetime_from_iso8601 (   value)
Turns an ISO8601 formatted date into a datetime object.

Example::

    inputs.datetime_from_iso8601("2012-01-01T23:30:00+02:00")

:param str value: The ISO8601-complying string to transform
:return: A datetime
:rtype: datetime
:raises ValueError: if value is an invalid date literal

◆ datetime_from_rfc822()

def flask_restx.inputs.datetime_from_rfc822 (   value)
Turns an RFC822 formatted date into a datetime object.

Example::

    inputs.datetime_from_rfc822('Wed, 02 Oct 2002 08:00:00 EST')

:param str value: The RFC822-complying string to transform
:return: The parsed datetime
:rtype: datetime
:raises ValueError: if value is an invalid date literal

◆ ip()

def flask_restx.inputs.ip (   value)
Validate an IP address (both IPv4 and IPv6)

◆ ipv4()

def flask_restx.inputs.ipv4 (   value)
Validate an IPv4 address

◆ ipv6()

def flask_restx.inputs.ipv6 (   value)
Validate an IPv6 address

◆ iso8601interval()

def flask_restx.inputs.iso8601interval (   value,
  argument = "argument" 
)
Parses ISO 8601-formatted datetime intervals into tuples of datetimes.

Accepts both a single date(time) or a full interval using either start/end
or start/duration notation, with the following behavior:

- Intervals are defined as inclusive start, exclusive end
- Single datetimes are translated into the interval spanning the
  largest resolution not specified in the input value, up to the day.
- The smallest accepted resolution is 1 second.
- All timezones are accepted as values; returned datetimes are
  localized to UTC. Naive inputs and date inputs will are assumed UTC.

Examples::

    "2013-01-01" -> datetime(2013, 1, 1), datetime(2013, 1, 2)
    "2013-01-01T12" -> datetime(2013, 1, 1, 12), datetime(2013, 1, 1, 13)
    "2013-01-01/2013-02-28" -> datetime(2013, 1, 1), datetime(2013, 2, 28)
    "2013-01-01/P3D" -> datetime(2013, 1, 1), datetime(2013, 1, 4)
    "2013-01-01T12:00/PT30M" -> datetime(2013, 1, 1, 12), datetime(2013, 1, 1, 12, 30)
    "2013-01-01T06:00/2013-01-01T12:00" -> datetime(2013, 1, 1, 6), datetime(2013, 1, 1, 12)

:param str value: The ISO8601 date time as a string
:return: Two UTC datetimes, the start and the end of the specified interval
:rtype: A tuple (datetime, datetime)
:raises ValueError: if the interval is invalid.

◆ natural()

def flask_restx.inputs.natural (   value,
  argument = "argument" 
)
Restrict input type to the natural numbers (0, 1, 2, 3...)

◆ positive()

def flask_restx.inputs.positive (   value,
  argument = "argument" 
)
Restrict input type to the positive integers (1, 2, 3...)

Variable Documentation

◆ email_regex

email_regex
Initial value:
1 = re.compile(
2  r"^" "(?P<local>[^@]*[^@.])" r"@" r"(?P<server>[^@]+(?:\.[^@]+)*)" r"$",
3  re.IGNORECASE,
4 )

◆ END_OF_DAY

END_OF_DAY = time(23, 59, 59, 999999, tzinfo=pytz.UTC)

◆ netloc_regex

netloc_regex
Initial value:
1 = re.compile(
2  r"(?:(?P<auth>[^:@]+?(?::[^:@]*?)?)@)?" # basic auth
3  r"(?:"
4  r"(?P<localhost>localhost)|" # localhost...
5  r"(?P<ipv4>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|" # ...or ipv4
6  r"(?:\[?(?P<ipv6>[A-F0-9]*:[A-F0-9:]+)\]?)|" # ...or ipv6
7  r"(?P<domain>(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?))" # domain...
8  r")"
9  r"(?::(?P<port>\d+))?" # optional port
10  r"$",
11  re.IGNORECASE,
12 )

◆ START_OF_DAY

START_OF_DAY = time(0, 0, 0, tzinfo=pytz.UTC)

◆ time_regex

time_regex = re.compile(r"\d{2}:\d{2}")

◆ url

url
Initial value:
1 = URL(
2  ip=True, auth=True, port=True, local=True, schemes=("http", "https", "ftp", "ftps")
3 )
marshmallow.fields.URL
URL
Definition: fields.py:1934