Skip to content

Commit 72a4441

Browse files
authored
Merge pull request #409 from twisted/rtd-shiny
Shinier documentation
2 parents 6291b35 + 0a814ed commit 72a4441

22 files changed

+164
-172
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Features
2626
--------
2727

2828
- treq now ships type annotations. (`#366 <https://github.com/twisted/treq/issues/366>`__)
29-
- The new :mod:`treq.cookies` module provides helper functions for working with `http.cookiejar.Cookie` and `CookieJar` objects. (`#384 <https://github.com/twisted/treq/issues/384>`__)
29+
- The new :mod:`treq.cookies` module provides helper functions for working with `http.cookiejar.Cookie` and :class:`~http.cookiejar.CookieJar` objects. (`#384 <https://github.com/twisted/treq/issues/384>`__)
3030
- Python 3.13 is now supported. (`#391 <https://github.com/twisted/treq/issues/391>`__)
3131

3232

@@ -40,7 +40,7 @@ Deprecations and Removals
4040
-------------------------
4141

4242
- Mixing the *json* argument with *files* or *data* now raises `TypeError`. (`#297 <https://github.com/twisted/treq/issues/297>`__)
43-
- Passing non-string (`str` or `bytes`) values as part of a dict to the *headers* argument now results in a `TypeError`, as does passing any collection other than a `dict` or `Headers` instance. (`#302 <https://github.com/twisted/treq/issues/302>`__)
43+
- Passing non-string (`str` or `bytes`) values as part of a dict to the *headers* argument now results in a `TypeError`, as does passing any collection other than a `dict` or :class:`~twisted.web.http.http_headers.Headers` instance. (`#302 <https://github.com/twisted/treq/issues/302>`__)
4444
- Support for Python 3.7 and PyPy 3.8, which have reached end of support, has been dropped. (`#378 <https://github.com/twisted/treq/issues/378>`__)
4545

4646

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ treq: High-level Twisted HTTP Client API
2424

2525
``treq`` is an HTTP library inspired by
2626
`requests <https://requests.readthedocs.io/>`_ but written on top of
27-
`Twisted <https://www.twistedmatrix.com>`_'s
28-
`Agents <https://twistedmatrix.com/documents/current/api/twisted.web.client.Agent.html>`_.
27+
`Twisted <https://twisted.org/>`_'s
28+
`Agents <https://docs.twisted.org/en/stable/api/twisted.web.client.Agent.html>`_.
2929

3030
It provides a simple, higher level API for making HTTP requests when
3131
using Twisted.

changelog.d/409.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update documentation to use `async`/`await` syntax

docs/conf.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,18 @@
2626

2727
# Add any Sphinx extension module names here, as strings. They can be extensions
2828
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
29-
extensions = ["sphinx.ext.viewcode", "sphinx.ext.autodoc", "sphinx.ext.intersphinx"]
29+
extensions = [
30+
"sphinx.ext.viewcode",
31+
"sphinx.ext.autodoc",
32+
"sphinx.ext.intersphinx",
33+
"sphinx_rtd_theme",
34+
]
3035

3136
# Add any paths that contain templates here, relative to this directory.
3237
templates_path = ["_templates"]
3338

3439
# The suffix of source filenames.
35-
source_suffix = ".rst"
40+
source_suffix = {".rst": "restructuredtext"}
3641

3742
# The encoding of source files.
3843
# source_encoding = 'utf-8-sig'
@@ -92,12 +97,15 @@
9297

9398
# The theme to use for HTML and HTML Help pages. See the documentation for
9499
# a list of builtin themes.
95-
html_theme = "default"
100+
html_theme = "sphinx_rtd_theme"
101+
102+
# https://docs.readthedocs.com/platform/stable/intro/sphinx.html#set-the-canonical-url
103+
html_baseurl = os.environ.get("READTHEDOCS_CANONICAL_URL", "/")
96104

97105
# Theme options are theme-specific and customize the look and feel of a theme
98106
# further. For a list of options available for each theme, see the
99107
# documentation.
100-
# html_theme_options = {}
108+
html_theme_options = {"flyout_display": "attached"}
101109

