The class StringAdapter in module casbin.persist.adapters.string_adapter does not appear to be useable because of a missing import statement in casbin.persist.adapters.__init__.py.
Steps to reproduce:
install casbin
run python interpreter
>>> import casbin.persist as p
>>> dir(p.adapters)
['FileAdapter', 'FilteredAdapter', 'FilteredFileAdapter', 'UpdateAdapter', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'asyncio', 'file_adapter', 'filtered_file_adapter']
>>> sa = p.adapters.StringAdapter("foo")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'casbin.persist.adapters' has no attribute 'StringAdapter'
Note that there is no class StringAdapter despite the presence of the module string_adapter.py
Fix
Edit casbin.persist.adapters.__init__.py, adding the import statement for string_adapers.py and adding it to the __all__ variable
# Copyright 2021 The casbin Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .string_adapter import StringAdapter
from .file_adapter import FileAdapter
from .filtered_file_adapter import FilteredFileAdapter
from ..update_adapter import UpdateAdapter
# alias import for backwards compatibility
FilteredAdapter = FilteredFileAdapter
__all__ = ["StringAdapter", "FileAdapter", "FilteredFileAdapter", "FilteredAdapter", "UpdateAdapter"]
Now it works:
>>> import casbin.persist as p
>>> dir(p)
['Adapter', 'BatchAdapter', 'FileAdapter', 'FilteredAdapter', 'FilteredFileAdapter', 'StringAdapter', 'UpdateAdapter', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'adapter', 'adapter_filtered', 'adapters', 'batch_adapter', 'load_policy_line', 'update_adapter']
>>> sa = p.StringAdapter("foo")
>>> sa
<casbin.persist.adapters.string_adapter.StringAdapter object at 0x10266b740>
The class StringAdapter in module
casbin.persist.adapters.string_adapter
does not appear to be useable because of a missing import statement incasbin.persist.adapters.__init__.py
.Steps to reproduce:
Note that there is no class
StringAdapter
despite the presence of the modulestring_adapter.py
Fix Edit
casbin.persist.adapters.__init__.py
, adding the import statement forstring_adapers.py
and adding it to the__all__
variableNow it works: