Skip to main content

Parse formats defined in IETF RFCs

Project description

Version ReadTheDocs Build Coverage CodeClimate

Wait… Why? What??

This is a gut reaction to the wealth of ways to parse URLs, MIME headers, HTTP messages and other things described by IETF RFCs. They range from the Python standard library (urllib) to be buried in the guts of other kitchen sink libraries (werkzeug) and most of them are broken in one way or the other.

So why create another one? Good question… glad that you asked. This is a companion library to the great packages out there that are responsible for communicating with other systems. I’m going to concentrate on providing a crisp and usable set of APIs that concentrate on parsing text. Nothing more. Hopefully by concentrating on the specific task of parsing things, the result will be a beautiful and usable interface to the text strings that power the Internet world.

Here’s a sample of the code that this library lets you write:

from ietfparse import algorithms, headers

def negotiate_versioned_representation(request, handler, data_dict):
    requested = headers.parse_accept(request.headers['Accept'])
    selected = algorithms.select_content_type(requested, [
        headers.parse_content_type('application/example+json; v=1'),
        headers.parse_content_type('application/example+json; v=2'),
        headers.parse_content_type('application/json'),
    ])

    output_version = selected.parameters.get('v', '2')
    if output_version == '1':
        handler.set_header('Content-Type', 'application/example+json; v=1')
        handler.write(generate_legacy_json(data_dict))
    else:
        handler.set_header('Content-Type', 'application/example+json; v=2')
        handler.write(generate_modern_json(data_dict))

def redirect_to_peer(host, port=80):
    flask.redirect(algorithms.rewrite_url(flask.request.url,
                                          host=host, port=port))

OK… Where?

Source

https://github.com/dave-shawley/ietfparse

Status

https://circleci.com/gh/dave-shawley/ietfparse/tree/master

Download

https://pypi.org/project/ietfparse

Documentation

https://ietfparse.readthedocs.io/en/latest

Issues

https://github.com/dave-shawley/ietfparse

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ietfparse-1.9.0.tar.gz (38.3 kB view details)

Uploaded Source

Built Distribution

ietfparse-1.9.0-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file ietfparse-1.9.0.tar.gz.

File metadata

  • Download URL: ietfparse-1.9.0.tar.gz
  • Upload date:
  • Size: 38.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for ietfparse-1.9.0.tar.gz
Algorithm Hash digest
SHA256 2a5e7006f742e42a3651cd24d16f050acdf7ae4d0ae0cd576f3f4abc150dc5b3
MD5 f31bccf2fc25c0b2f231cbd60f840f15
BLAKE2b-256 1fd95347ee8ff3765800d4aaab7d6a9816ac4ed6fee4fbafcf6cb8ffc58c3094

See more details on using hashes here.

File details

Details for the file ietfparse-1.9.0-py3-none-any.whl.

File metadata

  • Download URL: ietfparse-1.9.0-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for ietfparse-1.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72216d31d94764156c4380c419af41295b53a1b309dd8091e5610a411c8b5446
MD5 9e0a6c236cea07a3f6bf95f6a1d96631
BLAKE2b-256 11ac5c6e72985228dee72e25a28b12ad97746832c9cca846d2969b0452018fdb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page