Skip to content

Commit

Permalink
cleanup deprecation warnings and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Feb 19, 2017
1 parent a678178 commit e1c682c
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 110 deletions.
19 changes: 11 additions & 8 deletions aiohttp/client_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,22 @@ def set_response_params(self, *, timer=None,
self, self._loop, timer=timer)

def data_received(self, data):
if not data:
return

# custom payload parser
if self._payload_parser is not None:
if data:
eof, tail = self._payload_parser.feed_data(data)
if eof:
self._payload = None
self._payload_parser = None

if tail:
super().data_received(tail)
eof, tail = self._payload_parser.feed_data(data)
if eof:
self._payload = None
self._payload_parser = None

if tail:
super().data_received(tail)
return
else:
if self._upgraded:
# i.e. websocket connection, websocket parser is not set yet
self._tail += data
else:
# parse http messages
Expand Down
83 changes: 38 additions & 45 deletions aiohttp/web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .helpers import HeadersMixin, SimpleCookie, reify, sentinel
from .web_exceptions import HTTPRequestEntityTooLarge

__all__ = ('BaseRequest', 'Request')
__all__ = ('BaseRequest', 'FileField', 'Request')

FileField = collections.namedtuple('Field', 'name filename file content_type')

Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__(self, message, payload, protocol, time_service, task, *,
self._task = task
self._client_max_size = client_max_size

self.rel_url = message.url
self._rel_url = message.url

def clone(self, *, method=sentinel, rel_url=sentinel,
headers=sentinel):
Expand Down Expand Up @@ -111,6 +111,10 @@ def transport(self):
def message(self):
return self._message

@property
def rel_url(self):
return self._rel_url

# MutableMapping API

def __getitem__(self, key):
Expand All @@ -130,15 +134,12 @@ def __iter__(self):

########

@reify
@property
def scheme(self):
"""A string representing the scheme of the request.
'http' or 'https'.
"""
warnings.warn("scheme is deprecated, "
"use .url.scheme instead",
DeprecationWarning)
return self.url.scheme

@reify
Expand Down Expand Up @@ -179,22 +180,27 @@ def host(self):
DeprecationWarning)
return self._message.headers.get(hdrs.HOST)

@reify
def url(self):
return URL('{}://{}{}'.format(self._scheme,
self._message.headers.get(hdrs.HOST),
str(self._rel_url)))

@property
def path(self):
"""The URL including *PATH INFO* without the host or scheme.
E.g., ``/app/blog``
"""
return self._rel_url.path

@reify
def path_qs(self):
"""The URL including PATH_INFO and the query string.
E.g, /app/blog?id=10
"""
warnings.warn("path_qs property is deprecated, "
"use str(request.rel_url) instead",
DeprecationWarning)
return str(self.rel_url)

@reify
def url(self):
return URL('{}://{}{}'.format(self._scheme,
self._message.headers.get(hdrs.HOST),
str(self.rel_url)))
return str(self._rel_url)

@property
def raw_path(self):
Expand All @@ -205,36 +211,28 @@ def raw_path(self):
"""
return self._message.path

@reify
def path(self):
"""The URL including *PATH INFO* without the host or scheme.
E.g., ``/app/blog``
"""
warnings.warn("path property is deprecated, use .rel_url.path instead",
DeprecationWarning)
return self.rel_url.path
@property
def query(self):
"""A multidict with all the variables in the query string."""
return self._rel_url.query

@reify
@property
def query_string(self):
"""The query string in the URL.
E.g., id=10
"""
warnings.warn("query_string property is deprecated, "
"use .rel_url.query_string instead",
DeprecationWarning)
return self.rel_url.query_string
return self._rel_url.query_string

@reify
@property
def GET(self):
"""A multidict with all the variables in the query string.
Lazy property.
"""
warnings.warn("GET property is deprecated, use .rel_url.query instead",
warnings.warn("GET property is deprecated, use .query instead",
DeprecationWarning)
return self.rel_url.query
return self._rel_url.query

@reify
def POST(self):
Expand Down Expand Up @@ -300,7 +298,7 @@ def http_range(self, *, _RANGE=hdrs.RANGE):
Return a slice instance.
"""
rng = self.headers.get(_RANGE)
rng = self._headers.get(_RANGE)
start, end = None, None
if rng is not None:
try:
Expand Down Expand Up @@ -373,27 +371,22 @@ def text(self):
return bytes_body.decode(encoding)

@asyncio.coroutine
def json(self, *, loads=json.loads, loader=None):
def json(self, *, loads=json.loads):
"""Return BODY as JSON."""
if loader is not None:
warnings.warn(
"Using loader argument is deprecated, use loads instead",
DeprecationWarning)
loads = loader
body = yield from self.text()
return loads(body)

@asyncio.coroutine
def multipart(self, *, reader=multipart.MultipartReader):
"""Return async iterator to process BODY as multipart."""
return reader(self.headers, self.content)
return reader(self._headers, self._payload)

@asyncio.coroutine
def post(self):
"""Return POST parameters."""
if self._post is not None:
return self._post
if self.method not in self.POST_METHODS:
if self._method not in self.POST_METHODS:
self._post = MultiDictProxy(MultiDict())
return self._post

Expand All @@ -411,10 +404,10 @@ def post(self):
body = yield from self.read()
content_charset = self.charset or 'utf-8'

