diff options
| author | Gunnar Aastrand Grimnes <gromgull@gmail.com> | 2016-11-19 10:19:57 +0100 |
|---|---|---|
| committer | Gunnar Aastrand Grimnes <gromgull@gmail.com> | 2017-01-30 17:43:04 +0100 |
| commit | afd3fb478fa7a7b303c6b6bb4d23ff632ce776dc (patch) | |
| tree | 5d760577764cea7ed2cc2e03823cc5e1ee03520d | |
| parent | 8798f1bb9b181cabea6fd65e7e7d82aa0c1a7fdd (diff) | |
| download | rdflib-afd3fb478fa7a7b303c6b6bb4d23ff632ce776dc.tar.gz | |
converted stores
| -rw-r--r-- | rdflib/plugins/stores/auditable.py | 3 | ||||
| -rw-r--r-- | rdflib/plugins/stores/concurrent.py | 6 | ||||
| -rw-r--r-- | rdflib/plugins/stores/regexmatching.py | 7 | ||||
| -rw-r--r-- | rdflib/plugins/stores/sparqlstore.py | 38 | ||||
| -rw-r--r-- | setup.py | 6 |
5 files changed, 34 insertions, 26 deletions
diff --git a/rdflib/plugins/stores/auditable.py b/rdflib/plugins/stores/auditable.py index cf975044..61893d27 100644 --- a/rdflib/plugins/stores/auditable.py +++ b/rdflib/plugins/stores/auditable.py @@ -64,7 +64,8 @@ class AuditableStore(Store): pass self.store.add((s, p, o), context, quoted) - def remove(self, (subject, predicate, object_), context=None): + def remove(self, spo, context=None): + subject, predicate, object_ = spo lock = destructiveOpLocks['remove'] lock = lock if lock else threading.RLock() with lock: diff --git a/rdflib/plugins/stores/concurrent.py b/rdflib/plugins/stores/concurrent.py index 1ab3a82d..40747fb1 100644 --- a/rdflib/plugins/stores/concurrent.py +++ b/rdflib/plugins/stores/concurrent.py @@ -16,8 +16,8 @@ class ResponsibleGenerator(object): def __iter__(self): return self - def next(self): - return self.gen.next() + def __next__(self): + return next(self.gen) class ConcurrentStore(object): @@ -86,7 +86,7 @@ class ConcurrentStore(object): self.store.remove((s, p, o)) except: # TODO: change to try finally? - print s, p, o, "Not in store to remove" + print(s, p, o, "Not in store to remove") pending_adds = self.__pending_adds while pending_adds: (s, p, o) = pending_adds.pop() diff --git a/rdflib/plugins/stores/regexmatching.py b/rdflib/plugins/stores/regexmatching.py index c2dcfd0d..3f186a12 100644 --- a/rdflib/plugins/stores/regexmatching.py +++ b/rdflib/plugins/stores/regexmatching.py @@ -10,6 +10,9 @@ matching against the results from the store it's wrapping. from rdflib.store import Store from rdflib.graph import Graph + +from rdflib.py3compat import text_type + import re # Store is capable of doing its own REGEX matching @@ -18,7 +21,7 @@ NATIVE_REGEX = 0 PYTHON_REGEX = 1 -class REGEXTerm(unicode): +class REGEXTerm(text_type): """ REGEXTerm can be used in any term slot and is interpreted as a request to perform a REGEX match (not a string comparison) using the value @@ -28,7 +31,7 @@ class REGEXTerm(unicode): self.compiledExpr = re.compile(expr) def __reduce__(self): - return (REGEXTerm, (unicode(''),)) + return (REGEXTerm, (text_type(''),)) def regexCompareQuad(quad, regexQuad): diff --git a/rdflib/plugins/stores/sparqlstore.py b/rdflib/plugins/stores/sparqlstore.py index b0eeb8c1..0f6731a8 100644 --- a/rdflib/plugins/stores/sparqlstore.py +++ b/rdflib/plugins/stores/sparqlstore.py @@ -32,6 +32,8 @@ from rdflib import Variable, Namespace, BNode, URIRef, Literal from rdflib.graph import DATASET_DEFAULT_GRAPH_ID from rdflib.term import Node +from rdflib.py3compat import text_type, string_types + class NSSPARQLWrapper(SPARQLWrapper): nsBindings = {} @@ -60,7 +62,7 @@ class NSSPARQLWrapper(SPARQLWrapper): self.queryString = self.injectPrefixes(query) def injectPrefixes(self, query): - prefixes = self.nsBindings.items() + prefixes = list(self.nsBindings.items()) if not prefixes: return query return '\n'.join([ @@ -239,13 +241,13 @@ class SPARQLStore(NSSPARQLWrapper, Store): def rollback(self): raise TypeError('The SPARQL store is read only') - def add(self, (subject, predicate, obj), context=None, quoted=False): + def add(self, _, context=None, quoted=False): raise TypeError('The SPARQL store is read only') def addN(self, quads): raise TypeError('The SPARQL store is read only') - def remove(self, (subject, predicate, obj), context): + def remove(self, _, context): raise TypeError('The SPARQL store is read only') def query(self, query, @@ -254,7 +256,7 @@ class SPARQLStore(NSSPARQLWrapper, Store): queryGraph=None, DEBUG=False): self.debug = DEBUG - assert isinstance(query, basestring) + assert isinstance(query, string_types) self.setNamespaceBindings(initNs) if initBindings: if not self.sparql11: @@ -278,7 +280,7 @@ class SPARQLStore(NSSPARQLWrapper, Store): return Result.parse(res) - def triples(self, (s, p, o), context=None): + def triples(self, spo, context=None): """ - tuple **(s, o, p)** the triple used as filter for the SPARQL select. @@ -314,6 +316,8 @@ class SPARQLStore(NSSPARQLWrapper, Store): `` """ + s, p, o = spo + vars = [] if not s: s = Variable('s') @@ -376,7 +380,7 @@ class SPARQLStore(NSSPARQLWrapper, Store): rt.get(p, p), rt.get(o, o)), None - def triples_choices(self, (subject, predicate, object_), context=None): + def triples_choices(self, _, context=None): """ A variant of triples that can take a list of terms instead of a single term in any slot. Stores can implement this to optimize @@ -401,13 +405,13 @@ class SPARQLStore(NSSPARQLWrapper, Store): with contextlib.closing(SPARQLWrapper.query(self).response) as res: doc = etree.parse(res) - rt, vars = iter( + rt, vars = next(iter( _traverse_sparql_result_dom( doc, as_dictionary=True, node_from_result=self.node_from_result ) - ).next() + )) return int(rt.get(Variable("c"))) def contexts(self, triple=None): @@ -474,7 +478,7 @@ class SPARQLStore(NSSPARQLWrapper, Store): """ if (not self.context_aware) or (graph is None): return False - if isinstance(graph, basestring): + if isinstance(graph, string_types): return graph != '__UNION__' else: return graph.identifier != DATASET_DEFAULT_GRAPH_ID @@ -520,18 +524,18 @@ class SPARQLUpdateStore(SPARQLStore): # in order to avoid unbalanced curly braces. # From the SPARQL grammar - STRING_LITERAL1 = ur"'([^'\\]|\\.)*'" - STRING_LITERAL2 = ur'"([^"\\]|\\.)*"' - STRING_LITERAL_LONG1 = ur"'''(('|'')?([^'\\]|\\.))*'''" - STRING_LITERAL_LONG2 = ur'"""(("|"")?([^"\\]|\\.))*"""' + STRING_LITERAL1 = u"'([^'\\\\]|\\\\.)*'" + STRING_LITERAL2 = u'"([^"\\\\]|\\\\.)*"' + STRING_LITERAL_LONG1 = u"'''(('|'')?([^'\\\\]|\\\\.))*'''" + STRING_LITERAL_LONG2 = u'"""(("|"")?([^"\\\\]|\\\\.))*"""' String = u'(%s)|(%s)|(%s)|(%s)' % (STRING_LITERAL1, STRING_LITERAL2, STRING_LITERAL_LONG1, STRING_LITERAL_LONG2) - IRIREF = ur'<([^<>"{}|^`\]\\\[\x00-\x20])*>' - COMMENT = ur'#[^\x0D\x0A]*([\x0D\x0A]|\Z)' + IRIREF = u'<([^<>"{}|^`\\]\\\\\[\\x00-\\x20])*>' + COMMENT = u'#[^\\x0D\\x0A]*([\\x0D\\x0A]|\\Z)' # Simplified grammar to find { at beginning and } at end of blocks BLOCK_START = u'{' BLOCK_END = u'}' - ESCAPED = ur'\\.' + ESCAPED = u'\\\\.' # Match anything that doesn't start or end a block: BlockContent = u'(%s)|(%s)|(%s)|(%s)' % (String, IRIREF, COMMENT, ESCAPED) @@ -765,7 +769,7 @@ class SPARQLUpdateStore(SPARQLStore): raise Exception("UpdateEndpoint is not set - call 'open'") self.debug = DEBUG - assert isinstance(query, basestring) + assert isinstance(query, string_types) self.setNamespaceBindings(initNs) query = self.injectPrefixes(query) @@ -134,9 +134,9 @@ def setup_python3(): join(tmp_src, 'rdflib', 'plugins', 'sparql', 'sparql.py'), join(tmp_src, 'rdflib', 'plugins', 'sparql', 'update.py'), join(tmp_src, 'rdflib', 'plugins', 'stores', '__init__.py'), - # join(tmp_src, 'rdflib', 'plugins', 'stores', 'auditable.py'), - # join(tmp_src, 'rdflib', 'plugins', 'stores', 'concurrent.py'), - # join(tmp_src, 'rdflib', 'plugins', 'stores', 'regexmatching.py'), + join(tmp_src, 'rdflib', 'plugins', 'stores', 'auditable.py'), + join(tmp_src, 'rdflib', 'plugins', 'stores', 'concurrent.py'), + join(tmp_src, 'rdflib', 'plugins', 'stores', 'regexmatching.py'), # join(tmp_src, 'rdflib', 'plugins', 'stores', 'sparqlstore.py'), join(tmp_src, 'rdflib', 'py3compat.py'), join(tmp_src, 'rdflib', 'query.py'), |
