99The license for OTMT at the time timemap.py was copied was the MIT license,
1010https://github.com/oduwsdl/off-topic-memento-toolkit/blob/master/LICENSE.txt
1111
12+ Since copying the original, I've made some alterations to this source code.
13+ The git history can be consulted to find out what the changes have been.
14+
1215Authors (original)
1316------------------
1417
2023Michael Hucka <mhucka@caltech.edu> -- Caltech Library
2124'''
2225
23- from copy import deepcopy
24- from datetime import datetime
25- import requests
26+ from datetime import datetime
2627
27- from ..exceptions import *
28+ from ..exceptions import CorruptedContent
2829
2930
3031def timemap_as_dict(timemap_text, skip_errors = False):
@@ -45,6 +46,9 @@ def process_local_dict(local_dict, working_dict):
4546
4647 for uri in local_dict:
4748
49+ if "rel" not in local_dict[uri]:
50+ raise ValueError("Missing 'rel' element in timemap")
51+
4852 relation = local_dict[uri]["rel"]
4953
5054 if relation == "original":
@@ -94,7 +98,6 @@ def process_local_dict(local_dict, working_dict):
9498
9599 return working_dict
96100
97-
98101 dict_timemap = {}
99102
100103 # current_char = ""
@@ -160,9 +163,7 @@ def process_local_dict(local_dict, working_dict):
160163 state = 3
161164 elif character == ',':
162165 state = 0
163-
164166 process_local_dict(local_dict, dict_timemap)
165-
166167 elif character == '"':
167168 state = 5
168169 elif character.isspace():
@@ -193,7 +194,14 @@ def process_local_dict(local_dict, working_dict):
193194 raise CorruptedContent(
194195 "discovered unknown state while processing TimeMap")
195196
196- process_local_dict(local_dict, dict_timemap)
197+ try:
198+ process_local_dict(local_dict, dict_timemap)
199+ except Exception as ex:
200+ if not skip_errors:
201+ raise CorruptedContent(
202+ "unexpected construction in timemap: " + str(ex))
203+ else:
204+ return dict()
197205
198206 return dict_timemap
199207
0 commit comments