Skip to main content

This module provides regular expressions according to RFC 3986 “Uniform Resource Identifier (URI): Generic Syntax” and RFC 3987 “Internationalized Resource Identifiers (IRIs)”, and utilities for composition and relative resolution of references:

patterns

A dict of regular expressions keyed by rule names for URIs and rule names for IRIs.

>>> u = regex.compile('^%s$' % patterns['URI'])
>>> m = u.match(u'http://tools.ietf.org/html/rfc3986#appendix-A')
>>> assert m.groupdict() == dict(scheme=u'http',
...                              authority=u'tools.ietf.org',
...                              userinfo=None, host=u'tools.ietf.org',
...                              port=None, path=u'/html/rfc3986',
...                              query=None, fragment=u'appendix-A')
>>> assert not u.match(u'urn:\U00010300')
>>> assert regex.match('^%s$' % patterns['IRI'], u'urn:\U00010300')
>>> assert not regex.match('^%s$' % patterns['relative_ref'], '#f#g')
compose

Returns an URI composed from named parts.

resolve

Resolves an URI reference relative to a base URI.

Test cases:

>>> base = "http://a/b/c/d;p?q"
>>> for relative, resolved in {
...     "g:h"           :  "g:h",
...     "g"             :  "http://a/b/c/g",
...     "./g"           :  "http://a/b/c/g",
...     "g/"            :  "http://a/b/c/g/",
...     "/g"            :  "http://a/g",
...     "//g"           :  "http://g",
...     "?y"            :  "http://a/b/c/d;p?y",
...     "g?y"           :  "http://a/b/c/g?y",
...     "#s"            :  "http://a/b/c/d;p?q#s",
...     "g#s"           :  "http://a/b/c/g#s",
...     "g?y#s"         :  "http://a/b/c/g?y#s",
...     ";x"            :  "http://a/b/c/;x",
...     "g;x"           :  "http://a/b/c/g;x",
...     "g;x?y#s"       :  "http://a/b/c/g;x?y#s",
...     ""              :  "http://a/b/c/d;p?q",
...     "."             :  "http://a/b/c/",
...     "./"            :  "http://a/b/c/",
...     ".."            :  "http://a/b/",
...     "../"           :  "http://a/b/",
...     "../g"          :  "http://a/b/g",
...     "../.."         :  "http://a/",
...     "../../"        :  "http://a/",
...     "../../g"       :  "http://a/g",
...     "../../../g"    :  "http://a/g",
...     "../../../../g" :  "http://a/g",
...     "/./g"          :  "http://a/g",
...     "/../g"         :  "http://a/g",
...     "g."            :  "http://a/b/c/g.",
...     ".g"            :  "http://a/b/c/.g",
...     "g.."           :  "http://a/b/c/g..",
...     "..g"           :  "http://a/b/c/..g",
...     "./../g"        :  "http://a/b/g",
...     "./g/."         :  "http://a/b/c/g/",
...     "g/./h"         :  "http://a/b/c/g/h",
...     "g/../h"        :  "http://a/b/c/h",
...     "g;x=1/./y"     :  "http://a/b/c/g;x=1/y",
...     "g;x=1/../y"    :  "http://a/b/c/y",
...     }.iteritems():
...     assert resolve(base, relative) == resolved

If return_parts is True, returns a dict of named parts instead of a string.

Metadata

Release files for rfc3987 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rfc3987 1.2.1
File Size Uploaded
rfc3987-1.2.1.tar.gz 5.3 kB Details

Release files / rfc3987-1.2.1.tar.gz

Download URL rfc3987-1.2.1.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
13fc7b7a7c827f408968d83b20b3d6b09dd626a5bba3a53af3689d40d1916395
BLAKE2b-256 checksum
How to use checksums
09ca61fa927437e54b56c5c7945aa9ae7731599b510cf28fd1731804a0f23e31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.3.8

2 release files

1.3.7

2 release files

1.3.6

2 release files

1.3.5

2 release files

1.3.4

1 release file

1.3.3

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

This release

1.2.1 This release

1 release file

1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page