From 5a07892bfc58472c1b651f66deaf03176bfe79df Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 16 Oct 2016 20:56:46 -0700 Subject: py2--: inline type info --- netlib/http/message.py | 16 ++++++---------- netlib/http/request.py | 6 ++---- netlib/http/response.py | 19 +++++++++---------- netlib/http/url.py | 11 +++++------ 4 files changed, 22 insertions(+), 30 deletions(-) (limited to 'netlib/http') diff --git a/netlib/http/message.py b/netlib/http/message.py index 13f908ca..e44faf18 100644 --- a/netlib/http/message.py +++ b/netlib/http/message.py @@ -2,6 +2,7 @@ from __future__ import absolute_import, print_function, division import re import warnings +from typing import Optional from netlib import encoding, strutils, basetypes from netlib.http import headers @@ -77,8 +78,7 @@ class Message(basetypes.Serializable): self.data.headers = h @property - def raw_content(self): - # type: () -> bytes + def raw_content(self) -> bytes: """ The raw (encoded) HTTP message body @@ -90,8 +90,7 @@ class Message(basetypes.Serializable): def raw_content(self, content): self.data.content = content - def get_content(self, strict=True): - # type: (bool) -> bytes + def get_content(self, strict: bool=True) -> bytes: """ The HTTP message body decoded with the content-encoding header (e.g. gzip) @@ -168,14 +167,12 @@ class Message(basetypes.Serializable): def timestamp_end(self, timestamp_end): self.data.timestamp_end = timestamp_end - def _get_content_type_charset(self): - # type: () -> Optional[str] + def _get_content_type_charset(self) -> Optional[str]: ct = headers.parse_content_type(self.headers.get("content-type", "")) if ct: return ct[2].get("charset") - def _guess_encoding(self): - # type: () -> str + def _guess_encoding(self) -> str: enc = self._get_content_type_charset() if enc: return enc @@ -186,8 +183,7 @@ class Message(basetypes.Serializable): # We may also want to check for HTML meta tags here at some point. return "latin-1" - def get_text(self, strict=True): - # type: (bool) -> str + def get_text(self, strict: bool=True) -> str: """ The HTTP message body decoded with both content-encoding header (e.g. gzip) and content-type header charset. diff --git a/netlib/http/request.py b/netlib/http/request.py index cccda13e..7a83894b 100644 --- a/netlib/http/request.py +++ b/netlib/http/request.py @@ -248,8 +248,7 @@ class Request(message.Message): return netlib.http.url.unparse(self.scheme, self.pretty_host, self.port, self.path) @property - def query(self): - # type: () -> multidict.MultiDictView + def query(self) -> multidict.MultiDictView: """ The request query string as an :py:class:`~netlib.multidict.MultiDictView` object. """ @@ -272,8 +271,7 @@ class Request(message.Message): self._set_query(value) @property - def cookies(self): - # type: () -> multidict.MultiDictView + def cookies(self) -> multidict.MultiDictView: """ The request cookies. diff --git a/netlib/http/response.py b/netlib/http/response.py index 30bec2df..02a93fa7 100644 --- a/netlib/http/response.py +++ b/netlib/http/response.py @@ -8,11 +8,11 @@ from netlib.http import cookies from netlib.http import headers as nheaders from netlib.http import message from netlib.http import status_codes -from typing import AnyStr # noqa -from typing import Dict # noqa -from typing import Iterable # noqa -from typing import Tuple # noqa -from typing import Union # noqa +from typing import AnyStr +from typing import Dict +from typing import Iterable +from typing import Tuple +from typing import Union class ResponseData(message.MessageData): @@ -69,9 +69,9 @@ class Response(message.Message): @classmethod def make( cls, - status_code=200, # type: int - content=b"", # type: AnyStr - headers=() # type: Union[Dict[AnyStr, AnyStr], Iterable[Tuple[bytes, bytes]]] + status_code: int=200, + content: AnyStr=b"", + headers: Union[Dict[AnyStr, AnyStr], Iterable[Tuple[bytes, bytes]]]=() ): """ Simplified API for creating response objects. @@ -130,8 +130,7 @@ class Response(message.Message): self.data.reason = message._always_bytes(reason) @property - def cookies(self): - # type: () -> multidict.MultiDictView + def cookies(self) -> multidict.MultiDictView: """ The response cookies. A possibly empty :py:class:`~netlib.multidict.MultiDictView`, where the keys are cookie diff --git a/netlib/http/url.py b/netlib/http/url.py index 2878734a..67e22efa 100644 --- a/netlib/http/url.py +++ b/netlib/http/url.py @@ -1,4 +1,6 @@ import urllib +from typing import Sequence +from typing import Tuple from netlib import utils @@ -80,8 +82,7 @@ def unparse(scheme, host, port, path=""): return "%s://%s%s" % (scheme, hostport(scheme, host, port), path) -def encode(s): - # type: Sequence[Tuple[str,str]] -> str +def encode(s: Sequence[Tuple[str, str]]) -> str: """ Takes a list of (key, value) tuples and returns a urlencoded string. """ @@ -95,23 +96,21 @@ def decode(s): return urllib.parse.parse_qsl(s, keep_blank_values=True, errors='surrogateescape') -def quote(b, safe="/"): +def quote(b: str, safe: str="/") -> str: """ Returns: An ascii-encodable str. """ - # type: (str) -> str return urllib.parse.quote(b, safe=safe, errors="surrogateescape") -def unquote(s): +def unquote(s: str) -> str: """ Args: s: A surrogate-escaped str Returns: A surrogate-escaped str """ - # type: (str) -> str return urllib.parse.unquote(s, errors="surrogateescape") -- cgit v1.2.3