def make_timemap(wbrequest, cdx_lines): prefix = wbrequest.wb_prefix url = wbrequest.wb_url.url mod = wbrequest.options.get('replay_mod', '') # get first memento as it'll be used for 'from' field try: first_cdx = six.next(cdx_lines) from_date = timestamp_to_http_date(first_cdx['timestamp']) except StopIteration: first_cdx = None if first_cdx: # timemap link timemap = ('<{0}>; rel="self"; ' + 'type="application/link-format"; from="{1}",\n') yield timemap.format(prefix + wbrequest.wb_url.to_str(), from_date) # original link original = '<{0}>; rel="original",\n' yield original.format(url) # timegate link timegate = '<{0}>; rel="timegate",\n' timegate_url= WbUrl.to_wburl_str(url=url, mod=mod, type=WbUrl.LATEST_REPLAY) yield timegate.format(prefix + timegate_url) if not first_cdx: # terminating timemap link, no from timemap = ('<{0}>; rel="self"; type="application/link-format"') yield timemap.format(prefix + wbrequest.wb_url.to_str()) return # first memento link yield make_timemap_memento_link(first_cdx, prefix, datetime=from_date, mod=mod) prev_cdx = None for cdx in cdx_lines: if prev_cdx: yield make_timemap_memento_link(prev_cdx, prefix, mod=mod) prev_cdx = cdx # last memento link, if any if prev_cdx: yield make_timemap_memento_link(prev_cdx, prefix, end='', mod=mod)
def make_timemap(wbrequest, cdx_lines): prefix = wbrequest.wb_prefix url = wbrequest.wb_url.url mod = wbrequest.options.get('replay_mod', '') # get first memento as it'll be used for 'from' field try: first_cdx = six.next(cdx_lines) from_date = timestamp_to_http_date(first_cdx['timestamp']) except StopIteration: first_cdx = None if first_cdx: # timemap link timemap = ('<{0}>; rel="self"; ' + 'type="application/link-format"; from="{1}",\n') yield timemap.format(prefix + wbrequest.wb_url.to_str(), from_date) # original link original = '<{0}>; rel="original",\n' yield original.format(url) # timegate link timegate = '<{0}>; rel="timegate",\n' timegate_url = WbUrl.to_wburl_str(url=url, mod=mod, type=WbUrl.LATEST_REPLAY) yield timegate.format(prefix + timegate_url) if not first_cdx: # terminating timemap link, no from timemap = ('<{0}>; rel="self"; type="application/link-format"') yield timemap.format(prefix + wbrequest.wb_url.to_str()) return # first memento link yield make_timemap_memento_link(first_cdx, prefix, datetime=from_date, mod=mod) prev_cdx = None for cdx in cdx_lines: if prev_cdx: yield make_timemap_memento_link(prev_cdx, prefix, mod=mod) prev_cdx = cdx # last memento link, if any if prev_cdx: yield make_timemap_memento_link(prev_cdx, prefix, end='', mod=mod)
def make_memento_link(cdx, prefix, datetime=None, rel='memento', end=',\n'): memento = '<{0}>; rel="{1}"; datetime="{2}"' + end string = WbUrl.to_wburl_str(url=cdx['original'], mod='', timestamp=cdx['timestamp'], type=WbUrl.REPLAY) url = prefix + string if not datetime: datetime = timestamp_to_http_date(cdx['timestamp']) return memento.format(url, rel, datetime)