Ejemplo n.º 1
0
    def parse(self, source):

        try:
            r = Result('SELECT')

            header = source.readline()

            r.vars = list(HEADER.parseString(header.strip(), parseAll=True))
            r.bindings = []
            while True:
                line = source.readline()
                if not line:
                    break
                line = line.strip()
                if line == "":
                    continue

                row = ROW.parseString(line, parseAll=True)
                r.bindings.append(
                    dict(zip(r.vars, (self.convertTerm(x) for x in row))))

            return r

        except ParseException, err:
            print err.line
            print " " * (err.column - 1) + "^"
            print err
Ejemplo n.º 2
0
    def parse(self, source):

        if isinstance(source.read(0), bytestype):
            # if reading from source returns bytes do utf-8 decoding
            source = codecs.getreader('utf-8')(source)

        try:
            r = Result('SELECT')

            header = source.readline()

            r.vars = list(HEADER.parseString(header.strip(), parseAll=True))
            r.bindings = []
            while True:
                line = source.readline()
                if not line:
                    break
                line = line.strip('\n')
                if line == "":
                    continue

                row = ROW.parseString(line, parseAll=True)
                r.bindings.append(
                    dict(zip(r.vars, (self.convertTerm(x) for x in row))))

            return r

        except ParseException, err:
            print err.line
            print " " * (err.column - 1) + "^"
            print err
Ejemplo n.º 3
0
    def parse(self, source, content_type):

        res = Result('CONSTRUCT')  # hmm - or describe?type_)
        res.graph = Graph()
        res.graph.parse(source, format=content_type)

        return res
Ejemplo n.º 4
0
    def parse(self, source):

        r = Result('SELECT')

        reader = csv.reader(source, delimiter=self.delim)
        r.vars = [Variable(x) for x in reader.next()]
        r.bindings = []

        for row in reader:
            r.bindings.append(self.parseRow(row, r.vars))

        return r
Ejemplo n.º 5
0
    def parse(self, source):

        r = Result('SELECT')

        if hasattr(source, 'mode') and 'b' in source.mode:
            source = codecs.getreader('utf-8')(source)

        reader = csv.reader(source, delimiter=self.delim)
        r.vars = [Variable(x) for x in reader.next()]
        r.bindings = []

        for row in reader:
            r.bindings.append(self.parseRow(row, r.vars))

        return r
Ejemplo n.º 6
0
    def parse(self, source):

        r = Result('SELECT')

        if isinstance(source.read(0), binary_type):
            # if reading from source returns bytes do utf-8 decoding
            source = codecs.getreader('utf-8')(source)

        reader = csv.reader(source, delimiter=self.delim)
        r.vars = [Variable(x) for x in next(reader)]
        r.bindings = []

        for row in reader:
            r.bindings.append(self.parseRow(row, r.vars))

        return r
Ejemplo n.º 7
0
    def check_violations(self):
        res = []
        headers = {
            'Content-Type':
            'application/x-turtle, text/turtle, application/rdf+xml'
        }
        req = requests.post(
            'http://*****:*****@localhost:5820/test-haris/icv/violations',
            headers=headers)

        resp = decoder.MultipartDecoder.from_response(req)
        for p in resp.parts:
            print(p.headers)
            #if "rdf+xml" in p.headers["Content-Type"]:
            #    g = Graph()
            #    g.parse(data=p.content, format=p.headers["Content-Type"])
            if "sparql-result" in p.headers["Content-Type"]:
                g = Result('SELECT')
                g = g.parse(StringIO.StringIO(
                    p.content))  # , format=p.headers["Content-Type"])
                for r in g:
                    res.append({"type": "path", "entity": r["path"]})
        return res