Skip to content

Commit

Permalink
updated to rdflib 7.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
situx committed Feb 1, 2025
1 parent 9b30c6c commit f3c9879
Show file tree
Hide file tree
Showing 106 changed files with 5,982 additions and 2,408 deletions.
8 changes: 5 additions & 3 deletions dependencies/rdflib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
True
"""

import logging
import sys
from importlib import metadata
Expand All @@ -51,13 +52,14 @@
__docformat__ = "restructuredtext en"

__version__: str = _DISTRIBUTION_METADATA["Version"]
__date__ = "2023-08-02"
__date__ = "2025-01-18"

__all__ = [
"URIRef",
"BNode",
"IdentifiedNode",
"Literal",
"Node",
"Variable",
"Namespace",
"Dataset",
Expand Down Expand Up @@ -194,7 +196,7 @@
XSD,
Namespace,
)
from rdflib.term import BNode, IdentifiedNode, Literal, URIRef, Variable
from rdflib.term import BNode, IdentifiedNode, Literal, Node, URIRef, Variable

from rdflib import plugin, query, util # isort:skip
from rdflib.container import * # isort:skip # noqa:F401,F403
from rdflib.container import * # isort:skip # noqa: F403
2 changes: 1 addition & 1 deletion dependencies/rdflib/_type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
from typing import Literal as PyLiteral

_NamespaceSetString = PyLiteral["core", "rdflib", "none"]
_MulPathMod = PyLiteral["*", "+", "?"] # noqa: F722
_MulPathMod = PyLiteral["*", "+", "?"]
22 changes: 15 additions & 7 deletions dependencies/rdflib/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class Collection:
__doc__ = """
"""
See "Emulating container types":
https://docs.python.org/reference/datamodel.html#emulating-container-types
Expand All @@ -37,9 +37,9 @@ class Collection:
<Graph identifier=... (<class 'rdflib.graph.Graph'>)>
>>> c = Collection(g,listname)
>>> pprint([term.n3() for term in c])
[u'"1"^^<http://www.w3.org/2001/XMLSchema#integer>',
u'"2"^^<http://www.w3.org/2001/XMLSchema#integer>',
u'"3"^^<http://www.w3.org/2001/XMLSchema#integer>']
['"1"^^<http://www.w3.org/2001/XMLSchema#integer>',
'"2"^^<http://www.w3.org/2001/XMLSchema#integer>',
'"3"^^<http://www.w3.org/2001/XMLSchema#integer>']
>>> Literal(1) in c
True
Expand All @@ -49,12 +49,16 @@ class Collection:
True
>>> c.index(Literal(2)) == 1
True
The collection is immutable if ``uri`` is the empty list
(``http://www.w3.org/1999/02/22-rdf-syntax-ns#nil``).
"""

def __init__(self, graph: Graph, uri: Node, seq: List[Node] = []):
self.graph = graph
self.uri = uri or BNode()
self += seq
if seq:
self += seq

def n3(self) -> str:
"""
Expand Down Expand Up @@ -82,8 +86,7 @@ def n3(self) -> str:
"2"^^<http://www.w3.org/2001/XMLSchema#integer>
"3"^^<http://www.w3.org/2001/XMLSchema#integer> )
"""
# type error: "Node" has no attribute "n3"
return "( %s )" % (" ".join([i.n3() for i in self])) # type: ignore[attr-defined]
return "( %s )" % (" ".join([i.n3() for i in self]))

def _get_container(self, index: int) -> Optional[Node]:
"""Gets the first, rest holding node at index."""
Expand Down Expand Up @@ -233,6 +236,9 @@ def append(self, item: Node) -> Collection:
"""

end = self._end()
if end == RDF.nil:
raise ValueError("Cannot append to empty list")

if (end, RDF.first, None) in self.graph:
# append new node to the end of the linked list
node = BNode()
Expand All @@ -245,6 +251,8 @@ def append(self, item: Node) -> Collection:

def __iadd__(self, other: Iterable[Node]):
end = self._end()
if end == RDF.nil:
raise ValueError("Cannot append to empty list")
self.graph.remove((end, RDF.rest, None))

for item in other:
Expand Down
10 changes: 5 additions & 5 deletions dependencies/rdflib/compare.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
A collection of utilities for canonicalizing and inspecting graphs.
Expand Down Expand Up @@ -73,7 +72,8 @@
_:cb558f30e21ddfc05ca53108348338ade8
<http://example.org/ns#label> "B" .
"""
from __future__ import absolute_import, division, print_function

