Esempio n. 1
0
def browse():
    uri = request.args.get('uri', None)

    if uri is None:
        return document()
    else:
        if 'Accept' in request.headers:
            mimetype = parse_accept_header(request.headers['Accept']).best
        else:
            log.debug("No accept header, using 'text/html'")
            mimetype = 'text/html'

        try:
            if mimetype in ['text/html', 'application/xhtml_xml', '*/*']:
                results = visit(uri, format='html', external=True)
                local_results = localize_results(results)
                return render_template('resource.html', local_resource='http://bla', resource=uri, results=local_results, local=LOCAL_STORE, preflabel=PREFLABEL_SERVICE)
            elif mimetype in ['application/json']:
                response = make_response(visit(uri, format='jsonld', external=True), 200)
                response.headers['Content-Type'] = 'application/json'
                return response
            elif mimetype in ['application/rdf+xml', 'application/xml']:
                response = make_response(visit(uri, format='rdfxml', external=True), 200)
                response.headers['Content-Type'] = 'application/rdf+xml'
                return response
            elif mimetype in ['application/x-turtle', 'text/turtle']:
                response = make_response(visit(uri, format='turtle', external=True), 200)
                response.headers['Content-Type'] = 'text/turtle'
                return response
        except Exception as e:
            log.error(e)
            log.error(traceback.format_exc())
            return traceback.format_exc()
Esempio n. 2
0
def browse():
    uri = request.args.get('uri', None)

    if uri is None:
        return document()
    else:
        if 'Accept' in request.headers:
            mimetype = parse_accept_header(request.headers['Accept']).best
        else:
            log.debug("No accept header, using 'text/html'")
            mimetype = 'text/html'

        try:
            if mimetype in ['text/html', 'application/xhtml_xml', '*/*']:
                results = visit(uri, format='html', external=True)
                local_results = localize_results(results)
                return render_template('resource.html', local_resource='http://bla', resource=uri, results=local_results, local=LOCAL_STORE)
            elif mimetype in ['application/json']:
                response = make_response(visit(uri, format='jsonld', external=True), 200)
                response.headers['Content-Type'] = 'application/json'
                return response
            elif mimetype in ['application/rdf+xml', 'application/xml']:
                response = make_response(visit(uri, format='rdfxml', external=True), 200)
                response.headers['Content-Type'] = 'application/rdf+xml'
                return response
            elif mimetype in ['application/x-turtle', 'text/turtle']:
                response = make_response(visit(uri, format='turtle', external=True), 200)
                response.headers['Content-Type'] = 'text/turtle'
                return response
        except Exception as e:
            log.error(e)
            log.error(traceback.format_exc())
            return traceback.format_exc()
Esempio n. 3
0
def browse():
    uri = request.args.get('uri', None)

    if uri is None:
        return document()
    else:
        if 'Accept' in request.headers:
            mimetype = parse_accept_header(request.headers['Accept']).best
        else:
            log.debug("No accept header, using 'text/html'")
            mimetype = 'text/html'

        try:
            if mimetype in ['text/html', 'application/xhtml_xml', '*/*']:
                try:
                    results = visit(uri, format='html', external=True)
                except:  #when the uri is a javascript injection (or any other illegal string) this will fail and the uri shouldn't be send to the response
                    return render_template('resource.html',
                                           local_resource='http://bla',
                                           resource="error in sparql query",
                                           results=[],
                                           local=LOCAL_STORE,
                                           preflabel=PREFLABEL_SERVICE)
                local_results = localize_results(results)
                if local_results == []:  #when there are no results the uri might be a javascript injection and the uri shouldn't be send to the response
                    uri = "unknown uri"
                return render_template('resource.html',
                                       local_resource='http://bla',
                                       resource=uri,
                                       results=local_results,
                                       local=LOCAL_STORE,
                                       preflabel=PREFLABEL_SERVICE)
            elif mimetype in ['application/json']:
                response = make_response(
                    visit(uri, format='jsonld', external=True), 200)
                response.headers['Content-Type'] = 'application/json'
                return response
            elif mimetype in ['application/rdf+xml', 'application/xml']:
                response = make_response(
                    visit(uri, format='rdfxml', external=True), 200)
                response.headers['Content-Type'] = 'application/rdf+xml'
                return response
            elif mimetype in ['application/x-turtle', 'text/turtle']:
                response = make_response(
                    visit(uri, format='turtle', external=True), 200)
                response.headers['Content-Type'] = 'text/turtle'
                return response
        except Exception as e:
            log.error(e)
            log.error(traceback.format_exc())
            return traceback.format_exc()
