Skip to content

Commit d817d4b

Browse files
committed
Use black to format the codebase and fix docs
Enforce that black requires no changes in Travis as well. Furthermore, re-enable our docs building and validation on Travis by fixing our doctests. For some reason, using the `.. doctest::` directive and tracebacks in Sphinx causes problems with pygments' pycon3 lexer and so we have to use the less explicit doctest format in our plain-rST docs.
1 parent 1ca99c9 commit d817d4b

28 files changed

+1366
-1116
lines changed

.travis.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
language: python
2-
sudo: false
32
before_script:
43
- pip install tox codecov
54

@@ -17,13 +16,15 @@ matrix:
1716
env: TOXENV=py36
1817
- python: 3.7
1918
env: TOXENV=py37
20-
dist: xenial
21-
sudo: true
19+
- python: 3.8
20+
env: TOXENV=py38
2221
- python: pypy
2322
env: TOXENV=pypy
2423
- python: 3.6
25-
env: TOXENV=flake8
26-
#- env: TOXENV=docs
24+
env: TOXENV=lint
25+
BLACK_ARGS='--check'
26+
- python: 3.7
27+
env: TOXENV=docs
2728

2829
notifications:
2930
on_success: change

docs/source/_static/.keep

Whitespace-only changes.

docs/source/user/validating.rst

Lines changed: 96 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,25 @@ Let's assume that we're building something that takes user input for a URL and
2424
we want to ensure that URL is only ever using a specific domain with https. In
2525
that case, our code would look like this:
2626

27-
.. doctest::
28-
29-
>>> from rfc3986 import validators, uri_reference
30-
>>> user_url = 'https://github.com/sigmavirus24/rfc3986'
31-
>>> validator = validators.Validator().allow_schemes(
32-
... 'https',
33-
... ).allow_hosts(
34-
... 'github.com',
35-
... )
36-
>>> validator.validate(uri_reference(
37-
... 'https://github.com/sigmavirus24/rfc3986'
38-
... ))
39-
>>> validator.validate(uri_reference(
40-
... 'https://github.com/'
41-
... ))
42-
>>> validator.validate(uri_reference(
43-
... 'http://example.com'
44-
... ))
45-
Traceback (most recent call last):
46-
...
47-
rfc3986.exceptions.UnpermittedComponentError
27+
>>> from rfc3986 import validators, uri_reference
28+
>>> user_url = 'https://github.com/sigmavirus24/rfc3986'
29+
>>> validator = validators.Validator().allow_schemes(
30+
... 'https',
31+
... ).allow_hosts(
32+
... 'github.com',
33+
... )
34+
>>> validator.validate(uri_reference(
35+
... 'https://github.com/sigmavirus24/rfc3986'
36+
... ))
37+
>>> validator.validate(uri_reference(
38+
... 'https://github.com/'
39+
... ))
40+
>>> validator.validate(uri_reference(
41+
... 'http://example.com'
42+
... ))
43+
Traceback (most recent call last):
44+
...
45+
rfc3986.exceptions.UnpermittedComponentError
4846

4947
First notice that we can easily reuse our validator object for each URL.
5048
This allows users to not have to constantly reconstruct Validators for each
@@ -65,36 +63,34 @@ Next, let's imagine that we want to prevent leaking user credentials. In that
6563
case, we want to ensure that there is no password in the user information
6664
portion of the authority. In that case, our new validator would look like this:
6765

68-
.. doctest::
69-
70-
>>> from rfc3986 import validators, uri_reference
71-
>>> user_url = 'https://github.com/sigmavirus24/rfc3986'
72-
>>> validator = validators.Validator().allow_schemes(
73-
... 'https',
74-
... ).allow_hosts(
75-
... 'github.com',
76-
... ).forbid_use_of_password()
77-
>>> validator.validate(uri_reference(
78-
... 'https://github.com/sigmavirus24/rfc3986'
79-
... ))
80-
>>> validator.validate(uri_reference(
81-
... 'https://github.com/'
82-
... ))
83-
>>> validator.validate(uri_reference(
84-
... 'http://example.com'
85-
... ))
86-
Traceback (most recent call last):
87-
...
88-
rfc3986.exceptions.UnpermittedComponentError
89-
>>> validator.validate(uri_reference(
90-
... 'https://[email protected]'
91-
... ))
92-
>>> validator.validate(uri_reference(
93-
... 'https://sigmavirus24:[email protected]'
94-
... ))
95-
Traceback (most recent call last):
96-
...
97-
rfc3986.exceptions.PasswordForbidden
66+
>>> from rfc3986 import validators, uri_reference
67+
>>> user_url = 'https://github.com/sigmavirus24/rfc3986'
68+
>>> validator = validators.Validator().allow_schemes(
69+
... 'https',
70+
... ).allow_hosts(
71+
... 'github.com',
72+
... ).forbid_use_of_password()
73+
>>> validator.validate(uri_reference(
74+
... 'https://github.com/sigmavirus24/rfc3986'
75+
... ))
76+
>>> validator.validate(uri_reference(
77+
... 'https://github.com/'
78+
... ))
79+
>>> validator.validate(uri_reference(
80+
... 'http://example.com'
81+
... ))
82+
Traceback (most recent call last):
83+
...
84+
rfc3986.exceptions.UnpermittedComponentError
85+
>>> validator.validate(uri_reference(
86+
... 'https://[email protected]'
87+
... ))
88+
>>> validator.validate(uri_reference(
89+
... 'https://sigmavirus24:[email protected]'
90+
... ))
91+
Traceback (most recent call last):
92+
...
93+
rfc3986.exceptions.PasswordForbidden
9894

9995
Requiring the Presence of Components
10096
------------------------------------
@@ -104,47 +100,43 @@ components for validation. For example, we assume that we will have a URL that
104100
has a scheme and hostname. However, our current validation doesn't require
105101
those items exist.
106102

107-
.. doctest::
108-
109-
>>> from rfc3986 import validators, uri_reference
110-
>>> user_url = 'https://github.com/sigmavirus24/rfc3986'
111-
>>> validator = validators.Validator().allow_schemes(
112-
... 'https',
113-
... ).allow_hosts(
114-
... 'github.com',
115-
... ).forbid_use_of_password()
116-
>>> validator.validate(uri_reference('//github.com'))
117-
>>> validator.validate(uri_reference('https:/'))
103+
>>> from rfc3986 import validators, uri_reference
104+
>>> user_url = 'https://github.com/sigmavirus24/rfc3986'
105+
>>> validator = validators.Validator().allow_schemes(
106+
... 'https',
107+
... ).allow_hosts(
108+
... 'github.com',
109+
... ).forbid_use_of_password()
110+
>>> validator.validate(uri_reference('//github.com'))
111+
>>> validator.validate(uri_reference('https:/'))
118112

119113
In the first case, we have a host name but no scheme and in the second we have
120114
a scheme and a path but no host. If we want to ensure that those components
121115
are there and that they are *always* what we allow, then we must add one last
122116
item to our validator:
123117

124-
.. doctest::
125-
126-
>>> from rfc3986 import validators, uri_reference
127-
>>> user_url = 'https://github.com/sigmavirus24/rfc3986'
128-
>>> validator = validators.Validator().allow_schemes(
129-
... 'https',
130-
... ).allow_hosts(
131-
... 'github.com',
132-
... ).forbid_use_of_password(
133-
... ).require_presence_of(
134-
... 'scheme', 'host',
135-
... )
136-
>>> validator.validate(uri_reference('//github.com'))
137-
Traceback (most recent call last):
138-
...
139-
rfc3986.exceptions.MissingComponentError
140-
>>> validator.validate(uri_reference('https:/'))
141-
Traceback (most recent call last):
142-
...
143-
rfc3986.exceptions.MissingComponentError
144-
>>> validator.validate(uri_reference('https://github.com'))
145-
>>> validator.validate(uri_reference(
146-
... 'https://github.com/sigmavirus24/rfc3986'
147-
... ))
118+
>>> from rfc3986 import validators, uri_reference
119+
>>> user_url = 'https://github.com/sigmavirus24/rfc3986'
120+
>>> validator = validators.Validator().allow_schemes(
121+
... 'https',
122+
... ).allow_hosts(
123+
... 'github.com',
124+
... ).forbid_use_of_password(
125+
... ).require_presence_of(
126+
... 'scheme', 'host',
127+
... )
128+
>>> validator.validate(uri_reference('//github.com'))
129+
Traceback (most recent call last):
130+
...
131+
rfc3986.exceptions.MissingComponentError
132+
>>> validator.validate(uri_reference('https:/'))
133+
Traceback (most recent call last):
134+
...
135+
rfc3986.exceptions.MissingComponentError
136+
>>> validator.validate(uri_reference('https://github.com'))
137+
>>> validator.validate(uri_reference(
138+
... 'https://github.com/sigmavirus24/rfc3986'
139+
... ))
148140

