Skip to content

Commit

Permalink
dropped aiohttp.get(), aiohttp.options(), aiohttp.head(),
Browse files Browse the repository at this point in the history
 aiohttp.post(), aiohttp.put(), aiohttp.patch(), aiohttp.delete(),
 and aiohttp.ws_connect() aio-libs#1593
  • Loading branch information
Nikolay Kim committed Feb 8, 2017
1 parent fc126aa commit 568f690
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 379 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ CHANGES
use `app.add_subapp()` instead #1592

- Dropped: `Application.finish()` and `Application.register_on_finish()` #1602

- Dropped: aiohttp.get(), aiohttp.options(), aiohttp.head(), aiohttp.post(),
aiohttp.put(), aiohttp.patch(), aiohttp.delete(), and aiohttp.ws_connect() #1593
64 changes: 1 addition & 63 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
from .errors import WSServerHandshakeError
from .helpers import TimeService

__all__ = ('ClientSession', 'request', 'get', 'options', 'head',
'delete', 'post', 'put', 'patch', 'ws_connect')
__all__ = ('ClientSession', 'request')

PY_35 = sys.version_info >= (3, 5)

Expand Down Expand Up @@ -747,64 +746,3 @@ def request(method, url, *,
proxy=proxy,
proxy_auth=proxy_auth,),
session=session)


def get(url, **kwargs):
warnings.warn("Use ClientSession().get() instead", DeprecationWarning)
return request(hdrs.METH_GET, url, **kwargs)


def options(url, **kwargs):
warnings.warn("Use ClientSession().options() instead", DeprecationWarning)
return request(hdrs.METH_OPTIONS, url, **kwargs)


def head(url, **kwargs):
warnings.warn("Use ClientSession().head() instead", DeprecationWarning)
return request(hdrs.METH_HEAD, url, **kwargs)


def post(url, **kwargs):
warnings.warn("Use ClientSession().post() instead", DeprecationWarning)
return request(hdrs.METH_POST, url, **kwargs)


def put(url, **kwargs):
warnings.warn("Use ClientSession().put() instead", DeprecationWarning)
return request(hdrs.METH_PUT, url, **kwargs)


def patch(url, **kwargs):
warnings.warn("Use ClientSession().patch() instead", DeprecationWarning)
return request(hdrs.METH_PATCH, url, **kwargs)


def delete(url, **kwargs):
warnings.warn("Use ClientSession().delete() instead", DeprecationWarning)
return request(hdrs.METH_DELETE, url, **kwargs)


def ws_connect(url, *, protocols=(), timeout=10.0, connector=None, auth=None,
ws_response_class=ClientWebSocketResponse, autoclose=True,
autoping=True, loop=None, origin=None, headers=None):

warnings.warn("Use ClientSession().ws_connect() instead",
DeprecationWarning)
if loop is None:
loop = asyncio.get_event_loop()

if connector is None:
connector = aiohttp.TCPConnector(loop=loop, force_close=True)

session = aiohttp.ClientSession(loop=loop, connector=connector, auth=auth,
ws_response_class=ws_response_class,
headers=headers)

return _DetachedWSRequestContextManager(
session._ws_connect(url,
protocols=protocols,
timeout=timeout,
autoclose=autoclose,
autoping=autoping,
origin=origin),
session=session)
186 changes: 0 additions & 186 deletions docs/client_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -562,192 +562,6 @@ certification chaining.
URLs may be either :class:`str` or :class:`~yarl.URL`


.. coroutinefunction:: get(url, **kwargs)

Perform a GET request.

:param url: Requested URL, :class:`str` or :class:`~yarl.URL`.

:param \*\*kwargs: Optional arguments that :func:`request` takes.

:return: :class:`ClientResponse` or derived from

.. deprecated:: 0.21

Use :meth:`ClientSession.get`.

.. versionchanged:: 1.1

URLs may be either :class:`str` or :class:`~yarl.URL`

.. coroutinefunction:: options(url, **kwargs)

Perform an OPTIONS request.

:param url: Requested URL, :class:`str` or :class:`~yarl.URL`.

:param \*\*kwargs: Optional arguments that :func:`request` takes.

:return: :class:`ClientResponse` or derived from

.. deprecated:: 0.21

Use :meth:`ClientSession.options`.

.. versionchanged:: 1.1

URLs may be either :class:`str` or :class:`~yarl.URL`

.. coroutinefunction:: head(url, **kwargs)

Perform a HEAD request.

:param url: Requested URL, :class:`str` or :class:`~yarl.URL`.

:param \*\*kwargs: Optional arguments that :func:`request` takes.

:return: :class:`ClientResponse` or derived from

.. deprecated:: 0.21

Use :meth:`ClientSession.head`.

.. versionchanged:: 1.1

URLs may be either :class:`str` or :class:`~yarl.URL`

.. coroutinefunction:: delete(url, **kwargs)

Perform a DELETE request.

:param url: Requested URL, :class:`str` or :class:`~yarl.URL`.

:param \*\*kwargs: Optional arguments that :func:`request` takes.

:return: :class:`ClientResponse` or derived from

.. deprecated:: 0.21

Use :meth:`ClientSession.delete`.

.. versionchanged:: 1.1

URLs may be either :class:`str` or :class:`~yarl.URL`