Esempio n. 4
0
def document(resource_suffix=""):
    if resource_suffix:
        uri = u"{}/{}".format(DEFAULT_BASE, resource_suffix)
    else:
        uri = START_URI

    log.debug('The URI we will use is: ' + uri)

    if 'Accept' in request.headers:
        mimetype = parse_accept_header(request.headers['Accept']).best
        log.debug("Looking for mime type '{}'".format(mimetype))
    else:
        log.debug("No accept header, using 'text/html'")
        mimetype = 'text/html'

    try:
        if mimetype in ['text/html', 'application/xhtml_xml', '*/*']:
            local_resource_uri = u"{}/{}".format(LOCAL_SERVER_NAME,
                                                 resource_suffix)
            results = visit(uri, format='html')
            local_results = localize_results(results)

            return render_template('resource.html',
                                   local_resource=local_resource_uri,
                                   resource=uri,
                                   results=local_results,
                                   local=LOCAL_STORE,
                                   preflabel=PREFLABEL_SERVICE)
        elif mimetype in ['application/json']:
            response = make_response(visit(uri, format='jsonld'), 200)
            response.headers['Content-Type'] = 'application/json'
            return response
        elif mimetype in ['application/rdf+xml', 'application/xml']:
            response = make_response(visit(uri, format='rdfxml'), 200)
            response.headers['Content-Type'] = 'application/rdf+xml'
            return response
        elif mimetype in ['application/x-turtle', 'text/turtle']:
            response = make_response(visit(uri, format='turtle'), 200)
            response.headers['Content-Type'] = 'text/turtle'
            return response
    except Exception as e:
        log.error(e)
        log.error(traceback.format_exc())
        return make_response("Incorrect mimetype or other error", 400)
Esempio n. 5
0
def graph_json():
    uri = request.args.get('uri', None)

    # Visit the selected URI up to a depth of 2
    results = visit(uri, format='html', depth=SUNBURST_DEPTH)
    local_results = localize_results(results)
    # graph = prepare_graph(local_results)
    labels, incoming, outgoing = prepare_sunburst(uri, local_results, SUNBURST_DEPTH)

    return jsonify({'labels': labels, 'incoming': incoming, 'outgoing': outgoing})
Esempio n. 6
0
def document(resource_suffix=""):
    if resource_suffix:
        uri = u"{}/{}".format(DEFAULT_BASE, resource_suffix)
    else:
        uri = START_URI

    log.debug('The URI we will use is: ' + uri)

    if 'Accept' in request.headers:
        mimetype = parse_accept_header(request.headers['Accept']).best
        log.debug("Looking for mime type '{}'".format(mimetype))
    else:
        log.debug("No accept header, using 'text/html'")
        mimetype = 'text/html'

    try:
        if mimetype in ['text/html', 'application/xhtml_xml','*/*']:
            local_resource_uri = u"{}/{}".format(LOCAL_SERVER_NAME,resource_suffix)
            results = visit(uri, format='html')
            local_results = localize_results(results)

            return render_template('resource.html', local_resource=local_resource_uri, resource=uri, results=local_results, local=LOCAL_STORE, preflabel=PREFLABEL_SERVICE)
        elif mimetype in ['application/json']:
            response = make_response(visit(uri,format='jsonld'),200)
            response.headers['Content-Type'] = 'application/json'
            return response
        elif mimetype in ['application/rdf+xml','application/xml']:
            response = make_response(visit(uri,format='rdfxml'),200)
            response.headers['Content-Type'] = 'application/rdf+xml'
            return response
        elif mimetype in ['application/x-turtle','text/turtle']:
            response = make_response(visit(uri,format='turtle'),200)
            response.headers['Content-Type'] = 'text/turtle'
            return response
    except Exception as e:
        log.error(e)
        log.error(traceback.format_exc())
        return make_response("Incorrect mimetype or other error", 400)
Esempio n. 7
0
def graph_json():
    uri = request.args.get('uri', None)

    # Visit the selected URI up to a depth of 2
    results = visit(uri, format='html', depth=SUNBURST_DEPTH)
    local_results = localize_results(results)
    # graph = prepare_graph(local_results)
    labels, incoming, outgoing = prepare_sunburst(uri, local_results,
                                                  SUNBURST_DEPTH)

    return jsonify({
        'labels': labels,
        'incoming': incoming,
        'outgoing': outgoing
    })
Esempio n. 8
0
 def test_success_request(self):
     success_send = mock.Mock(return_value='200')
     client.send_request = success_send
     self.assertEqual(client.visit(URL), '200')
Esempio n. 9
0
 def test_fail_request(self):
     fail_send = mock.Mock(return_value='404')
     client.send_request = fail_send
     self.assertEqual(client.visit(URL), '404')