102110
# Add any paths that contain custom themes here, relative to this directory.
103111
# html_theme_path = []

docs/examples/_utils.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
from __future__ import print_function
2-
31
import treq
42

53

6-
def print_response(response):
4+
async def print_response(response):
75
print(response.code, response.phrase)
86
print(response.headers)
9-
10-
return treq.text_content(response).addCallback(print)
7+
print(await treq.text_content(response))

docs/examples/basic_auth.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
from twisted.internet.task import react
21
from _utils import print_response
2+
from twisted.internet.task import react
33

44
import treq
55

66

7-
def main(reactor, *args):
8-
d = treq.get(
9-
'https://httpbin.org/basic-auth/treq/treq',
10-
auth=('treq', 'treq')
7+
async def basic_auth(reactor):
8+
resp = await treq.get(
9+
"https://httpbin.org/basic-auth/treq/treq",
10+
auth=("treq", "treq"),
1111
)
12-
d.addCallback(print_response)
13-
return d
12+
await print_response(resp)
13+
1414

15-
react(main, [])
15+
react(basic_auth)

docs/examples/basic_get.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from twisted.internet.task import react
2-
from _utils import print_response
32

43
import treq
54

65

7-
def main(reactor, *args):
8-
d = treq.get('https://httpbin.org/get')
9-
d.addCallback(print_response)
10-
return d
6+
async def basic_get(reactor):
7+
resp = await treq.get("https://httpbin.org/get")
8+
print(resp.code, resp.phrase)
9+
print(resp.headers)
10+
print(await resp.text())
1111

12-
react(main, [])
12+
13+
react(basic_get)

docs/examples/basic_post.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
from twisted.internet.task import react
21
from _utils import print_response
2+
from twisted.internet.task import react
33

44
import treq
55

66

7-
def main(reactor):
8-
d = treq.post("https://httpbin.org/post",
9-
data={"form": "data"})
10-
d.addCallback(print_response)
11-
return d
7+
def basic_post(reactor):
8+
resp = await treq.post(
9+
"https://httpbin.org/post",
10+
data={"form": "data"},
11+
)
12+
await print_response(resp)
13+
1214

13-
react(main, [])
15+
react(basic_post)

docs/examples/basic_url.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
# -*- encoding: utf-8 -*-
1+
from _utils import print_response
22
from hyperlink import DecodedURL
33
from twisted.internet.task import react
4-
from _utils import print_response
54

65
import treq
76

8-
def main(reactor):
7+
8+
async def basic_url(reactor):
99
url = (
10-
DecodedURL.from_text(u"https://httpbin.org")
11-
.child(u"get") # add path /get
12-
.add(u"foo", u"&") # add query ?foo=%26
10+
DecodedURL.from_text("https://httpbin.org")
11+
.child("get") # add path /get
12+
.add("foo", "&") # add query ?foo=%26
1313
)
1414
print(url.to_text())
15-
return treq.get(url).addCallback(print_response)
15+
await print_response(await treq.get(url))
16+
1617

17-
react(main, [])
18+
react(basic_url)

docs/examples/custom_agent.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
from treq.client import HTTPClient
21
from _utils import print_response
32
from twisted.internet.task import react
43
from twisted.web.client import Agent
54

6-
def make_custom_agent(reactor):
7-
return Agent(reactor, connectTimeout=42)
5+
from treq.client import HTTPClient
6+
87

9-
def main(reactor, *args):
10-
agent = make_custom_agent(reactor)
11-
http_client = HTTPClient(agent)
12-
d = http_client.get(
13-
'https://secure.example.net/area51',
14-
auth=('admin', "you'll never guess!"))
15-
d.addCallback(print_response)
16-
return d
8+
async def custom_agent(reactor):
9+
my_agent = Agent(reactor, connectTimeout=42)
10+
http_client = HTTPClient(my_agent)
11+
resp = await http_client.get(
12+
"https://secure.example.net/area51",
13+
auth=("admin", "you'll never guess!"),
14+
)
15+
await print_response(resp)
1716

18-
react(main, [])
1917

18+
react(custom_agent)

0 commit comments

Comments
 (0)