51Degrees Pipeline for Python

fiftyone_pipeline_core.callback_url Namespace Reference

Detailed Description

The callback URL the client script posts to for updated JSON.

The protocol and host usually come from the request, and the script holds the URL in a single-quoted string, so the URL is checked before it is written into the script. A URL that is not valid, including one whose protocol is not http or https, is refused. In anything after the authority, and in the endpoint, the characters a URL cannot hold or that could end the string or the script are percent-encoded.

See https://github.com/51Degrees/specifications/blob/main/pipeline-specification/pipeline-elements/javascript-builder.md#callback-url

Functions

 is_blank (text)
 Whether a part of the URL is not set.
 ascii_lower (text)
 The text with the ASCII letters A to Z in lower case and every other character as it is, so that no letter outside ASCII can stand in for an ASCII one, as str.casefold would let the long s stand in for "s".
 is_scheme (protocol)
 Whether the protocol is http or https, ignoring the case of its ASCII letters only.
 callback_url (protocol, host, endpoint)
 Build the callback URL from its parts and check it.
 _checked_host_port (host_port)
 The host and optional port in lower case, or None when they are not valid.
 _is_port (text)
 Whether the text is ':' followed by digits whose value is no more than 65535.
 _is_ipv6 (text)
 Whether the text is an IPv6 address as RFC 3986 section 3.2.2 defines one.
 _groups (run, ipv4_at_end)
 The number of 16 bit groups in a run of groups separated by ':', or -1 when the run is not valid.
 _encoded (text)
 The text with each byte of its UTF-8 encoding percent-encoded where the byte is a control character, a space, outside ASCII or one of ENCODED_CHARACTERS, and with a '' encoded where two hexadecimal digits do not follow it.

Variables

 CallbackUrl = namedtuple("CallbackUrl", ["valid", "url"])
int MAX_PORT = 65535
int MAX_PORT_DIGITS = 5
 ENCODED_CHARACTERS = frozenset(b"\"'<>\\^`{|}")
 HEX_DIGITS = frozenset(b"0123456789ABCDEFabcdef")
 BLANK_PATTERN
tuple SCHEMES = ("http", "https")
 _ASCII_LOWER
 FORBIDDEN_PATTERN = re.compile(r"[?#@]")
 LABEL_PATTERN = re.compile(r"[A-Za-z0-9_-]+")
 NUMBER_LABEL_PATTERN = re.compile(r"[0-9]+|0[xX][0-9A-Fa-f]*")
 PORT_PATTERN = re.compile(r":[0-9]+")
 HEX_GROUP_PATTERN = re.compile(r"[0-9A-Fa-f]{1,4}")
str _DEC_OCTET = r"(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])"
 IPV4_PATTERN = re.compile(_DEC_OCTET + r"(\." + _DEC_OCTET + r"){3}")
 SURROGATE_PATTERN = re.compile(r"[\ud800-\udfff]")

Function Documentation

◆ _checked_host_port()

_checked_host_port ( host_port)
protected

The host and optional port in lower case, or None when they are not valid.

The host is an IPv6 address in brackets, or a name of labels separated by dots with a dot allowed at the end, which is an IPv4 address when its last label is a number. The port is ':' followed by digits up to 65535.

◆ _encoded()

_encoded ( text)
protected

The text with each byte of its UTF-8 encoding percent-encoded where the byte is a control character, a space, outside ASCII or one of ENCODED_CHARACTERS, and with a '' encoded where two hexadecimal digits do not follow it.

◆ _groups()

_groups ( run,
ipv4_at_end )
protected

The number of 16 bit groups in a run of groups separated by ':', or -1 when the run is not valid.

An empty run has none, and an IPv4 address at the end of the run, where one is allowed, counts as two.

◆ _is_ipv6()

_is_ipv6 ( text)
protected

Whether the text is an IPv6 address as RFC 3986 section 3.2.2 defines one.

That is eight groups of one to four hexadecimal digits separated by ':', where one '::' can stand for one or more groups of zeros and the last two groups can be written as an IPv4 address.

◆ _is_port()

_is_port ( text)
protected

Whether the text is ':' followed by digits whose value is no more than 65535.

