Skip to content

Commit

Permalink
Merge branch 'task/file-extension-accessor'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekokatt committed Aug 21, 2020
2 parents 9a691b3 + a072289 commit 5afdab5
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions hikari/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,10 @@ class AsyncReader(typing.AsyncIterable[bytes], abc.ABC):
detail is left to each implementation of this class to define.
"""

filename: str = attr.ib()
filename: str = attr.ib(repr=True)
"""The filename of the resource."""

mimetype: typing.Optional[str] = attr.ib()
mimetype: typing.Optional[str] = attr.ib(repr=True)
"""The mimetype of the resource. May be `builtins.None` if not known."""

async def data_uri(self) -> str:
Expand Down Expand Up @@ -418,6 +418,12 @@ def url(self) -> str:
def filename(self) -> str:
"""Filename of the resource."""

@property
def extension(self) -> typing.Optional[str]:
"""File extension, if there is one."""
_, _, ext = self.filename.rpartition(".")
return ext if ext != self.filename else None

@abc.abstractmethod
def stream(
self, *, executor: typing.Optional[concurrent.futures.Executor] = None, head_only: bool = False,
Expand All @@ -433,7 +439,10 @@ def stream(
head_only : builtins.bool
Defaults to `builtins.False`. If `builtins.True`, then the
implementation may only retrieve HEAD information if supported.
This currently only has any effect for web requests.
This currently only has any effect for web requests. This will
fetch the headers for the HTTP resource this object points to
without downloading the entire content, which can be significantly
faster if you are scanning file types in messages, for example.
Returns
-------
Expand Down Expand Up @@ -465,10 +474,10 @@ def __hash__(self) -> int:
class WebReader(AsyncReader):
"""Asynchronous reader to use to read data from a web resource."""

stream: aiohttp.StreamReader = attr.ib()
stream: aiohttp.StreamReader = attr.ib(repr=False)
"""The `aiohttp.StreamReader` to read the content from."""

url: str = attr.ib()
url: str = attr.ib(repr=False)
"""The URL being read from."""

status: int = attr.ib()
Expand Down

0 comments on commit 5afdab5

Please sign in to comment.