<commit_before>#
# This source file is part of the EdgeDB open source project.
#
# Copyright 2008-present MagicStack Inc. and the EdgeDB authors.
#
# 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.
#

"""Low level introspection of the schema."""


from edb import errors

from edb.common import topological

from edb import schema as so

from edb.schema import abc as s_abc
from edb.schema import attributes as s_attrs
from edb.schema import casts as s_casts
from edb.schema import scalars as s_scalars
from edb.schema import objtypes as s_objtypes
from edb.schema import constraints as s_constr
from edb.schema import expr as s_expr
from edb.schema import functions as s_funcs
from edb.schema import indexes as s_indexes
from edb.schema import links as s_links
from edb.schema import lproperties as s_props
from edb.schema import modules as s_mod
from edb.schema import name as sn
from edb.schema import operators as s_opers
from edb.schema import pointers as s_pointers
from edb.schema import pseudo as s_pseudo
from edb.schema import types as s_types

from edb.pgsql import common
from edb.pgsql import dbops

from . import datasources
from .datasources import introspection

from . import schemamech
from . import types


class IntrospectionMech:

    def __init__(self, connection):
        self._constr_mech = schemamech.ConstraintMech()

        self._operator_commutators = {}

        self.connection = connection

    async def readschema(self, *, schema=None, modules=None,
                         exclude_modules=None):
        if schema is None:
            schema = so.Schema()

        async with self.connection.transaction():
            schema = await self.read_modules(
                schema, only_modules=modules, exclude_modules=exclude_modules)
            schema = await self.read_scalars(
                schema, only_modules=modules, exclude_modules=exclude_modules)
            schema = await self.read_attributes(
                schema, only_modules=modules, exclude_modules=exclude_modules)
            schema = await self.read_objtypes(
                schema, only_modules=modules, exclude_modules=exclude_modules)
            schema = await self.read_casts(
                schema, only_modules=modules, exclude_modules=exclude_modules)
            schema = await self.read_links(
                schema, only_modules=modules, exclude_modules=exclude_modules)
            schema = await self.read_link_properties(
                schema, only_modules=modules, exclude_modules=exclude_modules)
            schema = await self.read_operators(
                schema, only_modules=modules, exclude_modules=exclude_modules)
            schema = await self.read_functions(
                schema, only_modules=modules, exclude_modules=exclude_modules)
            schema = await self.read_constraints(
                schema, only_modules=modules, exclude_modules=exclude_modules)<commit_msg>Use REPEATABLE READ isolation level in intromech<commit_after>#
# This source file is part of the EdgeDB open source project.
#
# Copyright 2008-present MagicStack Inc. and the EdgeDB authors.
#
# 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.
#

"""Low level introspection of the schema."""


from edb import errors

from edb.common import topological

from edb import schema as so

from edb.schema import abc as s_abc
from edb.schema import attributes as s_attrs
from edb.schema import casts as s_casts
from edb.schema import scalars as s_scalars
from edb.schema import objtypes as s_objtypes
from edb.schema import constraints as s_constr
from edb.schema import expr as s_expr
from edb.schema import functions as s_funcs
from edb.schema import indexes as s_indexes
from edb.schema import links as s_links
from edb.schema import lproperties as s_props
from edb.schema import modules as s_mod
from edb.schema import name as sn
from edb.schema import operators as s_opers
from edb.schema import pointers as s_pointers
from edb.schema import pseudo as s_pseudo
from edb.schema import types as s_types

from edb.pgsql import common
from edb.pgsql import dbops

from . import datasources
from .datasources import introspection

from . import schemamech
from . import types


class IntrospectionMech:

    def __init__(self, connection):
        self._constr_mech = schemamech.ConstraintMech()

        self._operator_commutators = {}

        self.connection = connection

    async def readschema(self, *, schema=None, modules=None,
                         exclude_modules=None):
        if schema is None:
            schema = so.Schema()

        async with self.connection.transaction(isolation='repeatable_read'):
            schema = await self.read_modules(
                schema, only_modules=modules, exclude_modules=exclude_modules)
            schema = await self.read_scalars(
                schema, only_modules=modules, exclude_modules=exclude_modules)
            schema = await self.read_attributes(
                schema, only_modules=modules, exclude_modules=exclude_modules)
            schema = await self.read_objtypes(
                schema, only_modules=modules, exclude_modules=exclude_modules)
            schema = await self.read_casts(
                schema, only_modules=modules, exclude_modules=exclude_modules)
            schema = await self.read_links(
                schema, only_modules=modules, exclude_modules=exclude_modules)
            schema = await self.read_link_properties(
                schema, only_modules=modules, exclude_modules=exclude_modules)
            schema = await self.read_operators(
                schema, only_modules=modules, exclude_modules=exclude_modules)
            schema = await self.read_functions(
                schema, only_modules=modules, exclude_modules=exclude_modules)
            schema = await self.read_constraints(
                schema, only_modules=modules, exclude_modules=exclude_modules)
{'fraction_non_alphanumeric': 0.05731282646546721, 'fraction_numerical': 0.0023215322112594312, 'mean_word_length': 3.273403595784253, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7423528', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1778, 'n_words': 657}