Skip to content

Commit

Permalink
Merge pull request #1051 from RDFLib/kill-Py2
Browse files Browse the repository at this point in the history
Removal of six & styling
  • Loading branch information
nicholascar authored May 24, 2020
2 parents 231bc6d + b72bf07 commit 9103720
Show file tree
Hide file tree
Showing 188 changed files with 7,455 additions and 6,020 deletions.
17 changes: 10 additions & 7 deletions docs/plugintable.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,24 @@
p = {}

for (name, kind), plugin in _plugins.items():
if "/" in name: continue # skip duplicate entries for mimetypes
if "/" in name:
continue # skip duplicate entries for mimetypes
if cls == kind.__name__:
p[name]="%s.%s"%(plugin.module_path, plugin.class_name)
p[name] = "%s.%s" % (plugin.module_path, plugin.class_name)

l1 = max(len(x) for x in p)
l2 = max(10 + len(x) for x in p.values())

l1=max(len(x) for x in p)
l2=max(10+len(x) for x in p.values())

def hr():
print("="*l1,"="*l2)
print("=" * l1, "=" * l2)


hr()
print("%-*s"%(l1,"Name"), "%-*s"%(l2, "Class"))
print("%-*s" % (l1, "Name"), "%-*s" % (l2, "Class"))
hr()

for n in sorted(p):
print("%-*s"%(l1,n), ":class:`~%s`"%p[n])
print("%-*s" % (l1, n), ":class:`~%s`" % p[n])
hr()
print()
2 changes: 1 addition & 1 deletion examples/conjunctive_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

# query the conjunction of all graphs
xx = None
for x in g[mary: ns.loves / ns.hasCuteName]:
for x in g[mary : ns.loves / ns.hasCuteName]:
xx = x
print("Q: Who does Mary love?")
print("A: Mary loves {}".format(xx))
1 change: 0 additions & 1 deletion examples/film.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

from rdflib import BNode, ConjunctiveGraph, URIRef, Literal, Namespace, RDF
from rdflib.namespace import FOAF, DC
from six.moves import input

storefn = os.path.expanduser("~/movies.n3")
# storefn = '/home/simon/codes/film.dev/movies.n3'
Expand Down
4 changes: 2 additions & 2 deletions examples/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

graph.load("foaf.n3", format="n3")

for person in graph[: RDF.type: FOAF.Person]:
for person in graph[: RDF.type : FOAF.Person]:

friends = list(graph[person: FOAF.knows * "+" / FOAF.name])
friends = list(graph[person : FOAF.knows * "+" / FOAF.name])
if friends:
print("%s's circle of friends:" % graph.value(person, FOAF.name))
for name in friends:
Expand Down
19 changes: 12 additions & 7 deletions examples/sparqlstore_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@
graph = Graph("SPARQLStore", identifier="http://dbpedia.org")
graph.open("http://dbpedia.org/sparql")

pop = graph.value(
URIRef("http://dbpedia.org/resource/Berlin"),
dbo.populationTotal)
pop = graph.value(URIRef("http://dbpedia.org/resource/Berlin"), dbo.populationTotal)

print("According to DBPedia, Berlin has a population of {0:,}".format(int(pop), ',d').replace(",", "."))
print(
"According to DBPedia, Berlin has a population of {0:,}".format(
int(pop), ",d"
).replace(",", ".")
)

# using a SPARQLStore object directly
s = SPARQLStore(endpoint="http://dbpedia.org/sparql")
s.open(None)
pop = graph.value(
URIRef("http://dbpedia.org/resource/Brisbane"),
dbo.populationTotal)
print("According to DBPedia, Brisbane has a population of " "{0:,}".format(int(pop), ',d'))
URIRef("http://dbpedia.org/resource/Brisbane"), dbo.populationTotal
)
print(
"According to DBPedia, Brisbane has a population of "
"{0:,}".format(int(pop), ",d")
)
2 changes: 1 addition & 1 deletion examples/swap_primer.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
# dataset from the example, and start
# with a fresh new graph.

del(primer)
del primer
primer = ConjunctiveGraph()

# Lets start with a verbatim string straight from the primer text:
Expand Down
24 changes: 1 addition & 23 deletions rdflib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,14 @@

import sys

assert sys.version_info >= (2, 7, 0), "rdflib requires Python 2.7 or higher"

import logging

logger = logging.getLogger(__name__)
_interactive_mode = False
try:
import __main__

if not hasattr(__main__, "__file__") and sys.stdout != None and sys.stderr.isatty():
if not hasattr(__main__, "__file__") and sys.stdout is not None and sys.stderr.isatty():
# show log messages in interactive mode
_interactive_mode = True
logger.setLevel(logging.INFO)
Expand All @@ -115,26 +113,6 @@
del sys


import six

try:
six.unichr(0x10FFFF)
except ValueError:
import warnings

warnings.warn(
"You are using a narrow Python build!\n"
"This means that your Python does not properly support chars > 16bit.\n"
'On your system chars like c=u"\\U0010FFFF" will have a len(c)==2.\n'
"As this can cause hard to debug problems with string processing\n"
"(slicing, regexp, ...) later on, we strongly advise to use a wide\n"
"Python build in production systems.",
ImportWarning,
)
del warnings
del six


NORMALIZE_LITERALS = True
"""
If True - Literals lexical forms are normalized when created.
Expand Down
14 changes: 7 additions & 7 deletions rdflib/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from rdflib.term import Literal


__all__ = ['Collection']
__all__ = ["Collection"]


class Collection(object):
Expand Down Expand Up @@ -67,7 +67,7 @@ def n3(self):
"2"^^<http://www.w3.org/2001/XMLSchema#integer>
"3"^^<http://www.w3.org/2001/XMLSchema#integer> )
"""
return "( %s )" % (' '.join([i.n3() for i in self]))
return "( %s )" % (" ".join([i.n3() for i in self]))

def _get_container(self, index):
"""Gets the first, rest holding node at index."""
Expand Down Expand Up @@ -103,8 +103,7 @@ def index(self, item):
elif not newLink:
raise Exception("Malformed RDF Collection: %s" % self.uri)
else:
assert len(newLink) == 1, \
"Malformed RDF Collection: %s" % self.uri
assert len(newLink) == 1, "Malformed RDF Collection: %s" % self.uri
listName = newLink[0]

def __getitem__(self, key):
Expand Down Expand Up @@ -246,21 +245,22 @@ def clear(self):

def test():
import doctest

doctest.testmod()


if __name__ == "__main__":
test()

from rdflib import Graph

g = Graph()

c = Collection(g, BNode())

assert len(c) == 0

c = Collection(
g, BNode(), [Literal("1"), Literal("2"), Literal("3"), Literal("4")])
c = Collection(g, BNode(), [Literal("1"), Literal("2"), Literal("3"), Literal("4")])

assert len(c) == 4

Expand All @@ -272,7 +272,7 @@ def test():

try:
del c[500]
except IndexError as i:
except IndexError:
pass

c.append(Literal("5"))
Expand Down
Loading

0 comments on commit 9103720

Please sign in to comment.