import pkg_resources


def get_dialect(self):
    """Return the SQLAlchemy database dialect class corresponding to this URL's driver name."""
    
    try:
        module = getattr(__import__('sqlalchemy.databases.%s' % self.drivername).databases, self.drivername)
        return module.dialect
    except ImportError:
        # if sys.exc_info()[2].tb_next is None:
        if True:
            for res in pkg_resources.iter_entry_points('sqlalchemy.databases'):
                if res.name == self.drivername:
                    return res.load()
        raise