mirror of
https://github.com/httpie/cli.git
synced 2024-11-25 09:13:25 +01:00
Refine abstract methods and properties (#1118)
This commit is contained in:
parent
da47e37c44
commit
11399dde76
@ -1,32 +1,33 @@
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from typing import Iterable, Optional
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
from .utils import split_cookies
|
||||
|
||||
|
||||
class HTTPMessage:
|
||||
class HTTPMessage(metaclass=ABCMeta):
|
||||
"""Abstract class for HTTP messages."""
|
||||
|
||||
def __init__(self, orig):
|
||||
self._orig = orig
|
||||
|
||||
@abstractmethod
|
||||
def iter_body(self, chunk_size: int) -> Iterable[bytes]:
|
||||
"""Return an iterator over the body."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@abstractmethod
|
||||
def iter_lines(self, chunk_size: int) -> Iterable[bytes]:
|
||||
"""Return an iterator over the body yielding (`line`, `line_feed`)."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def headers(self) -> str:
|
||||
"""Return a `str` with the message's headers."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def encoding(self) -> Optional[str]:
|
||||
"""Return a `str` with the message's encoding, if known."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
def body(self) -> bytes:
|
||||
|
@ -1,3 +1,4 @@
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from itertools import chain
|
||||
from typing import Callable, Iterable, Union
|
||||
|
||||
@ -24,7 +25,7 @@ class BinarySuppressedError(DataSuppressedError):
|
||||
message = BINARY_SUPPRESSED_NOTICE
|
||||
|
||||
|
||||
class BaseStream:
|
||||
class BaseStream(metaclass=ABCMeta):
|
||||
"""Base HTTP message output stream class."""
|
||||
|
||||
def __init__(
|
||||
@ -50,9 +51,9 @@ class BaseStream:
|
||||
"""Return the headers' bytes."""
|
||||
return self.msg.headers.encode('utf8')
|
||||
|
||||
@abstractmethod
|
||||
def iter_body(self) -> Iterable[bytes]:
|
||||
"""Return an iterator over the message body."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def __iter__(self) -> Iterable[bytes]:
|
||||
"""Return an iterator over `self.msg`."""
|
||||
|
Loading…
Reference in New Issue
Block a user