mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
- memento fixes, fully support memento pattern 2.2 api spec - add timemap endpoints at /timemap/link/<url>, also /timemap/cdxj/<url>, /timemap/json/<url> - include original and timemap links in Link header - correct memento headers for timegate, timemap, memento - support Accept-Datetime header for timegate - Link rel="memento" includes canonical url, matches Content-Location url - tests: update memento tests
31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
import re
|
|
|
|
MEMENTO_DATETIME = 'Memento-Datetime'
|
|
ACCEPT_DATETIME = 'Accept-Datetime'
|
|
LINK = 'Link'
|
|
VARY = 'Vary'
|
|
LINK_FORMAT = 'application/link-format'
|
|
|
|
class MementoMixin(object):
|
|
def get_links(self, resp):
|
|
return list(map(lambda x: x.strip(), re.split(', (?![0-9])', resp.headers[LINK])))
|
|
|
|
def make_timemap_link(self, url, coll='pywb'):
|
|
format_ = '<http://localhost:80/{2}/timemap/link/{0}>; rel="timemap"; type="{1}"'
|
|
return format_.format(url, LINK_FORMAT, coll)
|
|
|
|
def make_original_link(self, url):
|
|
format_ = '<{0}>; rel="original"'
|
|
return format_.format(url)
|
|
|
|
def make_timegate_link(self, url, fmod='', coll='pywb'):
|
|
fmod_slash = fmod + '/' if fmod else ''
|
|
format_ = '<http://localhost:80/{2}/{1}{0}>; rel="timegate"'
|
|
return format_.format(url, fmod_slash, coll)
|
|
|
|
def make_memento_link(self, url, ts, dt, fmod='', coll='pywb'):
|
|
format_ = '<http://localhost:80/{4}/{1}{3}/{0}>; rel="memento"; datetime="{2}"'
|
|
return format_.format(url, ts, dt, fmod, coll)
|
|
|
|
|