http-sfv

Parse and serialise HTTP structured field values

https://github.com/mnot/http_sfv

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.1%) to scientific vocabulary

Keywords

headers http parser python

Keywords from Contributors

interactive serializer packaging network-simulation shellcodes hacking autograding observability genomics embedded
Last synced: 6 months ago · JSON representation

Repository

Parse and serialise HTTP structured field values

Basic Info
  • Host: GitHub
  • Owner: mnot
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 232 KB
Statistics
  • Stars: 13
  • Watchers: 4
  • Forks: 0
  • Open Issues: 1
  • Releases: 0
Topics
headers http parser python
Created over 7 years ago · Last pushed 6 months ago
Metadata Files
Readme

README.md

HTTP Structured Field Values in Python

Actions Status

This Package is DEPRECATED

See the http-sf package for a replacement. This package will only be updated for security issues, and may be yanked in the future.

Introduction

This is a Python 3 library implementing parsing and serialisation of HTTP Structured Fields.

The library's initial purpose is to prove the algorithms in the specification; as a result, it is not at all optimised. It tracks the specification closely, but since it is not yet an RFC, may change at any time.

Currently, this implements draft-ietf-httpbis-sfbis-03.

Python API

There are three top-level types for Structured Field Values; Dictionary, List and Item. After instantiation, each can be used to parse a string HTTP header field value by calling .parse():

~~~ python

from httpsfv import List mylist = List() my_list.parse(b"foo; a=1, bar; b=2") ~~~

Note that .parse() takes a bytes-like object. If you want to parse a string, please .encode() it first.

Members of Lists and Dictionaries are available by normal Pythonic list and dictionary methods, respectively:

~~~ python

mylist [<httpsfv.item.Item object at 0x106d25190>, ] mylist[0] <httpsfv.item.Item object at 0x106d25190> ~~~

Items (whether top-level or inside a list or dictionary value) can have their values accessed with the .value property:

~~~ python

my_list[0].value 'foo' ~~~

Parameters on Items (and Inner Lists) can be accessed using the .params property, which is a dictionary:

~~~ python

my_list[0].params['a'] 1 ~~~

Note that Tokens and Strings both evaluate as Python strings, but Tokens have a different class:

~~~ python

type(mylist[0].value) <class 'httpsfv.token.Token'> ~~~

That means that you need to create Tokens explicitly:

~~~ python

from httpsfv import Token mylist.append(Token('bar')) my_list[-1] 'bar' ~~~

Likewise, Display Strings are represented using DisplayString objects; Dates as datetime.datetime objects.

If you compare two Items, they'll be considered to be equivalent if their values match, even when their parameters are different:

~~~ python

Token('foo') in mylist # note that mylist's 'foo' has a parameter True my_list.count(Token("foo")) 1 ~~~

Inner Lists can be added by passing a list:

~~~ python

mylist.append(['anotherthing', 'andanother']) print(mylist) foo;a=1, bar;b=2, bar, ("anotherthing" "andanother") my_list[-1][-1].params['a'] = True ~~~

Dictionaries, Lists, and Items can be instantiated with a value:

~~~ python

from httpsfv import Dictionary mydictionary = Dictionary({'a': '1', 'b': 2, 'c': Token('foo')}) mydictionary {'a': <httpsfv.item.Item object at 0x106a94c40>, 'b': , 'c': } ~~~

Once instantiated, parameters can then be accessed:

~~~ python

my_dictionary['b'].params['1'] = 2.0 ~~~

Finally, to serialise a field value, just evaluate it as a string:

~~~ python

print(my_dictionary) a=1, b=2;b1=2.0, c=foo ~~~

Command Line Use

You can validate and examine the data model of a field value by calling the library on the command line, using -d, -l and -i to denote dictionaries, lists or items respectively; e.g.,

~~~ example

python3 -m httpsfv -i "foo;bar=baz" [ { "type": "token", "value": "foo" }, { "bar": { "_type": "token", "value": "baz" } } ] ~~~

or:

~~~ example

python3 -m http_sfv -i "foo;&bar=baz" FAIL: Key does not begin with lcalpha or * at: &bar=baz ~~~

Note that if successful, the output is in the JSON format used by the test suite.

Owner

  • Name: Mark Nottingham
  • Login: mnot
  • Kind: user
  • Location: Prahran, Australia

I work on HTTP specifications and implementations.

GitHub Events

Total
  • Delete event: 2
  • Push event: 1
  • Pull request event: 2
  • Create event: 2
Last Year
  • Delete event: 2
  • Push event: 1
  • Pull request event: 2
  • Create event: 2

Committers

Last synced: 8 months ago

All Time
  • Total Commits: 246
  • Total Committers: 2
  • Avg Commits per committer: 123.0
  • Development Distribution Score (DDS): 0.008
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Mark Nottingham m****t@m****t 244
dependabot[bot] 4****] 2
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 6
  • Total pull requests: 6
  • Average time to close issues: 6 months
  • Average time to close pull requests: 3 days
  • Total issue authors: 6
  • Total pull request authors: 2
  • Average comments per issue: 1.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 5
  • Bot issues: 0
  • Bot pull requests: 2
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • mnot (1)
  • ioggstream (1)
  • martinthomson (1)
  • kislyuk (1)
  • jkhales (1)
  • bortzmeyer (1)
Pull Request Authors
  • mnot (4)
  • dependabot[bot] (2)
Top Labels
Issue Labels
Pull Request Labels
dependencies (2) github_actions (2)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 25,828 last-month
  • Total dependent packages: 2
  • Total dependent repositories: 3
  • Total versions: 14
  • Total maintainers: 1
pypi.org: http-sfv

Parse and serialise HTTP Structured Field Values

  • Versions: 14
  • Dependent Packages: 2
  • Dependent Repositories: 3
  • Downloads: 25,828 Last month
Rankings
Downloads: 2.7%
Dependent repos count: 9.0%
Dependent packages count: 10.0%
Average: 13.4%
Stargazers count: 15.6%
Forks count: 29.8%
Maintainers (1)
Last synced: 6 months ago

Dependencies

requirements.txt pypi
  • black *
  • build *
  • mypy >=0.770
  • pylint >=2.4.4
  • twine >=3.1.1
  • typing_extensions *
.github/workflows/main.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
pyproject.toml pypi