149141

150142
Checking the Validity of Components
@@ -156,26 +148,24 @@ examples we can also check that a URI is valid per :rfc:`3986`. The validation
156148
of the components is pre-determined so all we need to do is specify which
157149
components we want to validate:
158150

159-
.. doctest::
160-
161-
>>> from rfc3986 import validators, uri_reference
162-
>>> valid_uri = uri_reference('https://github.com/')
163-
>>> validator = validators.Validator().allow_schemes(
164-
... 'https',
165-
... ).allow_hosts(
166-
... 'github.com',
167-
... ).forbid_use_of_password(
168-
... ).require_presence_of(
169-
... 'scheme', 'host',
170-
... ).check_validity_of(
171-
... 'scheme', 'host', 'path',
172-
... )
173-
>>> validator.validate(valid_uri)
174-
>>> invalid_uri = valid_uri.copy_with(path='/#invalid/path')
175-
>>> validator.validate(invalid_uri)
176-
Traceback (most recent call last):
177-
...
178-
rfc3986.exceptions.InvalidComponentsError
151+
>>> from rfc3986 import validators, uri_reference
152+
>>> valid_uri = uri_reference('https://github.com/')
153+
>>> validator = validators.Validator().allow_schemes(
154+
... 'https',
155+
... ).allow_hosts(
156+
... 'github.com',
157+
... ).forbid_use_of_password(
158+
... ).require_presence_of(
159+
... 'scheme', 'host',
160+
... ).check_validity_of(
161+
... 'scheme', 'host', 'path',
162+
... )
163+
>>> validator.validate(valid_uri)
164+
>>> invalid_uri = valid_uri.copy_with(path='/#invalid/path')
165+
>>> validator.validate(invalid_uri)
166+
Traceback (most recent call last):
167+
...
168+
rfc3986.exceptions.InvalidComponentsError
179169

180170
Paths are not allowed to contain a ``#`` character unless it's
181171
percent-encoded. This is why our ``invalid_uri`` raises an exception when we

src/rfc3986/__init__.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,26 @@
3131
from .api import urlparse
3232
from .parseresult import ParseResult
3333

34-
__title__ = 'rfc3986'
35-
__author__ = 'Ian Stapleton Cordasco'
36-
__author_email__ = '[email protected]'
37-
__license__ = 'Apache v2.0'
38-
__copyright__ = 'Copyright 2014 Rackspace; 2016 Ian Stapleton Cordasco'
39-
__version__ = '1.4.0'
34+
__title__ = "rfc3986"
35+
__author__ = "Ian Stapleton Cordasco"
36+
__author_email__ = "[email protected]"
37+
__license__ = "Apache v2.0"
38+
__copyright__ = "Copyright 2014 Rackspace; 2016 Ian Stapleton Cordasco"
39+
__version__ = "1.4.0"
4040

4141
__all__ = (
42-
'ParseResult',
43-
'URIReference',
44-
'IRIReference',
45-
'is_valid_uri',
46-
'normalize_uri',
47-
'uri_reference',
48-
'iri_reference',
49-
'urlparse',
50-
'__title__',
51-
'__author__',
52-
'__author_email__',
53-
'__license__',
54-
'__copyright__',
55-
'__version__',
42+
"ParseResult",
43+
"URIReference",
44+
"IRIReference",
45+
"is_valid_uri",
46+
"normalize_uri",
47+
"uri_reference",
48+
"iri_reference",
49+
"urlparse",
50+
"__title__",
51+
"__author__",
52+
"__author_email__",
53+
"__license__",
54+
"__copyright__",
55+
"__version__",
5656
)

0 commit comments

Comments
 (0)