Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions httpie/models.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
5 changes: 3 additions & 2 deletions httpie/output/streams.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from abc import ABCMeta, abstractmethod
from itertools import chain
from typing import Callable, Iterable, Union

Expand All @@ -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__(
Expand All @@ -50,9 +51,9 @@ def get_headers(self) -> bytes:
"""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`."""
Expand Down