Source code for pywb.utils.memento

import re
import six

from warcio.timeutils import timestamp_to_http_date, http_date_to_timestamp

from pywb.utils.wbexception import BadRequestException


LINK_SPLIT = re.compile(',\s*(?=[<])')
LINK_SEG_SPLIT = re.compile(';\s*')
LINK_URL = re.compile('<(.*)>')
LINK_PROP = re.compile('([\w]+)="([^"]+)')

FIND_DT = re.compile('datetime=\"([^\"]+)\"')


#=============================================================================
[docs]class MementoException(BadRequestException): pass
#=============================================================================
[docs]class MementoUtils(object):
[docs] @classmethod def make_timemap(cls, cdx_iter, params): prev_cdx = None memento_format = params.get('memento_format') for cdx in cdx_iter: if prev_cdx: yield cls.make_timemap_memento_link(prev_cdx, memento_format=memento_format) prev_cdx = cdx # last memento link, if any if prev_cdx: yield cls.make_timemap_memento_link(prev_cdx, end='\n', memento_format=memento_format)
[docs] @classmethod def wrap_timemap_header(cls, url, timegate_url, timemap_url, timemap): string = cls.make_link(timemap_url, "self") m = FIND_DT.search(timemap) if m: string += '; from="{0}"'.format(m.group(1)) string += ',\n' string += cls.make_link(timegate_url, "timegate") + ',\n' string += cls.make_link(url, "original") + ',\n' string += timemap return string