1# dialects/__init__.py 
    2# Copyright (C) 2005-2024 the SQLAlchemy authors and contributors 
    3# <see AUTHORS file> 
    4# 
    5# This module is part of SQLAlchemy and is released under 
    6# the MIT License: https://www.opensource.org/licenses/mit-license.php 
    7 
    8from __future__ import annotations 
    9 
    10from typing import Callable 
    11from typing import Optional 
    12from typing import Type 
    13from typing import TYPE_CHECKING 
    14 
    15from .. import util 
    16 
    17if TYPE_CHECKING: 
    18    from ..engine.interfaces import Dialect 
    19 
    20__all__ = ("mssql", "mysql", "oracle", "postgresql", "sqlite") 
    21 
    22 
    23def _auto_fn(name: str) -> Optional[Callable[[], Type[Dialect]]]: 
    24    """default dialect importer. 
    25 
    26    plugs into the :class:`.PluginLoader` 
    27    as a first-hit system. 
    28 
    29    """ 
    30    if "." in name: 
    31        dialect, driver = name.split(".") 
    32    else: 
    33        dialect = name 
    34        driver = "base" 
    35 
    36    try: 
    37        if dialect == "mariadb": 
    38            # it's "OK" for us to hardcode here since _auto_fn is already 
    39            # hardcoded.   if mysql / mariadb etc were third party dialects 
    40            # they would just publish all the entrypoints, which would actually 
    41            # look much nicer. 
    42            module = __import__( 
    43                "sqlalchemy.dialects.mysql.mariadb" 
    44            ).dialects.mysql.mariadb 
    45            return module.loader(driver)  # type: ignore 
    46        else: 
    47            module = __import__("sqlalchemy.dialects.%s" % (dialect,)).dialects 
    48            module = getattr(module, dialect) 
    49    except ImportError: 
    50        return None 
    51 
    52    if hasattr(module, driver): 
    53        module = getattr(module, driver) 
    54        return lambda: module.dialect 
    55    else: 
    56        return None 
    57 
    58 
    59registry = util.PluginLoader("sqlalchemy.dialects", auto_fn=_auto_fn) 
    60 
    61plugins = util.PluginLoader("sqlalchemy.plugins")