Skip to content

Commit

Permalink
Update http.py
Browse files Browse the repository at this point in the history
  • Loading branch information
chillymosh committed Feb 12, 2024
1 parent 36b643f commit 5b5e7f9
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions twitchio/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ def encode(cls, value: str, /, safe: str = "", plus: bool = False) -> str:
method = urllib.parse.quote_plus if plus else urllib.parse.quote
unquote = urllib.parse.unquote_plus if plus else urllib.parse.unquote

if unquote(value) == value:
return method(value, safe=safe)

return value
return method(value, safe=safe) if unquote(value) == value else value

@property
def url(self) -> str:
Expand Down Expand Up @@ -184,9 +181,9 @@ async def _call_next(self) -> None:

try:
inner: list[RawResponse] = data["data"]
except KeyError:
except KeyError as e:
# TODO: Proper exception...
raise ValueError('Expected "data" key not found.')
raise ValueError('Expected "data" key not found.') from e

for value in inner:
if self._max_results is None:
Expand Down Expand Up @@ -220,8 +217,8 @@ async def __anext__(self) -> T:

try:
data = self._buffer.popleft()
except IndexError:
raise StopAsyncIteration
except IndexError as e:
raise StopAsyncIteration from e

return data

Expand Down

0 comments on commit 5b5e7f9

Please sign in to comment.