Metadata-Version: 2.4
Name: cs-rfc2616
Version: 20260531
Summary: Some convenience routines for working with HTTP 1.1 (RFC2616). See https://datatracker.ietf.org/doc/html/rfc2616
Keywords: python3
Author-email: Cameron Simpson <cs@cskk.id.au>
Description-Content-Type: text/markdown
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
Requires-Dist: cs.fileutils>=20260531
Requires-Dist: cs.lex>=20260526
Requires-Dist: cs.timeutils
Project-URL: MonoRepo Commits, https://bitbucket.org/cameron_simpson/css/commits/branch/main
Project-URL: Monorepo Git Mirror, https://github.com/cameron-simpson/css
Project-URL: Monorepo Hg/Mercurial Mirror, https://hg.sr.ht/~cameron-simpson/css
Project-URL: Source, https://github.com/cameron-simpson/css/blob/main/lib/python/cs/rfc2616.py

Some convenience routines for working with HTTP 1.1 (RFC2616).
See https://datatracker.ietf.org/doc/html/rfc2616

*Latest release 20260531*:
* header(): new default=None optional parameter.
* content_length,content_type: plumb keyword arguments through to header().
* New content_encodings(headers) returning a list of the content encodings from headers.

Short summary:
* `content_encodings`: A list of the encodings named in the `Content-Encoding` header.
* `content_length`: Return the value of the `Content-Length` header, or `None`.
* `content_type`: Return the parsed value of the `Content-Type` header, or `None`.
* `datetime_from_asctime_date`: Parse an asctime-date from a string, return a datetime object. See RFC2616 section 3.3.1. Format: wkday, mon d hh:mm:ss yyyy.
* `datetime_from_http_date`: Parse an HTTP-date from a string, return a datetime object. See RFC2616 section 3.3.1.
* `datetime_from_rfc1123_date`: Parse an rfc1123-date from a string, return a datetime object. See RFC2616 section 3.3.1. Format: wkday, dd mon yyyy hh:mm:ss GMT.
* `datetime_from_rfc850_date`: Parse an rfc850-date from a string, return a datetime object. See RFC2616 section 3.3.1. Format: weekday, dd-mon-yy hh:mm:ss GMT.
* `default_headerregistry`: Return the default `email.headerregistry.HeaderRegistry` instance. Note that this is shared and should probably not be modified.
* `get_lws`: Gather up an LWS.
* `get_quoted_string`: Match a quoted-string in `s` starting at `offset`.
* `get_space`: Gather up a sequence of SP or HT, possibly empty.
* `get_text`: Gather up a sequence of TEXT characters (possibly empty).
* `get_token`: Get an RFC2616 token from the string `s` starting at `offset`. Return token, new_offset. See RFC2616 part 2.2.
* `header`: Return a header parsed into an instance of `email.headerregistry.BaseHeader` or `default` if `header_name` is not present.
* `message_has_body`: Does this message have a message body to forward? See RFC2616, part 4.3 and 4.4. Note that HTTP certain requests preempty this; for example HEAD never has a body. That aspect is not considered here.
* `parse_chunk_line1`: Parse the opening line of a chunked-encoding chunk.
* `pass_chunked`: Copy "chunked" data from `fpin` to `fpout`, and an optional trailer section (default False). See RFC2616, part 3.6.1.
* `pass_length`: Copy a specific amount of data from `fpin` to `fpout`.
* `read_chunked`: Generator that reads "chunked" data from `fpin`, and an optional trailer section (default False). See RFC2616, part 3.6.1.
* `read_headers`: Read headers from a binary file such as an HTTP stream, return the raw binary data and the corresponding Message object.
* `read_http_request_line`: Read HTTP Request-Line from the binary file `fp`, return method, uri, version. See RFC2616 section 5.1. If an empty request line is received return None, None, None.

Module contents:
- <a name="content_encodings"></a>`content_encodings(headers: Mapping[str, str], **header_kw) -> List[str]`: A list of the encodings named in the `Content-Encoding` header.
- <a name="content_length"></a>`content_length(headers: Mapping[str, str], **header_kw) -> Optional[int]`: Return the value of the `Content-Length` header, or `None`.

  Note that `headers` is expected to be a case insensitive mapping.
