Skip to content

Clarify that the Headers class is a Sequence #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2021
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
7 changes: 2 additions & 5 deletions h11/_headers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from collections.abc import Sequence

from ._abnf import field_name, field_value
from ._util import bytesify, LocalProtocolError, validate
Expand Down Expand Up @@ -62,7 +63,7 @@
_field_value_re = re.compile(field_value.encode("ascii"))


class Headers:
class Headers(Sequence):
"""
A list-like interface that allows iterating over headers as byte-pairs
of (lowercased-name, value).
Expand Down Expand Up @@ -92,10 +93,6 @@ class Headers:
def __init__(self, full_items):
self._full_items = full_items

def __iter__(self):
for _, name, value in self._full_items:
yield name, value

def __bool__(self):
return bool(self._full_items)

Expand Down
3 changes: 3 additions & 0 deletions newsfragments/112.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Clarify that the Headers class is a Sequence and inherit from the
collections Sequence abstract base class to also indicate this (and
gain the mixin methods). See also #104.