def check_manifest(self, data, version, url=None, warnings=[]): """Check manifest data at version, return JSON.""" infojson = {} # Check if 3.0 if so run through schema rather than this version... if version == '3.0': infojson = schemavalidator.validate(data, version, url) else: reader = ManifestReader(data, version=version) err = None try: mf = reader.read() mf.toJSON() # Passed! okay = 1 except Exception as e: # Failed err = e okay = 0 warnings.extend(reader.get_warnings()) infojson = { 'received': data, 'okay': okay, 'warnings': warnings, 'error': str(err), 'url': url } return self.return_json(infojson)
def check_manifest(self, data, version, warnings=[]): # Now check data reader = ManifestReader(data, version=version) err = None try: mf = reader.read() mf.toJSON() # Passed! okay = 1 except Exception as e: # Failed err = e okay = 0 warnings.extend(reader.get_warnings()) infojson = {'received': data, 'okay': okay, 'warnings': warnings, \ 'error': str(err)} return self.return_json(infojson)
def do_GET_test(self): url = request.query.get('url', '') version = request.query.get('version', '2.0') url = url.strip() parsed_url = urlparse(url) if not parsed_url.scheme.startswith('http'): return self.format_response({'okay': 0, 'error': 'URLs must use HTTP or HTTPS', 'url': url}) try: (data, webhandle) = self.fetch(url) except: return self.format_response({'okay': 0, 'error': 'Cannot fetch url', 'url': url}) # First check HTTP level ct = webhandle.headers.get('content-type', '') cors = webhandle.headers.get('access-control-allow-origin', '') warnings = [] if not ct.startswith('application/json') and not ct.startswith('application/ld+json'): # not json warnings.append("URL does not have correct content-type header: got \"%s\", expected JSON" % ct) if cors != "*": warnings.append("URL does not have correct access-control-allow-origin header:" " got \"%s\", expected *" % cors) # Now check data reader = ManifestReader(data, version=version) err = None try: mf = reader.read() mf.toJSON() # Passed! okay = 1 except Exception as err: # Failed okay = 0 warnings.extend(reader.get_warnings()) infojson = {'url': url, 'okay': okay, 'warnings': warnings, 'error': str(err)} return self.format_response(infojson)
def do_POST_test(self): data = request.json version = '2.0' warnings = [] # Now check data reader = ManifestReader(data, version=version) err = None try: mf = reader.read() mf.toJSON() # Passed! okay = 1 except Exception as err: # Failed okay = 0 warnings.extend(reader.get_warnings()) infojson = {'received': data, 'okay': okay, 'warnings': warnings, 'error': str(err)} return self.format_response(infojson)
def check_manifest(self, data, version, url=None, warnings=[]): """Check manifest data at version, return JSON.""" reader = ManifestReader(data, version=version) err = None try: mf = reader.read() mf.toJSON() # Passed! okay = 1 except Exception as e: # Failed err = e okay = 0 warnings.extend(reader.get_warnings()) infojson = { 'received': data, 'okay': okay, 'warnings': warnings, 'error': str(err), 'url': url } return self.return_json(infojson)
def check_manifest(self, data, version, url=None, warnings=[]): """Check manifest data at version, return JSON.""" infojson = {} # Check if 3.0 if so run through schema rather than this version... if version == '3.0': try: infojson = schemavalidator.validate(data, version, url) for error in infojson['errorList']: error.pop('error', None) mf = json.loads(data) if url and 'id' in mf and mf['id'] != url: raise ValidationError( "The manifest id ({}) should be the same as the URL it is published at ({})." .format(mf["id"], url)) except ValidationError as e: if infojson: infojson['errorList'].append({ 'title': 'Resolve Error', 'detail': str(e), 'description': '', 'path': '/id', 'context': '{ \'id\': \'...\'}' }) else: infojson = { 'received': data, 'okay': 0, 'error': str(e), 'url': url, 'warnings': [] } except Exception as e: traceback.print_exc() infojson = { 'received': data, 'okay': 0, 'error': 'Presentation Validator bug: "{}". Please create a <a href="https://github.com/IIIF/presentation-validator/issues">Validator Issue</a>, including a link to the manifest.' .format(e), 'url': url, 'warnings': [] } else: reader = ManifestReader(data, version=version) err = None try: mf = reader.read() mf.toJSON() if url and mf.id != url: raise ValidationError( "Manifest @id ({}) is different to the location where it was retrieved ({})" .format(mf.id, url)) # Passed! okay = 1 except KeyError as e: print('Failed falidation due to:') traceback.print_exc() err = 'Failed due to KeyError {}, check trace for details'.format( e) okay = 0 except Exception as e: # Failed print('Failed falidation due to:') traceback.print_exc() err = e okay = 0 warnings.extend(reader.get_warnings()) infojson = { 'received': data, 'okay': okay, 'warnings': warnings, 'error': str(err), 'url': url } return self.return_json(infojson)