fault.internet

Parse, Serialize, and Tokenize Resource Indicators

ri provides tools for working with standard IRIs or URIs. However, it is not strict. It does not require exact formatting for a parse operation to succeed; rather, the validation of the output is left to the user.

The module refers to IRI and URI strings as Resource Indicators. The distinction is made as the module deals with a slight generalization where constraints are not enforced or checked.

Entry Points

Types

A parsed indicator is designated a type. The set of possible types is inspired by the URI and IRI standards:

authority

An authority indicator identified by the presence of '://' following the scheme field.

absolute

A colon following the scheme field.

relative

A pair of slashes following the scheme field. Often, the scheme is implied in these cases.

amorphous

The absence of characters that allow the unambiguous identification of a type. Usually indicates a value error.

collections
import

scheme_chars0
data

scheme_chars = '-.+0123456789'

reserved_chars0
data

reserved_chars = "%!*'();:@&=+$,/?#[]"

_pct_encode0
data

_pct_encode = '%%%0.2X'.__mod__

_decode_parts0
function

_decode_parts(string)

decode_percent_escapes0
function

decode_percent_escapes(string)

strict0
function

strict()

Enable strict serializations. When performed on a cached import, this will effect the entire process.

In order to isolate the effect to a certain part of the process, the module should be created from the loader and strict should be called relative to the local copy.

_uri_escape0
data

_uri_escape = (lambda x: ''.join(map(_pct_encode, x.encode('utf-8'))))

_mktrans0
data

_mktrans = (lambda z: str.maketrans({x:_pct_encode(x) for x in [ord(y) for y in z] + list(range(0,33))}))

_percent_translations0
data

_percent_translations = _mktrans("%")

_user_percent_translations0
data

_user_percent_translations = _mktrans("%@:/?#")

_password_percent_translations0
data

_password_percent_translations = _mktrans("%@/?#")

_host_percent_translations0
data

_host_percent_translations = \
_address_percent_translations = \
_port_percent_translations = \
_primary_percent_translations = _mktrans("%/?#")

_fragment_percent_translations0
data

_fragment_percent_translations = _mktrans("%?#")

_query_key_percent_translations0
data

_query_key_percent_translations = _mktrans("%&#=")

_query_value_percent_translations0
data

_query_value_percent_translations = _mktrans("%&#")

Parts0
data

Parts = collections.namedtuple("Parts",
	('type', 'scheme', 'netloc', 'path', 'query', 'fragment')
)

split296%
function

split(iri)

Split an IRI into its base components based on the markers:

(: | ://), /, ?, #

Returns the top-level parts of the IRI as a namedtuple.

splitParameters

iri

A complete IRI or URI.

_scheme_char_set

Undocumented.

join_path0
function

join_path(p)

Join a list of paths(strings) on "/" after escaping them.

unsplit_path0
data

unsplit_path = join_path

split_path0
function

split_path(p)

Return a list of unescaped strings split on "/".

Set fieldproc to str if the components' percent escapes should not be decoded.

join292%
function

join(t)

Make an RI from a split RI(5-tuple)

unsplit0
data

unsplit = join

remap_ipv4_address370%
function

remap_ipv4_address(string)

Recognize IPv4 hosts as addresses.

split_netloc197%
function

split_netloc(netloc)

Split a network location into a 4-tuple, (user, password, host, port).

Set fieldproc to str if the components' percent escapes should not be decoded.

join_netloc0
function

join_netloc(t)

Create a netloc fragment from the given tuple(user, password, host, address, port).

unsplit_netloc0
data

unsplit_netloc = join_netloc

parse_query0
function

parse_query(query)

structure0
function

structure(t)

Create a dictionary from a split RI(5-tuple).

Set fieldproc to str if the components' percent escapes should not be decoded.

construct_query0
function

construct_query(x)

Given a sequence of (key, value) pairs, construct.

construct0
function

construct(x)

Construct a RI tuple(5-tuple) from a dictionary object.

parse0
function

parse(iri)

Parse an RI into a dictionary object. Synonym for structure(split(x)).

Set fieldproc to str if the components' percent escapes should not be decoded.

serialize0
function

serialize(x)

Return an RI from a dictionary object. Synonym for join(construct(x)).

http100%
function

http(struct)

Return the HTTP Request-URI suitable for submission with an HTTP request.

context_tokens200%
function

context_tokens(scheme, type, user, password, host, address, port)

Format the authority fields of a Resource Indicator.

query_tokens220%
function

query_tokens(query)

fragment_tokens30%
function

fragment_tokens(fragment)

path_tokens280%
function

path_tokens(root, path)

tokens50%
function

tokens(struct)

Construct an iterator producing Resource Indicator Tokens. The items are pairs providing the type and the exact text to be used to reconstruct the Resource Indicator parsed into the given struct.