<commit_before>"""
A simple storage interface for simulation objects and data objects.

Reserved words
--------------

Table names:

* ``uuid``
* ``tables``
* ``metadata``

Column names:

* ``uuid``
* ``idx``
"""

import logging
import collections
from collections import abc
import itertools

from . import tools
from .serialization_helpers import get_uuid, get_all_uuids
from .serialization_helpers import get_all_uuids_loading
from .serialization_helpers import get_reload_order
# from .serialization import Serialization
from .serialization import ProxyObjectFactory
from .storable_functions import StorageFunctionHandler, StorableFunction

try:
    basestring
except NameError:
    basestring = str

logger = logging.getLogger(__name__)

# these two tables are required in *all* schema
universal_schema = {
    'uuid': [('uuid', 'uuid'), ('table', 'int'), ('row', 'int')],
    'tables': [('name', 'str'), ('idx', 'int'), ('module', 'str'),
               ('class_name', 'str')]
}

from openpathsampling.netcdfplus import StorableNamedObject
class GeneralStorage(StorableNamedObject):
    _known_storages = {}
    def __init__(self, backend, class_info, schema=None,
                 simulation_classes=None, fallbacks=None, safemode=False):
        super().__init__()
        GeneralStorage._known_storages = {backend.identifier: self}
        self.backend = backend
        self.schema = schema.copy()
        self.class_info = class_info.copy()
        self._safemode = None
        self.safemode = safemode
        self._sf_handler = StorageFunctionHandler(storage=self)
        # TODO: implement fallback
        self.fallbacks = tools.none_to_default(fallbacks, [])

        self.simulation_classes = tools.none_to_default(simulation_classes,
                                                        {})

        # self._pseudo_tables = {table_name: dict()
                               # for table_name in self.simulation_classes}
        self._simulation_objects = {}
        self._pseudo_tables = {table_name: PseudoTable()
                               for table_name in self.simulation_classes}
        self._pseudo_tables['misc_simulation'] = PseudoTable()

        self._storage_tables = {}  # stores .steps, .snapshots
        # self.serialization = Serialization(self)
        self.proxy_factory = ProxyObjectFactory(self, self.class_info)
        self.cache = MixedCache()
        if self.schema is None:
            self.schema = backend.schema<commit_msg>Fix a potential bug in saving storage identifiers<commit_after>"""
A simple storage interface for simulation objects and data objects.

Reserved words
--------------

Table names:

* ``uuid``
* ``tables``
* ``metadata``

Column names:

* ``uuid``
* ``idx``
"""

import logging
import collections
from collections import abc
import itertools

from . import tools
from .serialization_helpers import get_uuid, get_all_uuids
from .serialization_helpers import get_all_uuids_loading
from .serialization_helpers import get_reload_order
# from .serialization import Serialization
from .serialization import ProxyObjectFactory
from .storable_functions import StorageFunctionHandler, StorableFunction

try:
    basestring
except NameError:
    basestring = str

logger = logging.getLogger(__name__)

# these two tables are required in *all* schema
universal_schema = {
    'uuid': [('uuid', 'uuid'), ('table', 'int'), ('row', 'int')],
    'tables': [('name', 'str'), ('idx', 'int'), ('module', 'str'),
               ('class_name', 'str')]
}

from openpathsampling.netcdfplus import StorableNamedObject
class GeneralStorage(StorableNamedObject):
    _known_storages = {}
    def __init__(self, backend, class_info, schema=None,
                 simulation_classes=None, fallbacks=None, safemode=False):
        super().__init__()
        GeneralStorage._known_storages[backend.identifier] = self
        self.backend = backend
        self.schema = schema.copy()
        self.class_info = class_info.copy()
        self._safemode = None
        self.safemode = safemode
        self._sf_handler = StorageFunctionHandler(storage=self)
        # TODO: implement fallback
        self.fallbacks = tools.none_to_default(fallbacks, [])

        self.simulation_classes = tools.none_to_default(simulation_classes,
                                                        {})

        # self._pseudo_tables = {table_name: dict()
                               # for table_name in self.simulation_classes}
        self._simulation_objects = {}
        self._pseudo_tables = {table_name: PseudoTable()
                               for table_name in self.simulation_classes}
        self._pseudo_tables['misc_simulation'] = PseudoTable()

        self._storage_tables = {}  # stores .steps, .snapshots
        # self.serialization = Serialization(self)
        self.proxy_factory = ProxyObjectFactory(self, self.class_info)
        self.cache = MixedCache()
        if self.schema is None:
            self.schema = backend.schema
{'fraction_non_alphanumeric': 0.10681362725450902, 'fraction_numerical': 0.0, 'mean_word_length': 2.9705648369132858, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5823946', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1374, 'n_words': 337}