mahanama94 / link-parse Goto Github PK
View Code? Open in Web Editor NEWPython Package for link header parsing.
License: Other
Python Package for link header parsing.
License: Other
One of the largest problems we have is parsing link-formatted TimeMaps. The RegexLinkParser gets farther than any other implementation I've seen, besides the solution I implemented in AIU, and even AIU has issues with the occasional TimeMap.
It parses a TimeMap into the appropriate relationships, but with the following unexpected behaviors:
strip
this off, but they will not expect thistitle
key in the resulting dict -- I realize that this is part of RFC5988, but link-parse does not produce empty entries for anchor
, rev
, or other link parameters listed in that RFC so this is confusingHere's what I did with RegexLinkParser:
timemap
Here's the code in ipython:
In [1]: from linkparse.regex_parser import RegexLinkParser
In [2]: timemap = """ <http://a.example.org>;rel="original",
...: <http://arxiv.example.net/timemap/http://a.example.org>
...: ; rel="self";type="application/link-format"
...: ; from="Tue, 20 Jun 2000 18:02:59 GMT"
...: ; until="Wed, 09 Apr 2008 20:30:51 GMT",
...: <http://arxiv.example.net/timegate/http://a.example.org>
...: ; rel="timegate",
...: <http://arxiv.example.net/web/20000620180259/http://a.example.org>
...: ; rel="first memento";datetime="Tue, 20 Jun 2000 18:02:59 GMT"
...: ; license="http://creativecommons.org/publicdomain/zero/1.0/",
...: <http://arxiv.example.net/web/20091027204954/http://a.example.org>
...: ; rel="last memento";datetime="Tue, 27 Oct 2009 20:49:54 GMT"
...: ; license="http://creativecommons.org/publicdomain/zero/1.0/",
...: <http://arxiv.example.net/web/20000621011731/http://a.example.org>
...: ; rel="memento";datetime="Wed, 21 Jun 2000 01:17:31 GMT"
...: ; license="http://creativecommons.org/publicdomain/zero/1.0/",
...: <http://arxiv.example.net/web/20000621044156/http://a.example.org>
...: ; rel="memento";datetime="Wed, 21 Jun 2000 04:41:56 GMT"
...: ; license="http://creativecommons.org/publicdomain/zero/1.0/",
...: """
In [3]: parser = RegexLinkParser()
In [4]: parser_results = parser.parse(timemap)
In [5]: from pprint import pprint
In [6]: for result in parser_results:
...: pprint(result.__dict__)
...:
{'datetime': '',
'link_from': '',
'link_type': '',
'link_until': '',
'relationship': 'original',
'title': '',
'uri': 'http://a.example.org'}
{'datetime': '',
'link_from': 'Tue, 20 Jun 2000 18:02:59 GMT',
'link_type': 'application/link-format',
'link_until': 'Wed, 09 Apr 2008 20:30:51 GMT',
'relationship': 'self',
'title': '',
'uri': 'http://arxiv.example.net/timemap/http://a.example.org\n '}
{'datetime': '',
'link_from': '',
'link_type': '',
'link_until': '',
'relationship': 'timegate',
'title': '',
'uri': 'http://arxiv.example.net/timegate/http://a.example.org\n '}
{'datetime': 'Tue, 20 Jun 2000 18:02:59 GMT',
'link_from': '',
'link_type': '',
'link_until': '',
'relationship': 'first memento',
'title': '',
'uri': 'http://arxiv.example.net/web/20000620180259/http://a.example.org\n'
' '}
{'datetime': 'Tue, 27 Oct 2009 20:49:54 GMT',
'link_from': '',
'link_type': '',
'link_until': '',
'relationship': 'last memento',
'title': '',
'uri': 'http://arxiv.example.net/web/20091027204954/http://a.example.org\n'
' '}
{'datetime': 'Wed, 21 Jun 2000 01:17:31 GMT',
'link_from': '',
'link_type': '',
'link_until': '',
'relationship': 'memento',
'title': '',
'uri': 'http://arxiv.example.net/web/20000621011731/http://a.example.org\n'
' '}
{'datetime': 'Wed, 21 Jun 2000 04:41:56 GMT',
'link_from': '',
'link_type': '',
'link_until': '',
'relationship': 'memento',
'title': '',
'uri': 'http://arxiv.example.net/web/20000621044156/http://a.example.org\n'
' '}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.