Skip to content

Commit

Permalink
Improve type annotations, remove rarely used direct methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-feld committed Aug 8, 2021
1 parent 8cf0bc7 commit dd6b6ae
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 15 deletions.
4 changes: 0 additions & 4 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,3 @@ Supported methods:
* post
* put
* delete
* connect
* options
* trace
* patch
68 changes: 58 additions & 10 deletions src/pywreck/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

import asyncio
import functools
import os.path
import ssl
from dataclasses import dataclass
Expand Down Expand Up @@ -202,12 +201,61 @@ async def request(
writer.transport.abort()


get = functools.partial(request, "GET")
head = functools.partial(request, "HEAD")
post = functools.partial(request, "POST")
put = functools.partial(request, "PUT")
delete = functools.partial(request, "DELETE")
connect = functools.partial(request, "CONNECT")
options = functools.partial(request, "OPTIONS")
trace = functools.partial(request, "TRACE")
patch = functools.partial(request, "PATCH")
async def get(
host: str,
uri: str,
payload: bytes = b"",
headers: Optional[Dict[str, str]] = None,
port: int = 443,
timeout: Optional[float] = 5.0,
ssl: Union[bool, ssl.SSLContext] = True,
) -> Response:
return await request("GET", host, uri, payload, headers, port, timeout, ssl)


async def head(
host: str,
uri: str,
payload: bytes = b"",
headers: Optional[Dict[str, str]] = None,
port: int = 443,
timeout: Optional[float] = 5.0,
ssl: Union[bool, ssl.SSLContext] = True,
) -> Response:
return await request("HEAD", host, uri, payload, headers, port, timeout, ssl)


async def post(
host: str,
uri: str,
payload: bytes = b"",
headers: Optional[Dict[str, str]] = None,
port: int = 443,
timeout: Optional[float] = 5.0,
ssl: Union[bool, ssl.SSLContext] = True,
) -> Response:
return await request("POST", host, uri, payload, headers, port, timeout, ssl)


async def put(
host: str,
uri: str,
payload: bytes = b"",
headers: Optional[Dict[str, str]] = None,
port: int = 443,
timeout: Optional[float] = 5.0,
ssl: Union[bool, ssl.SSLContext] = True,
) -> Response:
return await request("PUT", host, uri, payload, headers, port, timeout, ssl)


async def delete(
host: str,
uri: str,
payload: bytes = b"",
headers: Optional[Dict[str, str]] = None,
port: int = 443,
timeout: Optional[float] = 5.0,
ssl: Union[bool, ssl.SSLContext] = True,
) -> Response:
return await request("DELETE", host, uri, payload, headers, port, timeout, ssl)
2 changes: 1 addition & 1 deletion tests/test_pywreck.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def port(handler):

@pytest.mark.parametrize(
"method",
("get", "head", "post", "put", "delete", "connect", "options", "trace", "patch"),
("get", "head", "post", "put", "delete"),
)
@pytest.mark.parametrize("handler", (handle_echo,), indirect=True)
def test_basic(loop, port, method):
Expand Down

0 comments on commit dd6b6ae

Please sign in to comment.