◆ ascii_lower()

ascii_lower ( text)

The text with the ASCII letters A to Z in lower case and every other character as it is, so that no letter outside ASCII can stand in for an ASCII one, as str.casefold would let the long s stand in for "s".

@type text: str

Parameters
textThe text @rtype: str
Returns
: The text with A to Z in lower case

◆ callback_url()

callback_url ( protocol,
host,
endpoint )

Build the callback URL from its parts and check it.

One slash separates the host and the endpoint, being added when neither has one and removed when both do. The protocol and the host are written in lower case and the rest as given, apart from the percent-encoding. The host value holds no '?', '#' or '@'.

@type protocol: str

Parameters
protocolThe protocol, http or https in any case @type host: str
hostThe host, which can end with a port and a path @type endpoint: str
endpointThe endpoint @rtype: CallbackUrl
Returns
: The callback URL, or None when the protocol, host or endpoint is not set. The URL of an invalid one is as it was built, for the log, with '***' in place of everything in the host before its last '@'.

◆ is_blank()

is_blank ( text)

Whether a part of the URL is not set.

@type text: object

Parameters
textThe part @rtype: bool
Returns
: True if the part is not a string, or is empty or only whitespace

◆ is_scheme()

is_scheme ( protocol)

Whether the protocol is http or https, ignoring the case of its ASCII letters only.

@type protocol: str

Parameters
protocolThe protocol @rtype: bool
Returns
: True if the protocol is http or https

Variable Documentation

◆ _ASCII_LOWER

fiftyone_pipeline_core.callback_url._ASCII_LOWER
protected
Initial value:
= str.maketrans(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")

◆ _DEC_OCTET

str fiftyone_pipeline_core.callback_url._DEC_OCTET = r"(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])"
protected

◆ BLANK_PATTERN

fiftyone_pipeline_core.callback_url.BLANK_PATTERN
Initial value:
= re.compile(
r"[\t-\r \u0085\u00a0\u1680\u2000-\u200a"
r"\u2028\u2029\u202f\u205f\u3000]*")

◆ CallbackUrl

fiftyone_pipeline_core.callback_url.CallbackUrl = namedtuple("CallbackUrl", ["valid", "url"])

◆ ENCODED_CHARACTERS

fiftyone_pipeline_core.callback_url.ENCODED_CHARACTERS = frozenset(b"\"'<>\\^`{|}")

◆ FORBIDDEN_PATTERN

fiftyone_pipeline_core.callback_url.FORBIDDEN_PATTERN = re.compile(r"[?#@]")

◆ HEX_DIGITS

fiftyone_pipeline_core.callback_url.HEX_DIGITS = frozenset(b"0123456789ABCDEFabcdef")

◆ HEX_GROUP_PATTERN

fiftyone_pipeline_core.callback_url.HEX_GROUP_PATTERN = re.compile(r"[0-9A-Fa-f]{1,4}")

◆ IPV4_PATTERN

fiftyone_pipeline_core.callback_url.IPV4_PATTERN = re.compile(_DEC_OCTET + r"(\." + _DEC_OCTET + r"){3}")

◆ LABEL_PATTERN

fiftyone_pipeline_core.callback_url.LABEL_PATTERN = re.compile(r"[A-Za-z0-9_-]+")

◆ MAX_PORT

int fiftyone_pipeline_core.callback_url.MAX_PORT = 65535

◆ MAX_PORT_DIGITS

int fiftyone_pipeline_core.callback_url.MAX_PORT_DIGITS = 5

◆ NUMBER_LABEL_PATTERN

fiftyone_pipeline_core.callback_url.NUMBER_LABEL_PATTERN = re.compile(r"[0-9]+|0[xX][0-9A-Fa-f]*")

◆ PORT_PATTERN

fiftyone_pipeline_core.callback_url.PORT_PATTERN = re.compile(r":[0-9]+")

◆ SCHEMES

tuple fiftyone_pipeline_core.callback_url.SCHEMES = ("http", "https")

◆ SURROGATE_PATTERN

fiftyone_pipeline_core.callback_url.SURROGATE_PATTERN = re.compile(r"[\ud800-\udfff]")