environ = {'REQUEST_METHOD': self.method,
environ = {'REQUEST_METHOD': self._method,
'CONTENT_LENGTH': str(len(body)),
'QUERY_STRING': '',
'CONTENT_TYPE': self.headers.get(hdrs.CONTENT_TYPE)}
'CONTENT_TYPE': self._headers.get(hdrs.CONTENT_TYPE)}

fs = cgi.FieldStorage(fp=io.BytesIO(body),
environ=environ,
Expand Down Expand Up @@ -457,7 +450,7 @@ def __repr__(self):
ascii_encodable_path = self.path.encode('ascii', 'backslashreplace') \
.decode('ascii')
return "<{} {} {} >".format(self.__class__.__name__,
self.method, ascii_encodable_path)
self._method, ascii_encodable_path)

@asyncio.coroutine
def _prepare_hook(self, response):
Expand Down
12 changes: 5 additions & 7 deletions docs/web.rst
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ HTTP Forms
HTTP Forms are supported out of the box.

If form's method is ``"GET"`` (``<form method="get">``) use
:attr:`Request.rel_url.query` for getting form data.
:attr:`Request.query` for getting form data.

For accessing to form data with ``"POST"`` method use
:meth:`Request.post` or :meth:`Request.multipart`.
Expand Down Expand Up @@ -665,11 +665,10 @@ with the peer::

.. _aiohttp-web-websocket-read-same-task:

Reading from the *WebSocket* (``await ws.receive()``) and closing it
(``await ws.close()``) **must only** be done inside the request
handler *task*; however, writing (``ws.send_str(...)``) to the
*WebSocket* and canceling the handler task may be delegated to other
tasks. See also :ref:`FAQ section
Reading from the *WebSocket* (``await ws.receive()``) **must only** be done
inside the request handler *task*; however, writing (``ws.send_str(...)``) to the
*WebSocket*, closing (``await ws.close()``) and canceling the handler
task may be delegated to other tasks. See also :ref:`FAQ section
<aiohttp_faq_terminating_websockets>`.

*aiohttp.web* creates an implicit :class:`asyncio.Task` for handling every
Expand All @@ -689,7 +688,6 @@ incoming request.

Parallel reads from websocket are forbidden, there is no
possibility to call :meth:`aiohttp.web.WebSocketResponse.receive`
or :meth:`aiohttp.web.WebSocketResponse.close`
from two tasks.

See :ref:`FAQ section <aiohttp_faq_parallel_event_sources>` for
Expand Down
48 changes: 6 additions & 42 deletions docs/web_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,13 @@ and :ref:`aiohttp-web-signals` handlers.

Returns :class:`str` or ``None`` if HTTP request has no *HOST* header.

.. deprecated:: 1.1

Use :attr:`url` (``request.url.host``) instead.

.. attribute:: path_qs

The URL including PATH_INFO and the query string. e.g.,
``/app/blog?id=10``

Read-only :class:`str` property.

.. deprecated:: 1.1

Use :attr:`url` (``str(request.rel_url)``) instead.

.. attribute:: path

The URL including *PATH INFO* without the host or scheme. e.g.,
Expand All @@ -108,10 +100,6 @@ and :ref:`aiohttp-web-signals` handlers.

Read-only :class:`str` property.

.. deprecated:: 1.1

Use :attr:`url` (``request.rel_url.path``) instead.

.. attribute:: raw_path

The URL including raw *PATH INFO* without the host or scheme.
Expand All @@ -123,20 +111,18 @@ and :ref:`aiohttp-web-signals` handlers.

Read-only :class:`str` property.

.. deprecated:: 1.1
.. attribute:: query

Use :attr:`url` (``request.rel_url.raw_path``) instead.
A multidict with all the variables in the query string.

Read-only :class:`~multidict.MultiDictProxy` lazy property.

.. attribute:: query_string

The query string in the URL, e.g., ``id=10``

Read-only :class:`str` property.

.. deprecated:: 1.1

Use :attr:`url` (``request.rel_url.query_string``) instead.

.. attribute:: GET

A multidict with all the variables in the query string.
Expand Down Expand Up @@ -493,12 +479,6 @@ StreamResponse

.. versionadded:: 0.18

.. attribute:: started

Deprecated alias for :attr:`prepared`.

.. deprecated:: 0.18

.. attribute:: task

A task that serves HTTP request handling.
Expand Down Expand Up @@ -716,22 +696,6 @@ StreamResponse

Clear :attr:`tcp_cork` if *value* is ``True``.

.. method:: start(request)

:param aiohttp.web.Request request: HTTP request object, that the
response answers.

Send *HTTP header*. You should not change any header data after
calling this method.

.. deprecated:: 0.18

Use :meth:`prepare` instead.

.. warning:: The method doesn't call
:attr:`~aiohttp.web.Application.on_response_prepare` signal, use
:meth:`prepare` instead.

.. coroutinemethod:: prepare(request)

:param aiohttp.web.Request request: HTTP request object, that the
Expand Down Expand Up @@ -1097,7 +1061,7 @@ WebSocketResponse
with parsed JSON (:func:`json.loads` by
default).

:param timeout: timeout for `receive` operation.
:param timeout: timeout for `receive` operation.
timeout value overrides response`s receive_timeout attribute.

:return dict: loaded JSON content
Expand Down Expand Up @@ -2176,7 +2140,7 @@ Constants

*GZIP compression*

.. attribute:: identity
.. attribute:: identity

*no compression*

Expand Down
Loading

0 comments on commit e1c682c

Please sign in to comment.