Here are the examples of the python api sqlalchemy.engine.url.make_url taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
185 Examples
3
Source : hive_table_metadata_extractor.py
with Apache License 2.0
from amundsen-io
with Apache License 2.0
from amundsen-io
def _choose_default_sql_stm(self, conf: ConfigTree) -> str:
url = make_url(conf.get_string(SQLAlchemyExtractor.CONN_STRING))
if url.drivername.lower() in ['postgresql', 'postgres']:
return self.DEFAULT_POSTGRES_SQL_STATEMENT
else:
return self.DEFAULT_SQL_STATEMENT
def extract(self) -> Union[TableMetadata, None]:
3
Source : hive_table_metadata_extractor.py
with Apache License 2.0
from amundsen-io
with Apache License 2.0
from amundsen-io
def _choose_default_sql_stm(self, conf: ConfigTree) -> str:
url = make_url(conf.get_string(SQLAlchemyExtractor.CONN_STRING))
if url.drivername.lower() in ['postgresql', 'postgres']:
return HiveTableMetadataExtractor.DEFAULT_POSTGRES_SQL_STATEMENT
else:
return HiveTableMetadataExtractor.DEFAULT_SQL_STATEMENT
def extract(self) -> Union[TableMetadata, None]:
3
Source : strategies.py
with MIT License
from analyzeDFIR
with MIT License
from analyzeDFIR
def create(self, name_or_url, executor, **kwargs):
# create url.URL object
u = url.make_url(name_or_url)
dialect_cls = u.get_dialect()
dialect_args = {}
# consume dialect arguments from kwargs
for k in util.get_cls_kwargs(dialect_cls):
if k in kwargs:
dialect_args[k] = kwargs.pop(k)
# create dialect
dialect = dialect_cls(**dialect_args)
return MockEngineStrategy.MockConnection(dialect, executor)
class MockConnection(base.Connectable):
3
Source : provision.py
with MIT License
from analyzeDFIR
with MIT License
from analyzeDFIR
def __call__(self, cfg, *arg):
if isinstance(cfg, compat.string_types):
url = sa_url.make_url(cfg)
elif isinstance(cfg, sa_url.URL):
url = cfg
else:
url = cfg.db.url
backend = url.get_backend_name()
if backend in self.fns:
return self.fns[backend](cfg, *arg)
else:
return self.fns['*'](cfg, *arg)
def create_follower_db(follower_ident):
3
Source : provision.py
with MIT License
from analyzeDFIR
with MIT License
from analyzeDFIR
def _follower_url_from_main(url, ident):
url = sa_url.make_url(url)
url.database = ident
return url
@_update_db_opts.for_db("mssql")
3
Source : provision.py
with MIT License
from analyzeDFIR
with MIT License
from analyzeDFIR
def _sqlite_follower_url_from_main(url, ident):
url = sa_url.make_url(url)
if not url.database or url.database == ':memory:':
return url
else:
return sa_url.make_url("sqlite:///%s.db" % ident)
@_post_configure_engine.for_db("sqlite")
3
Source : provision.py
with MIT License
from analyzeDFIR
with MIT License
from analyzeDFIR
def _oracle_follower_url_from_main(url, ident):
url = sa_url.make_url(url)
url.username = ident
url.password = 'xe'
return url
@_create_db.for_db("mssql")
3
Source : test_dialect.py
with MIT License
from betodealmeida
with MIT License
from betodealmeida
def test_create_connect_args(self):
dialect = GSheetsDialect()
url = make_url('gsheets://')
args = dialect.create_connect_args(url)
self.assertEqual(args, ([None], {}))
self.assertIsNone(dialect.url)
url = make_url('gsheets://docs.google.com/')
args = dialect.create_connect_args(url)
self.assertEqual(args, ([None], {}))
self.assertEqual(
dialect.url, '{0}://docs.google.com/'.format(dialect.scheme))
def test_get_schema_names(self):
3
Source : test_dialect.py
with MIT License
from betodealmeida
with MIT License
from betodealmeida
def test_get_schema_names(self):
connection = Mock()
connection.execute = Mock()
result = Mock()
result.fetchall = Mock()
result.fetchall.return_value = [('default', 2), ('public', 4)]
connection.execute.return_value = result
dialect = GSheetsDialect()
url = make_url('gsheets://docs.google.com/')
dialect.create_connect_args(url)
result = dialect.get_schema_names(connection)
expected = ['default', 'public']
self.assertEqual(result, expected)
def test_get_schema_names_no_catalog(self):
3
Source : test_dialect.py
with MIT License
from betodealmeida
with MIT License
from betodealmeida
def test_get_schema_names_no_catalog(self):
connection = connect()
dialect = GSheetsDialect()
url = make_url('gsheets://')
dialect.create_connect_args(url)
result = dialect.get_schema_names(connection)
expected = []
self.assertEqual(result, expected)
def test_get_table_names(self):
3
Source : test_dialect.py
with MIT License
from betodealmeida
with MIT License
from betodealmeida
def test_get_table_names_no_catalog(self):
connection = connect()
dialect = GSheetsDialect()
url = make_url('gsheets://')
dialect.create_connect_args(url)
result = dialect.get_table_names(connection)
expected = []
self.assertEqual(result, expected)
def test_has_table(self):
3
Source : test_dialect.py
with MIT License
from betodealmeida
with MIT License
from betodealmeida
def test_has_table_no_catalog(self):
connection = connect()
dialect = GSheetsDialect()
url = make_url('gsheets://')
dialect.create_connect_args(url)
self.assertTrue(dialect.has_table(connection, 'ANY TABLE'))
def test_get_columns(self):
3
Source : provision.py
with MIT License
from bkerler
with MIT License
from bkerler
def __call__(self, cfg, *arg):
if isinstance(cfg, compat.string_types):
url = sa_url.make_url(cfg)
elif isinstance(cfg, sa_url.URL):
url = cfg
else:
url = cfg.db.url
backend = get_url_backend_name(url)
if backend in self.fns:
return self.fns[backend](cfg, *arg)
else:
return self.fns['*'](cfg, *arg)
def create_follower_db(follower_ident):
3
Source : messaging.py
with MIT License
from bkerler
with MIT License
from bkerler
def obfuscate_url_pw(u):
u = url.make_url(u)
if u.password:
u.password = 'XXXXX'
return str(u)
def warn(msg):
3
Source : 620241d1153f_update_time_grain_sqla.py
with Apache License 2.0
from CloudmindsRobot
with Apache License 2.0
from CloudmindsRobot
def grains(self):
url = make_url(self.sqlalchemy_uri)
backend = url.get_backend_name()
db_engine_spec = db_engine_specs.engines.get(
backend, db_engine_specs.BaseEngineSpec
)
return db_engine_spec.get_time_grains()
class Table(Base):
3
Source : core.py
with Apache License 2.0
from CloudmindsRobot
with Apache License 2.0
from CloudmindsRobot
def get_password_masked_url_from_uri( # pylint: disable=invalid-name
cls, uri: str
) -> URL:
sqlalchemy_url = make_url(uri)
return cls.get_password_masked_url(sqlalchemy_url)
@classmethod
3
Source : core.py
with Apache License 2.0
from CloudmindsRobot
with Apache License 2.0
from CloudmindsRobot
def set_sqlalchemy_uri(self, uri: str) -> None:
conn = sqla.engine.url.make_url(uri.strip())
if conn.password != PASSWORD_MASK and not custom_password_store:
# do not over-write the password with the password mask
self.password = conn.password
conn.password = PASSWORD_MASK if conn.password else None
self.sqlalchemy_uri = str(conn) # hides the password
def get_effective_user(
3
Source : core.py
with Apache License 2.0
from CloudmindsRobot
with Apache License 2.0
from CloudmindsRobot
def sqlalchemy_uri_decrypted(self) -> str:
conn = sqla.engine.url.make_url(self.sqlalchemy_uri)
if custom_password_store:
conn.password = custom_password_store(conn)
else:
conn.password = self.password
return str(conn)
@property
3
Source : core.py
with Apache License 2.0
from CloudmindsRobot
with Apache License 2.0
from CloudmindsRobot
def get_dialect(self) -> Dialect:
sqla_url = url.make_url(self.sqlalchemy_uri_decrypted)
return sqla_url.get_dialect()() # pylint: disable=no-member
sqla.event.listen(Database, "after_insert", security_manager.set_perm)
3
Source : validators.py
with Apache License 2.0
from CloudmindsRobot
with Apache License 2.0
from CloudmindsRobot
def sqlalchemy_uri_validator(
uri: str, exception: Type[ValidationError] = ValidationError
) -> None:
"""
Check if a user has submitted a valid SQLAlchemy URI
"""
try:
make_url(uri.strip())
except (ArgumentError, AttributeError):
raise exception(
_(
"Invalid connection string, a valid string usually follows:"
"'DRIVER://USER:PASSWORD@DB-HOST/DATABASE-NAME'"
" < p>Example:'postgresql://user:password@your-postgres-db/database' < /p>"
)
)
def schema_allows_csv_upload(database: Database, schema: Optional[str]) -> bool:
3
Source : core_tests.py
with Apache License 2.0
from CloudmindsRobot
with Apache License 2.0
from CloudmindsRobot
def test_custom_password_store(self):
database = utils.get_example_database()
conn_pre = sqla.engine.url.make_url(database.sqlalchemy_uri_decrypted)
def custom_password_store(uri):
return "password_store_test"
models.custom_password_store = custom_password_store
conn = sqla.engine.url.make_url(database.sqlalchemy_uri_decrypted)
if conn_pre.password:
assert conn.password == "password_store_test"
assert conn.password != conn_pre.password
# Disable for password store for later tests
models.custom_password_store = None
def test_databaseview_edit(self, username="admin"):
3
Source : database.py
with BSD 3-Clause "New" or "Revised" License
from clp-research
with BSD 3-Clause "New" or "Revised" License
from clp-research
def apply_driver_hacks(self, url):
url = engine.url.make_url(url)
if url.drivername == "sqlite" and url.database in (None, "", ":memory:"):
from sqlalchemy.pool import StaticPool
self._connect_args = {"check_same_thread": False}
self._poolclass = StaticPool
def bind(self, engine):
3
Source : messaging.py
with MIT License
from DiptoChakrabarty
with MIT License
from DiptoChakrabarty
def obfuscate_url_pw(u):
u = url.make_url(u)
if u.password:
u.password = "XXXXX"
return str(u)
def warn(msg, stacklevel=2):
3
Source : conftest.py
with MIT License
from dwreeves
with MIT License
from dwreeves
def db_params(uri) -> dict:
data = sa.engine.url.make_url(uri).translate_connect_args()
data.setdefault("dbname", data.pop("database", "localhost"))
data.setdefault("user", data.pop("username", None))
data.setdefault("host", data.pop("host", 5432))
return data
@pytest.fixture(autouse=True)
3
Source : test_enginestrategy.py
with GNU General Public License v2.0
from flathub
with GNU General Public License v2.0
from flathub
def test_sqlite_pct_sub(self):
u = url.make_url("sqlite:///%(basedir)s/x/state.sqlite")
kwargs = dict(basedir='/my-base-dir')
u, kwargs, max_conns = self.strat.special_case_sqlite(u, kwargs)
self.assertEqual([str(u), max_conns, self.filter_kwargs(kwargs)],
["sqlite:////my-base-dir/x/state.sqlite", 1,
self.sqlite_kwargs])
def test_sqlite_relpath(self):
3
Source : test_enginestrategy.py
with GNU General Public License v2.0
from flathub
with GNU General Public License v2.0
from flathub
def test_sqlite_abspath(self):
u = url.make_url("sqlite:////x/state.sqlite")
kwargs = dict(basedir='/my-base-dir')
u, kwargs, max_conns = self.strat.special_case_sqlite(u, kwargs)
self.assertEqual([str(u), max_conns, self.filter_kwargs(kwargs)],
["sqlite:////x/state.sqlite", 1, self.sqlite_kwargs])
def test_sqlite_memory(self):
3
Source : test_enginestrategy.py
with GNU General Public License v2.0
from flathub
with GNU General Public License v2.0
from flathub
def test_sqlite_memory(self):
u = url.make_url("sqlite://")
kwargs = dict(basedir='my-base-dir')
u, kwargs, max_conns = self.strat.special_case_sqlite(u, kwargs)
self.assertEqual([str(u), max_conns, self.filter_kwargs(kwargs)],
["sqlite://", 1, # only one conn at a time
dict(basedir='my-base-dir',
connect_args=dict(check_same_thread=False))])
def test_mysql_simple(self):
3
Source : test_enginestrategy.py
with GNU General Public License v2.0
from flathub
with GNU General Public License v2.0
from flathub
def test_mysql_simple(self):
u = url.make_url("mysql://host/dbname")
kwargs = dict(basedir='my-base-dir')
u, kwargs, max_conns = self.strat.special_case_mysql(u, kwargs)
self.assertEqual([str(u), max_conns, self.filter_kwargs(kwargs)],
["mysql://host/dbname?charset=utf8&use_unicode=True", None,
self.mysql_kwargs])
def test_mysql_userport(self):
3
Source : test_enginestrategy.py
with GNU General Public License v2.0
from flathub
with GNU General Public License v2.0
from flathub
def test_mysql_userport(self):
u = url.make_url("mysql://user:pass@host:1234/dbname")
kwargs = dict(basedir='my-base-dir')
u, kwargs, max_conns = self.strat.special_case_mysql(u, kwargs)
self.assertEqual([str(u), max_conns, self.filter_kwargs(kwargs)],
["mysql://user:pass@host:1234/dbname?"
"charset=utf8&use_unicode=True", None, self.mysql_kwargs])
def test_mysql_local(self):
3
Source : test_enginestrategy.py
with GNU General Public License v2.0
from flathub
with GNU General Public License v2.0
from flathub
def test_mysql_local(self):
u = url.make_url("mysql:///dbname")
kwargs = dict(basedir='my-base-dir')
u, kwargs, max_conns = self.strat.special_case_mysql(u, kwargs)
self.assertEqual([str(u), max_conns, self.filter_kwargs(kwargs)],
["mysql:///dbname?charset=utf8&use_unicode=True", None,
self.mysql_kwargs])
def test_mysql_args(self):
3
Source : test_enginestrategy.py
with GNU General Public License v2.0
from flathub
with GNU General Public License v2.0
from flathub
def test_mysql_args(self):
u = url.make_url("mysql:///dbname?foo=bar")
kwargs = dict(basedir='my-base-dir')
u, kwargs, max_conns = self.strat.special_case_mysql(u, kwargs)
self.assertEqual([str(u), max_conns, self.filter_kwargs(kwargs)],
["mysql:///dbname?charset=utf8&foo=bar&use_unicode=True",
None, self.mysql_kwargs])
def test_mysql_max_idle(self):
3
Source : test_enginestrategy.py
with GNU General Public License v2.0
from flathub
with GNU General Public License v2.0
from flathub
def test_mysql_max_idle(self):
u = url.make_url("mysql:///dbname?max_idle=1234")
kwargs = dict(basedir='my-base-dir')
u, kwargs, max_conns = self.strat.special_case_mysql(u, kwargs)
exp = self.mysql_kwargs.copy()
exp['pool_recycle'] = 1234
self.assertEqual([str(u), max_conns, self.filter_kwargs(kwargs)],
["mysql:///dbname?charset=utf8&use_unicode=True", None,
exp])
def test_mysql_good_charset(self):
3
Source : test_enginestrategy.py
with GNU General Public License v2.0
from flathub
with GNU General Public License v2.0
from flathub
def test_mysql_good_charset(self):
u = url.make_url("mysql:///dbname?charset=utf8")
kwargs = dict(basedir='my-base-dir')
u, kwargs, max_conns = self.strat.special_case_mysql(u, kwargs)
self.assertEqual([str(u), max_conns, self.filter_kwargs(kwargs)],
["mysql:///dbname?charset=utf8&use_unicode=True", None,
self.mysql_kwargs])
def test_mysql_bad_charset(self):
3
Source : test_enginestrategy.py
with GNU General Public License v2.0
from flathub
with GNU General Public License v2.0
from flathub
def test_mysql_bad_charset(self):
u = url.make_url("mysql:///dbname?charset=ebcdic")
kwargs = dict(basedir='my-base-dir')
with self.assertRaises(TypeError):
self.strat.special_case_mysql(u, kwargs)
def test_mysql_good_use_unicode(self):
3
Source : test_enginestrategy.py
with GNU General Public License v2.0
from flathub
with GNU General Public License v2.0
from flathub
def test_mysql_good_use_unicode(self):
u = url.make_url("mysql:///dbname?use_unicode=True")
kwargs = dict(basedir='my-base-dir')
u, kwargs, max_conns = self.strat.special_case_mysql(u, kwargs)
self.assertEqual([str(u), max_conns, self.filter_kwargs(kwargs)],
["mysql:///dbname?charset=utf8&use_unicode=True", None,
self.mysql_kwargs])
def test_mysql_bad_use_unicode(self):
3
Source : test_enginestrategy.py
with GNU General Public License v2.0
from flathub
with GNU General Public License v2.0
from flathub
def test_mysql_bad_use_unicode(self):
u = url.make_url("mysql:///dbname?use_unicode=maybe")
kwargs = dict(basedir='my-base-dir')
with self.assertRaises(TypeError):
self.strat.special_case_mysql(u, kwargs)
def test_mysql_storage_engine(self):
3
Source : test_enginestrategy.py
with GNU General Public License v2.0
from flathub
with GNU General Public License v2.0
from flathub
def test_mysql_storage_engine(self):
u = url.make_url("mysql:///dbname?storage_engine=foo")
kwargs = dict(basedir='my-base-dir')
u, kwargs, max_conns = self.strat.special_case_mysql(u, kwargs)
exp = self.mysql_kwargs.copy()
exp['connect_args'] = dict(
init_command='SET default_storage_engine=foo')
self.assertEqual([str(u), max_conns, self.filter_kwargs(kwargs)],
["mysql:///dbname?charset=utf8&use_unicode=True", None,
exp])
class BuildbotEngineStrategy(unittest.TestCase):
3
Source : test_engine.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_pyodbc_connect_dsn_trusted(self):
dialect = pyodbc.dialect()
u = url.make_url("mssql://mydsn")
connection = dialect.create_connect_args(u)
eq_([["dsn=mydsn;Trusted_Connection=Yes"], {}], connection)
def test_pyodbc_connect_old_style_dsn_trusted(self):
3
Source : test_engine.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_pyodbc_connect_old_style_dsn_trusted(self):
dialect = pyodbc.dialect()
u = url.make_url("mssql:///?dsn=mydsn")
connection = dialect.create_connect_args(u)
eq_([["dsn=mydsn;Trusted_Connection=Yes"], {}], connection)
def test_pyodbc_connect_dsn_non_trusted(self):
3
Source : test_engine.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_pyodbc_connect_dsn_non_trusted(self):
dialect = pyodbc.dialect()
u = url.make_url("mssql://username:password@mydsn")
connection = dialect.create_connect_args(u)
eq_([["dsn=mydsn;UID=username;PWD=password"], {}], connection)
def test_pyodbc_connect_dsn_extra(self):
3
Source : test_engine.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_pyodbc_connect_dsn_extra(self):
dialect = pyodbc.dialect()
u = url.make_url(
"mssql://username:password@mydsn/?LANGUAGE=us_" "english&foo=bar"
)
connection = dialect.create_connect_args(u)
dsn_string = connection[0][0]
assert ";LANGUAGE=us_english" in dsn_string
assert ";foo=bar" in dsn_string
def test_pyodbc_hostname(self):
3
Source : test_engine.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_pyodbc_hostname(self):
dialect = pyodbc.dialect()
u = url.make_url(
"mssql://username:password@hostspec/database?driver=SQL+Server"
)
connection = dialect.create_connect_args(u)
eq_(
[
[
"DRIVER={SQL Server};Server=hostspec;Database=database;UI"
"D=username;PWD=password"
],
{},
],
connection,
)
def test_pyodbc_host_no_driver(self):
3
Source : test_engine.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_pyodbc_connect_comma_port(self):
dialect = pyodbc.dialect()
u = url.make_url(
"mssql://username:password@hostspec:12345/data"
"base?driver=SQL Server"
)
connection = dialect.create_connect_args(u)
eq_(
[
[
"DRIVER={SQL Server};Server=hostspec,12345;Database=datab"
"ase;UID=username;PWD=password"
],
{},
],
connection,
)
def test_pyodbc_connect_config_port(self):
3
Source : test_engine.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_pyodbc_connect_config_port(self):
dialect = pyodbc.dialect()
u = url.make_url(
"mssql://username:password@hostspec/database?p"
"ort=12345&driver=SQL+Server"
)
connection = dialect.create_connect_args(u)
eq_(
[
[
"DRIVER={SQL Server};Server=hostspec;Database=database;UI"
"D=username;PWD=password;port=12345"
],
{},
],
connection,
)
def test_pyodbc_extra_connect(self):
3
Source : test_engine.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_pyodbc_odbc_connect_with_dsn(self):
dialect = pyodbc.dialect()
u = url.make_url(
"mssql:///?odbc_connect=dsn%3Dmydsn%3BDatabase"
"%3Ddatabase%3BUID%3Dusername%3BPWD%3Dpassword"
)
connection = dialect.create_connect_args(u)
eq_(
[["dsn=mydsn;Database=database;UID=username;PWD=password"], {}],
connection,
)
def test_pyodbc_odbc_connect_ignores_other_values(self):
3
Source : test_dialect.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_normal_arguments_mysqldb(self, kwarg, value):
from sqlalchemy.dialects.mysql import mysqldb
dialect = mysqldb.dialect()
connect_args = dialect.create_connect_args(
make_url(
"mysql://scott:tiger@localhost:3306/test"
"?%s=%s" % (kwarg, value)
)
)
eq_(connect_args[1][kwarg], value)
def test_mysqlconnector_buffered_arg(self):
3
Source : test_dialect.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_random_arg(self):
dialect = testing.db.dialect
kw = dialect.create_connect_args(
make_url("mysql://u:p@host/db?foo=true")
)[1]
eq_(kw["foo"], "true")
@testing.only_on("mysql")
3
Source : test_dialect.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _test_db_opt(self, url_string, key, value):
import cx_Oracle
url_obj = url.make_url(url_string)
dialect = cx_oracle.dialect(dbapi=cx_Oracle)
arg, kw = dialect.create_connect_args(url_obj)
eq_(kw[key], value)
def _test_db_opt_unpresent(self, url_string, key):
3
Source : test_dialect.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _test_db_opt_unpresent(self, url_string, key):
import cx_Oracle
url_obj = url.make_url(url_string)
dialect = cx_oracle.dialect(dbapi=cx_Oracle)
arg, kw = dialect.create_connect_args(url_obj)
assert key not in kw
def _test_dialect_param_from_url(self, url_string, key, value):
3
Source : test_dialect.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _test_dialect_param_from_url(self, url_string, key, value):
import cx_Oracle
url_obj = url.make_url(url_string)
dialect = cx_oracle.dialect(dbapi=cx_Oracle)
with testing.expect_deprecated(
"cx_oracle dialect option %r should" % key
):
arg, kw = dialect.create_connect_args(url_obj)
eq_(getattr(dialect, key), value)
# test setting it on the dialect normally
dialect = cx_oracle.dialect(dbapi=cx_Oracle, **{key: value})
eq_(getattr(dialect, key), value)
def test_mode(self):
See More Examples