from __future__ import annotations

# TODO:
# - Doesn't handle quads.
Expand Down Expand Up @@ -252,7 +252,7 @@ def stringify(x):
self._hash_cache[color] = val
return val

def distinguish(self, W: "Color", graph: Graph):
def distinguish(self, W: Color, graph: Graph): # noqa: N803
colors: Dict[str, Color] = {}
for n in self.nodes:
new_color: Tuple[ColorItem, ...] = list(self.color) # type: ignore[assignment]
Expand Down Expand Up @@ -352,7 +352,7 @@ def _refine(self, coloring: List[Color], sequence: List[Color]) -> List[Color]:
sequence = sorted(sequence, key=lambda x: x.key(), reverse=True)
coloring = coloring[:]
while len(sequence) > 0 and not self._discrete(coloring):
W = sequence.pop()
W = sequence.pop() # noqa: N806
for c in coloring[:]:
if len(c.nodes) > 1 or isinstance(c.nodes[0], BNode):
colors = sorted(
Expand Down Expand Up @@ -522,7 +522,7 @@ def canonical_triples(self, stats: Optional[Stats] = None):

def _canonicalize_bnodes(
self,
triple: "_TripleType",
triple: _TripleType,
labels: Dict[Node, str],
):
for term in triple:
Expand Down
13 changes: 8 additions & 5 deletions dependencies/rdflib/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
and different versions of support libraries.
"""

from __future__ import annotations

import codecs
import re
import warnings
Expand All @@ -20,7 +22,8 @@ def ascii(stream):


def bopen(*args, **kwargs):
return open(*args, mode="rb", **kwargs)
# type error: No overload variant of "open" matches argument types "Tuple[Any, ...]", "str", "Dict[str, Any]"
return open(*args, mode="rb", **kwargs) # type: ignore[call-overload]


long_type = int
Expand All @@ -34,14 +37,14 @@ def sign(n):
return 0


r_unicodeEscape = re.compile(r"(\\u[0-9A-Fa-f]{4}|\\U[0-9A-Fa-f]{8})")
r_unicodeEscape = re.compile(r"(\\u[0-9A-Fa-f]{4}|\\U[0-9A-Fa-f]{8})") # noqa: N816


def _unicodeExpand(s):
def _unicodeExpand(s): # noqa: N802
return r_unicodeEscape.sub(lambda m: chr(int(m.group(0)[2:], 16)), s)


def decodeStringEscape(s):
def decodeStringEscape(s): # noqa: N802
warnings.warn(
DeprecationWarning(
"rdflib.compat.decodeStringEscape() is deprecated, "
Expand Down Expand Up @@ -92,7 +95,7 @@ def _turtle_escape_subber(match: Match[str]) -> str:
)


def decodeUnicodeEscape(escaped: str) -> str:
def decodeUnicodeEscape(escaped: str) -> str: # noqa: N802
if "\\" not in escaped:
# Most of times, there are no backslashes in strings.
return escaped
Expand Down
12 changes: 11 additions & 1 deletion dependencies/rdflib/container.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from random import randint

from rdflib.namespace import RDF
Expand Down Expand Up @@ -82,6 +83,15 @@ def __len__(self):
return self._len

def type_of_conatiner(self):
warnings.warn(
"rdflib.container.Container.type_of_conatiner is deprecated. "
"Use type_of_container method instead.",
DeprecationWarning,
stacklevel=2,
)
return self._rtype

def type_of_container(self):
return self._rtype

def index(self, item):
Expand Down Expand Up @@ -260,7 +270,7 @@ def add_at_position(self, pos, item):
return self


class NoElementException(Exception):
class NoElementException(Exception): # noqa: N818
def __init__(self, message="rdf:Alt Container is empty"):
self.message = message

Expand Down
11 changes: 6 additions & 5 deletions dependencies/rdflib/events.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from __future__ import annotations

__doc__ = """
"""
Dirt Simple Events
A Dispatcher (or a subclass of Dispatcher) stores event handlers that
Expand All @@ -25,6 +23,7 @@
<rdflib.events.Event ['data', 'foo', 'used_by']>
"""

from __future__ import annotations

from typing import Any, Dict, Optional

Expand Down Expand Up @@ -73,12 +72,14 @@ def subscribe(self, event_type, handler):
"""
if self._dispatch_map is None:
self.set_map({})
lst = self._dispatch_map.get(event_type, None)
# type error: error: Item "None" of "Optional[Dict[Any, Any]]" has no attribute "get"
lst = self._dispatch_map.get(event_type, None) # type: ignore[union-attr]
if lst is None:
lst = [handler]
else:
lst.append(handler)
self._dispatch_map[event_type] = lst
# type error: Unsupported target for indexed assignment ("Optional[Dict[Any, Any]]")
self._dispatch_map[event_type] = lst # type: ignore[index]
return self

def dispatch(self, event):
Expand Down
2 changes: 2 additions & 0 deletions dependencies/rdflib/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
TODO:
"""

from __future__ import annotations

__all__ = [
"Error",
"ParserError",
Expand Down
1 change: 0 additions & 1 deletion dependencies/rdflib/extras/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
4 changes: 4 additions & 0 deletions dependencies/rdflib/extras/cmdlineutils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from __future__ import annotations

import codecs
import getopt
import sys
import time
from typing import TextIO, Union

import rdflib
from rdflib.util import guess_format
Expand Down Expand Up @@ -40,6 +43,7 @@ def main(target, _help=_help, options="", stdin=True):
else:
f = None

out: Union[TextIO, codecs.StreamReaderWriter]
if "-o" in dargs:
sys.stderr.write("Output to %s\n" % dargs["-o"])
out = codecs.open(dargs["-o"], "w", "utf-8")
Expand Down
23 changes: 10 additions & 13 deletions dependencies/rdflib/extras/describer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__doc__ = """
"""
A Describer is a stateful utility for creating RDF statements in a
semi-declarative manner. It has methods for creating literal values, rel and
rev resource relations (somewhat resembling RDFa).
Expand All @@ -22,15 +19,15 @@
>>>
>>> class Person:
... def __init__(self):
... self.first_name = u"Some"
... self.last_name = u"Body"
... self.first_name = "Some"
... self.last_name = "Body"
... self.username = "some1"
... self.presentation = u"Just a Python & RDF hacker."
... self.presentation = "Just a Python & RDF hacker."
... self.image = "/images/persons/" + self.username + ".jpg"
... self.site = "http://example.net/"
... self.start_date = datetime.date(2009, 9, 4)
... def get_full_name(self):
... return u" ".join([self.first_name, self.last_name])
... return " ".join([self.first_name, self.last_name])
... def get_absolute_url(self):
... return "/persons/" + self.username
... def get_thumbnail_url(self):
Expand Down Expand Up @@ -133,7 +130,7 @@ def about(self, subject, **kws):
rdflib.term.BNode(...)
>>> d.about("http://example.org/")
>>> d._current()
rdflib.term.URIRef(u'http://example.org/')
rdflib.term.URIRef('http://example.org/')
"""
kws.setdefault("base", self.base)
Expand All @@ -155,7 +152,7 @@ def value(self, p, v, **kws):
>>> d = Describer(about="http://example.org/")
>>> d.value(RDFS.label, "Example")
>>> d.graph.value(URIRef('http://example.org/'), RDFS.label)
rdflib.term.Literal(u'Example')
rdflib.term.Literal('Example')
"""
v = cast_value(v, **kws)
Expand All @@ -176,15 +173,15 @@ def rel(self, p, o=None, **kws):
>>> d = Describer(about="/", base="http://example.org/")
>>> _ctxt = d.rel(RDFS.seeAlso, "/about")
>>> d.graph.value(URIRef('http://example.org/'), RDFS.seeAlso)
rdflib.term.URIRef(u'http://example.org/about')
rdflib.term.URIRef('http://example.org/about')
>>> with d.rel(RDFS.seeAlso, "/more"):
... d.value(RDFS.label, "More")
>>> (URIRef('http://example.org/'), RDFS.seeAlso,
... URIRef('http://example.org/more')) in d.graph
True
>>> d.graph.value(URIRef('http://example.org/more'), RDFS.label)
rdflib.term.Literal(u'More')
rdflib.term.Literal('More')
"""

Expand All @@ -211,7 +208,7 @@ def rev(self, p, s=None, **kws):
... URIRef('http://example.org/')) in d.graph
True
>>> d.graph.value(URIRef('http://example.net/'), RDFS.label)
rdflib.term.Literal(u'Net')
rdflib.term.Literal('Net')
"""
kws.setdefault("base", self.base)
Expand Down
Loading

0 comments on commit f3c9879

Please sign in to comment.