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
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
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(list(zip(r.vars, (self.convertTerm(x) for x in row))))) return r except ParseException as err: print(err.line) print(" " * (err.column - 1) + "^") print(err)
def parse(self, source): r = Result('SELECT') 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
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
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
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
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
def parse(self, source): r = Result('SELECT') if isinstance(source.read(0), py3compat.bytestype): # 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 reader.next()] r.bindings = [] for row in reader: r.bindings.append(self.parseRow(row, r.vars)) return r