Skip to content

Commit

Permalink
Add annotations to web_response.py
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Oct 17, 2018
1 parent 59183f0 commit 22a58e2
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 125 deletions.
18 changes: 18 additions & 0 deletions aiohttp/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import (TYPE_CHECKING, Any, Awaitable, Dict, Iterable, List,
Mapping, Optional, Tuple, Union)

from multidict import CIMultiDict # noqa
from yarl import URL


Expand Down Expand Up @@ -148,6 +149,10 @@ def filter_cookies(self, request_url: URL) -> 'BaseCookie[str]':
class AbstractStreamWriter(ABC):
"""Abstract stream writer."""

buffer_size = 0
output_size = 0
length = 0 # type: Optional[int]

@abstractmethod
async def write(self, chunk: bytes) -> None:
"""Write chunk into stream."""
Expand All @@ -160,6 +165,19 @@ async def write_eof(self, chunk: bytes=b'') -> None:
async def drain(self) -> None:
"""Flush the write buffer."""

@abstractmethod
def enable_compression(self, encoding: str='deflate') -> None:
"""Enable HTTP body compression"""

@abstractmethod
def enable_chunking(self) -> None:
"""Enable HTTP chunked mode"""

@abstractmethod
async def write_headers(self, status_line: str,
headers: 'CIMultiDict[str]') -> None:
"""Write HTTP headers"""


class AbstractAccessLogger(ABC):
"""Abstract writer to access log."""
Expand Down
4 changes: 2 additions & 2 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,8 @@ class HeadersMixin:
ATTRS = frozenset([
'_content_type', '_content_dict', '_stored_content_type'])

_content_type = None
_content_dict = None
_content_type = None # type: Optional[str]
_content_dict = None # type: Optional[Dict[str, str]]
_stored_content_type = sentinel

def _parse_content_type(self, raw: str) -> None:
Expand Down
5 changes: 3 additions & 2 deletions aiohttp/http.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import http.server
import sys
from typing import Mapping, Tuple # noqa

from . import __version__
from .http_exceptions import HttpProcessingError
Expand Down Expand Up @@ -31,6 +32,6 @@


SERVER_SOFTWARE = 'Python/{0[0]}.{0[1]} aiohttp/{1}'.format(
sys.version_info, __version__)
sys.version_info, __version__) # type: str

RESPONSES = http.server.BaseHTTPRequestHandler.responses
RESPONSES = http.server.BaseHTTPRequestHandler.responses # type: Mapping[int, Tuple[str, str]] # noqa
4 changes: 2 additions & 2 deletions aiohttp/http_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ async def write(self, chunk: bytes,

if chunk:
if self.chunked:
chunk_len = ('%x\r\n' % len(chunk)).encode('ascii')
chunk = chunk_len + chunk + b'\r\n'
chunk_len_pre = ('%x\r\n' % len(chunk)).encode('ascii')
chunk = chunk_len_pre + chunk + b'\r\n'

self._write(chunk)

Expand Down
4 changes: 2 additions & 2 deletions aiohttp/web_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ def _format_r(request: BaseRequest,
@staticmethod
def _format_s(request: BaseRequest,
response: StreamResponse,
time: float) -> str:
time: float) -> int:
return response.status

@staticmethod
def _format_b(request: BaseRequest,
response: StreamResponse,
time: float) -> str:
time: float) -> int:
return response.body_length

@staticmethod
Expand Down
Loading

0 comments on commit 22a58e2

Please sign in to comment.