File: api.rst

package info (click to toggle)
hyperlink 21.0.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 472 kB
  • sloc: python: 3,113; makefile: 160
file content (106 lines) | stat: -rw-r--r-- 2,513 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
.. _hyperlink_api:

Hyperlink API
=============

.. automodule:: hyperlink._url

.. contents::
   :local:

Creation
--------

Before you can work with URLs, you must create URLs.

Parsing Text
^^^^^^^^^^^^

If you already have a textual URL, the easiest way to get URL objects
is with the :func:`parse()` function:

.. autofunction:: hyperlink.parse

By default, :func:`~hyperlink.parse()` returns an instance of
:class:`DecodedURL`, a URL type that handles all encoding for you, by
wrapping the lower-level :class:`URL`.

DecodedURL
^^^^^^^^^^

.. autoclass:: hyperlink.DecodedURL
.. automethod:: hyperlink.DecodedURL.from_text

The Encoded URL
^^^^^^^^^^^^^^^

The lower-level :class:`URL` looks very similar to the
:class:`DecodedURL`, but does not handle all encoding cases for
you. Use with caution.

.. note::

   :class:`URL` is also available as an alias,
   ``hyperlink.EncodedURL`` for more explicit usage.

.. autoclass:: hyperlink.URL
.. automethod:: hyperlink.URL.from_text

Transformation
--------------

Once a URL is created, some of the most common tasks are to transform
it into other URLs and text.

.. automethod:: hyperlink.URL.to_text
.. automethod:: hyperlink.URL.to_uri
.. automethod:: hyperlink.URL.to_iri
.. automethod:: hyperlink.URL.replace
.. automethod:: hyperlink.URL.normalize

Navigation
----------

Go places with URLs. Simulate browser behavior and perform semantic
path operations.

.. automethod:: hyperlink.URL.click
.. automethod:: hyperlink.URL.sibling
.. automethod:: hyperlink.URL.child

Query Parameters
----------------

CRUD operations on the query string multimap.

.. automethod:: hyperlink.URL.get
.. automethod:: hyperlink.URL.add
.. automethod:: hyperlink.URL.set
.. automethod:: hyperlink.URL.remove

Attributes
----------

URLs have many parts, and URL objects have many attributes to represent them.

.. autoattribute:: hyperlink.URL.absolute
.. autoattribute:: hyperlink.URL.scheme
.. autoattribute:: hyperlink.URL.host
.. autoattribute:: hyperlink.URL.port
.. autoattribute:: hyperlink.URL.path
.. autoattribute:: hyperlink.URL.query
.. autoattribute:: hyperlink.URL.fragment
.. autoattribute:: hyperlink.URL.userinfo
.. autoattribute:: hyperlink.URL.user
.. autoattribute:: hyperlink.URL.rooted

Low-level functions
-------------------

A couple of notable helpers used by the :class:`~hyperlink.URL` type.

.. autoclass:: hyperlink.URLParseError
.. autofunction:: hyperlink.register_scheme
.. autofunction:: hyperlink.parse

.. TODO: run doctests in docs?