- <a name="content_type"></a>`content_type(headers: Mapping[str, str], **header_kw) -> email.headerregistry.ContentTypeHeader`: Return the parsed value of the `Content-Type` header, or `None`.

  Note that `headers` is expected to be a case insensitive mapping.
- <a name="datetime_from_asctime_date"></a>`datetime_from_asctime_date(s)`: Parse an asctime-date from a string, return a datetime object.
  See RFC2616 section 3.3.1.
  Format: wkday, mon d hh:mm:ss yyyy
- <a name="datetime_from_http_date"></a>`datetime_from_http_date(s)`: Parse an HTTP-date from a string, return a datetime object.
  See RFC2616 section 3.3.1.
- <a name="datetime_from_rfc1123_date"></a>`datetime_from_rfc1123_date(s)`: Parse an rfc1123-date from a string, return a datetime object.
  See RFC2616 section 3.3.1.
  Format: wkday, dd mon yyyy hh:mm:ss GMT
- <a name="datetime_from_rfc850_date"></a>`datetime_from_rfc850_date(s)`: Parse an rfc850-date from a string, return a datetime object.
  See RFC2616 section 3.3.1.
  Format: weekday, dd-mon-yy hh:mm:ss GMT
- <a name="enc8"></a>`enc8(s)`: encode and decode bytes<->str for HTTP stream: 8-bit 1-to-1
- <a name="get_lws"></a>`get_lws(s, offset=0)`: Gather up an LWS.
- <a name="get_quoted_string"></a>`get_quoted_string(s, offset=0)`: Match a quoted-string in `s` starting at `offset`.
- <a name="get_space"></a>`get_space(s, offset=0)`: Gather up a sequence of SP or HT, possibly empty.
- <a name="get_text"></a>`get_text(s, offset=0)`: Gather up a sequence of TEXT characters (possibly empty).
- <a name="get_token"></a>`get_token(s, offset=0)`: Get an RFC2616 token from the string `s` starting at `offset`.
  Return token, new_offset.
  See RFC2616 part 2.2.
- <a name="header"></a>`header(headers: Mapping[str, str], header_name: str, registry: Optional[email.headerregistry.HeaderRegistry] = None, *, default=None) -> Optional[email.headerregistry.BaseHeader]`: Return a header parsed into an instance of `email.headerregistry.BaseHeader`
  or `default` if `header_name` is not present.
- <a name="message_has_body"></a>`message_has_body(headers)`: Does this message have a message body to forward?
  See RFC2616, part 4.3 and 4.4.
  Note that HTTP certain requests preempty this; for example HEAD never has a body.
  That aspect is not considered here.
- <a name="parse_chunk_line1"></a>`parse_chunk_line1(bline)`: Parse the opening line of a chunked-encoding chunk.
- <a name="pass_chunked"></a>`pass_chunked(fpin, fpout, has_trailer)`: Copy "chunked" data from `fpin` to `fpout`, and an optional trailer section (default False).
  See RFC2616, part 3.6.1.
- <a name="pass_length"></a>`pass_length(fpin, fpout, length)`: Copy a specific amount of data from `fpin` to `fpout`.
- <a name="read_chunked"></a>`read_chunked(fpin, has_trailer=False)`: Generator that reads "chunked" data from `fpin`, and an optional trailer section (default False).
  See RFC2616, part 3.6.1.
- <a name="read_headers"></a>`read_headers(fp)`: Read headers from a binary file such as an HTTP stream, return the raw binary data and the corresponding Message object.
- <a name="read_http_request_line"></a>`read_http_request_line(fp)`: Read HTTP Request-Line from the binary file `fp`, return method, uri, version.
  See RFC2616 section 5.1.
  If an empty request line is received return None, None, None.

# Release Log



*Release 20260531*:
* header(): new default=None optional parameter.
* content_length,content_type: plumb keyword arguments through to header().
* New content_encodings(headers) returning a list of the content encodings from headers.

*Release 20250306*:
New default_headerregistry(), header(headers,name), content_length(headers) and content_type(headers).

*Release 20160828*:
Use "install_requires" instead of "requires" in DISTINFO.

*Release 20160827*:
Initial PyPI release.
