Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions rdflib/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,9 @@ def rollback(self: _GraphT) -> _GraphT:
self.__store.rollback()
return self

def open(self, configuration: str, create: bool = False) -> Optional[int]:
def open(
self, configuration: Union[str, tuple[str, str]], create: bool = False
) -> Optional[int]:
"""Open the graph store

Might be necessary for stores that require opening a connection to a
Expand Down Expand Up @@ -2824,7 +2826,7 @@ def commit(self) -> NoReturn:
def rollback(self) -> NoReturn:
raise ModificationException()

def open(self, configuration: str, create: bool = False) -> None:
def open(self, configuration: str | tuple[str, str], create: bool = False) -> None:
# TODO: is there a use case for this method?
for graph in self.graphs:
# type error: Too many arguments for "open" of "Graph"
Expand Down
6 changes: 4 additions & 2 deletions rdflib/plugins/stores/auditable.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from __future__ import annotations

import threading
from typing import TYPE_CHECKING, Any, Generator, Iterator, List, Optional, Tuple
from typing import TYPE_CHECKING, Any, Generator, Iterator, List, Optional, Tuple, Union

from rdflib.graph import ConjunctiveGraph, Graph
from rdflib.store import Store
Expand Down Expand Up @@ -62,7 +62,9 @@ def __init__(self, store: Store):
] = []
self.rollbackLock = threading.RLock()

def open(self, configuration: str, create: bool = True) -> Optional[int]:
def open(
self, configuration: Union[str, tuple[str, str]], create: bool = True
) -> Optional[int]:
return self.store.open(configuration, create)

def close(self, commit_pending_transaction: bool = False) -> None:
Expand Down
22 changes: 19 additions & 3 deletions rdflib/plugins/stores/berkeleydb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@
from os import mkdir
from os.path import abspath, exists
from threading import Thread
from typing import TYPE_CHECKING, Any, Callable, Dict, Generator, List, Optional, Tuple
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
Generator,
List,
Optional,
Tuple,
Union,
)
from urllib.request import pathname2url

from rdflib.store import NO_STORE, VALID_STORE, Store
Expand Down Expand Up @@ -127,10 +137,16 @@ def _init_db_environment(
def is_open(self) -> bool:
return self.__open

def open(self, path: str, create: bool = True) -> Optional[int]:
def open(
self, configuration: Union[str, tuple[str, str]], create: bool = True
) -> Optional[int]:
if not has_bsddb:
return NO_STORE
homeDir = path # noqa: N806

if type(configuration) is str:
homeDir = configuration # noqa: N806
else:
raise Exception("Invalid configuration provided")

if self.__identifier is None:
self.__identifier = URIRef(pathname2url(abspath(homeDir)))
Expand Down
4 changes: 2 additions & 2 deletions rdflib/plugins/stores/sparqlstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ def __init__(
self._queries = 0

# type error: Missing return statement
def open(self, configuration: str, create: bool = False) -> Optional[int]: # type: ignore[return]
def open(self, configuration: Union[str, tuple[str, str]], create: bool = False) -> Optional[int]: # type: ignore[return]
"""This method is included so that calls to this Store via Graph, e.g. Graph("SPARQLStore"),
can set the required parameters
"""
if type(configuration) == str: # noqa: E721
if type(configuration) is str:
self.query_endpoint = configuration
else:
raise Exception(
Expand Down
7 changes: 4 additions & 3 deletions rdflib/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,10 @@ def node_pickler(self) -> NodePickler:
def create(self, configuration: str) -> None:
self.dispatcher.dispatch(StoreCreatedEvent(configuration=configuration))

def open(self, configuration: str, create: bool = False) -> Optional[int]:
"""
Opens the store specified by the configuration string. If
def open(
self, configuration: Union[str, tuple[str, str]], create: bool = False
) -> Optional[int]:
"""Opens the store specified by the configuration string or tuple. If
create is True a store will be created if it does not already
exist. If create is False and a store does not already exist
an exception is raised. An exception is also raised if a store
Expand Down
Loading