Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Kim committed Feb 16, 2017
1 parent 44cde0b commit e49b59b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
12 changes: 8 additions & 4 deletions aiohttp/_parser.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ cdef class HttpParser:
self._header_value += val
self._raw_header_value += raw_val

cdef _on_headers_complete(self):
cdef _on_headers_complete(self,
ENCODING='utf-8',
ENCODING_ERR='surrogateescape',
CONTENT_ENCODING=hdrs.CONTENT_ENCODING,
SUPPORTED=('gzip', 'deflate')):
self._process_header()

method = cparser.http_method_str(<cparser.http_method> self._cparser.method)
Expand All @@ -149,14 +153,14 @@ cdef class HttpParser:
self._upgraded = True

encoding = None
enc = headers.get(hdrs.CONTENT_ENCODING)
enc = headers.get(CONTENT_ENCODING)
if enc:
enc = enc.lower()
if enc in ('gzip', 'deflate'):
if enc in SUPPORTED:
encoding = enc

msg = RawRequestMessage(
method.decode('utf-8', 'surrogateescape'), self._path,
method.decode(ENCODING, ENCODING_ERR), self._path,
self.http_version(), headers, raw_headers,
should_close, encoding, upgrade, chunked, self._url)

Expand Down
5 changes: 2 additions & 3 deletions aiohttp/_ws_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import collections
import hashlib
import json
import os
import random
import sys
from enum import IntEnum
from struct import Struct

from aiohttp import errors, hdrs
from aiohttp import errors, hdrs, helpers
from aiohttp.log import ws_logger

__all__ = ('WebSocketReader', 'WebSocketWriter', 'do_handshake',
Expand Down Expand Up @@ -129,7 +128,7 @@ def _websocket_mask_python(mask, data):
return (data ^ mask).to_bytes(datalen, native_byteorder)


if bool(os.environ.get('AIOHTTP_NO_EXTENSIONS')):
if helpers.NO_EXTENSIONS:
_websocket_mask = _websocket_mask_python
else:
try:
Expand Down
1 change: 1 addition & 0 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

sentinel = object()
Timeout = timeout
NO_EXTENSIONS = bool(os.environ.get('AIOHTTP_NO_EXTENSIONS'))


class BasicAuth(namedtuple('BasicAuth', ['login', 'password', 'encoding'])):
Expand Down
7 changes: 4 additions & 3 deletions aiohttp/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,17 +706,18 @@ def write_eof(self, chunk=b''):

self.buffer_data(chunk)

yield from self.drain()
yield from self.drain(True)

self._transport = None
self._stream.release()

@asyncio.coroutine
def drain(self):
def drain(self, last=False):
if self._transport is not None:
if self._buffer:
self._transport.write(b''.join(self._buffer))
self._buffer.clear()
if not last:
self._buffer.clear()
yield from self._stream.drain()
else:
if self._buffer:
Expand Down
5 changes: 2 additions & 3 deletions aiohttp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import asyncio
import asyncio.streams
import http.server
import os
import socket
import traceback
import warnings
Expand Down Expand Up @@ -42,7 +41,7 @@ def tcp_keepalive(server, transport): # pragma: no cover
pass


if bool(os.environ.get('AIOHTTP_NO_EXTENSIONS')):
if helpers.NO_EXTENSIONS:
from .protocol import HttpRequestParser
else:
try:
Expand Down Expand Up @@ -238,7 +237,7 @@ def connection_lost(self, exc):
if not handler.done():
handler.cancel()

self._request_handlers.clear()
self._request_handlers = ()

if self._time_service_owner:
self._time_service.close()
Expand Down

0 comments on commit e49b59b

Please sign in to comment.