link_header /

Filename Size Date modified Message
48 B
Add .hgignore
394 B
version 0.4.2 for PyPi
1.5 KB
Add LICENSE and README files
1.1 KB
Add LICENSE and README files
12.3 KB
provide convenience functions for context and target
32 B
Tidy up doctest setup, add setup.cfg
791 B
Add LICENSE and README files

Parse and format link headers according to RFC 5988 "Web Linking".

Usage (assuming a suitable headers object in the environment):

>>> headers['Link'] = str(LinkHeader([Link("", rel="self"),
...                                   Link("", rel="up")]))
>>> headers['Link']
'<>; rel=self, <>; rel=up'
>>> parse(headers['Link'])
LinkHeader([Link('', rel='self'), Link('', rel='up')])

Blank and missing values roundtrip correctly:

>>> format_link(parse('</s/1>; obs; if="core.s"; foo=""'))
'<</s/1>; obs; if=core.s; foo="">'

Conversions to and from json-friendly list-based structures are also provided:

>>> parse(headers['Link']).to_py()
[['', [['rel', 'self']]], ['', [['rel', 'up']]]]
>>> str(LinkHeader([['', [['rel', 'self']]],
...                 ['', [['rel', 'up']]]]))
'<>; rel=self, <>; rel=up'