.. coroutinefunction:: post(url, *, data=None, **kwargs)

Perform a POST request.

:param url: Requested URL, :class:`str` or :class:`~yarl.URL`.

:param \*\*kwargs: Optional arguments that :func:`request` takes.

:return: :class:`ClientResponse` or derived from

.. deprecated:: 0.21

Use :meth:`ClientSession.post`.

.. versionchanged:: 1.1

URLs may be either :class:`str` or :class:`~yarl.URL`

.. coroutinefunction:: put(url, *, data=None, **kwargs)

Perform a PUT request.

:param url: Requested URL, :class:`str` or :class:`~yarl.URL`.

:param \*\*kwargs: Optional arguments that :func:`request` takes.

:return: :class:`ClientResponse` or derived from

.. deprecated:: 0.21

Use :meth:`ClientSession.put`.

.. versionchanged:: 1.1

URLs may be either :class:`str` or :class:`~yarl.URL`

.. coroutinefunction:: patch(url, *, data=None, **kwargs)

Perform a PATCH request.

:param url: Requested URL, :class:`str` or :class:`~yarl.URL`.

:param \*\*kwargs: Optional arguments that :func:`request` takes.

:return: :class:`ClientResponse` or derived from

.. deprecated:: 0.21

Use :meth:`ClientSession.patch`.

.. versionchanged:: 1.1

URLs may be either :class:`str` or :class:`~yarl.URL`

.. coroutinefunction:: ws_connect(url, *, protocols=(), \
timeout=10.0, connector=None, auth=None,\
autoclose=True, autoping=True, loop=None,\
origin=None, headers=None)

This function creates a websocket connection, checks the response and
returns a :class:`ClientWebSocketResponse` object. In case of failure
it may raise a :exc:`~aiohttp.errors.WSServerHandshakeError` exception.

:param url: Websocket server url, :class:`str` or :class:`~yarl.URL`

:param tuple protocols: Websocket protocols

:param float timeout: Timeout for websocket read. 10 seconds by default

:param obj connector: object :class:`TCPConnector`

:param bool autoclose: Automatically close websocket connection
on close message from server. If `autoclose` is
False them close procedure has to be handled manually

:param bool autoping: Automatically send `pong` on `ping` message from server

:param aiohttp.helpers.BasicAuth auth: BasicAuth named tuple that
represents HTTP Basic Authorization
(optional)

:param loop: :ref:`event loop<asyncio-event-loop>` used
for processing HTTP requests.

If param is ``None`` :func:`asyncio.get_event_loop`
used for getting default event loop, but we strongly
recommend to use explicit loops everywhere.

:param str origin: Origin header to send to server

:param headers: :class:`dict`, :class:`CIMultiDict` or
:class:`CIMultiDictProxy` for providing additional
headers for websocket handshake request.

.. versionadded:: 0.18

Add *auth* parameter.

.. versionadded:: 0.19

Add *origin* parameter.

.. versionadded:: 0.20

Add *headers* parameter.

.. deprecated:: 0.21

Use :meth:`ClientSession.ws_connect`.

.. versionchanged:: 1.1

URLs may be either :class:`str` or :class:`~yarl.URL`

.. _aiohttp-client-reference-connectors:

Connectors
Expand Down
45 changes: 5 additions & 40 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -1550,38 +1550,6 @@ def handler(request):
yield from resp.release()


@asyncio.coroutine
def test_module_shortcuts(test_client, loop):
@asyncio.coroutine
def handler(request):
return web.Response(text=request.method)

app = web.Application(loop=loop)
for meth in ('get', 'post', 'put', 'delete', 'head', 'patch', 'options'):
app.router.add_route(meth.upper(), '/', handler)
client = yield from test_client(lambda loop: app)

for meth in ('get', 'post', 'put', 'delete', 'head', 'patch', 'options'):
coro = getattr(aiohttp, meth)
with pytest.warns(DeprecationWarning):
resp = yield from coro(client.make_url('/'), loop=loop)

assert resp.status == 200
assert len(resp.history) == 0

content1 = yield from resp.read()
content2 = yield from resp.read()
assert content1 == content2
content = yield from resp.text()

if meth == 'head':
assert b'' == content1
else:
assert meth.upper() == content

yield from resp.release()


@asyncio.coroutine
def test_cookies(test_client, loop):
@asyncio.coroutine
Expand All @@ -1596,11 +1564,10 @@ def handler(request):

app = web.Application(loop=loop)
app.router.add_get('/', handler)
client = yield from test_client(lambda loop: app)
client = yield from test_client(
app, cookies={'test1': '123', 'test2': c})

resp = yield from aiohttp.get(client.make_url('/'),
cookies={'test1': '123', 'test2': c},
loop=loop)
resp = yield from client.get('/')
assert 200 == resp.status
resp.close()

Expand Down Expand Up @@ -1630,11 +1597,9 @@ def handler(request):

app = web.Application(loop=loop)
app.router.add_get('/', handler)
client = yield from test_client(lambda loop: app)
client = yield from test_client(app, cookies={'test2': c})

resp = yield from aiohttp.get(client.make_url('/'),
cookies={'test2': c},
loop=loop)
resp = yield from client.get('/')
assert 200 == resp.status
resp.close()

Expand Down
Loading

0 comments on commit 568f690

Please sign in to comment.