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 validate(jsonData, filepath):
    print('*************************')
    print('Testing: {}'.format(filepath))
    result = schemavalidator.validate(json.dumps(jsonData), '3.0', filepath)
    if result['okay'] != 1:
        # Failed validation
        for error in result['errorList']:
            print('# {}'.format(error['title']))
            print('Detail: {}'.format(error['detail']))
            print('Path: {}'.format(error['path']))
            print('Description: {}'.format(error['description']))
            print('context:')
            print(json.dumps(error['context'], indent=4))

    print('*************************')
    return result['okay'] == 1
    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)