当前位置: 首页>>代码示例>>Python>>正文


Python url.make_url方法代码示例

本文整理汇总了Python中sqlalchemy.engine.url.make_url方法的典型用法代码示例。如果您正苦于以下问题:Python url.make_url方法的具体用法?Python url.make_url怎么用?Python url.make_url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.engine.url的用法示例。


在下文中一共展示了url.make_url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create

# 需要导入模块: from sqlalchemy.engine import url [as 别名]
# 或者: from sqlalchemy.engine.url import make_url [as 别名]
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) 
开发者ID:jpush,项目名称:jbox,代码行数:18,代码来源:strategies.py

示例2: get_engine

# 需要导入模块: from sqlalchemy.engine import url [as 别名]
# 或者: from sqlalchemy.engine.url import make_url [as 别名]
def get_engine(self):
        with self._lock:
            uri = self.get_uri()
            echo = self._app.config['SQLALCHEMY_ECHO']
            if (uri, echo) == self._connected_for:
                return self._engine
            info = make_url(uri)
            options = {'convert_unicode': True}
            self._sa.apply_pool_defaults(self._app, options)
            self._sa.apply_driver_hacks(self._app, info, options)
            if echo:
                options['echo'] = True
            self._engine = rv = sqlalchemy.create_engine(info, **options)
            if _record_queries(self._app):
                _EngineDebuggingSignalEvents(self._engine,
                                             self._app.import_name).register()
            self._connected_for = (uri, echo)
            return rv 
开发者ID:jpush,项目名称:jbox,代码行数:20,代码来源:__init__.py

示例3: setUp

# 需要导入模块: from sqlalchemy.engine import url [as 别名]
# 或者: from sqlalchemy.engine.url import make_url [as 别名]
def setUp(self):
        self._undo = []
        url = os.getenv("PIFPAF_URL")
        if not url:
            self.skipTest("No database URL set")

        sa_url = make_url(url)

        if sa_url.drivername == 'mysql':
            sa_url.drivername = 'mysql+pymysql'

        initial_engine = sqlalchemy.create_engine(str(sa_url))
        initial_connection = initial_engine.connect()
        self._undo.append(initial_connection.close)
        initial_connection.execute("CREATE DATABASE a10_test_db")
        self._undo.append(lambda: initial_engine.execute("DROP DATABASE a10_test_db"))

        sa_url.database = 'a10_test_db'
        self.engine = sqlalchemy.create_engine(str(sa_url))
        self.connection = self.engine.connect()
        self._undo.append(self.connection.close) 
开发者ID:a10networks,项目名称:a10-neutron-lbaas,代码行数:23,代码来源:test_base.py

示例4: _read_connection_has_correct_privileges

# 需要导入模块: from sqlalchemy.engine import url [as 别名]
# 或者: from sqlalchemy.engine.url import make_url [as 别名]
def _read_connection_has_correct_privileges(self):
        ''' Returns True if the right permissions are set for the read
        only user. A table is created by the write user to test the
        read only user.
        '''
        write_connection = db._get_engine(
            {'connection_url': self.write_url}).connect()
        read_connection_user = sa_url.make_url(self.read_url).username

        drop_foo_sql = u'DROP TABLE IF EXISTS _foo'

        write_connection.execute(drop_foo_sql)

        try:
            write_connection.execute(u'CREATE TEMP TABLE _foo ()')
            for privilege in ['INSERT', 'UPDATE', 'DELETE']:
                test_privilege_sql = u"SELECT has_table_privilege(%s, '_foo', %s)"
                have_privilege = write_connection.execute(
                    test_privilege_sql, (read_connection_user, privilege)).first()[0]
                if have_privilege:
                    return False
        finally:
            write_connection.execute(drop_foo_sql)
            write_connection.close()
        return True 
开发者ID:italia,项目名称:daf-recipes,代码行数:27,代码来源:plugin.py

示例5: connect__

# 需要导入模块: from sqlalchemy.engine import url [as 别名]
# 或者: from sqlalchemy.engine.url import make_url [as 别名]
def connect__(self, uri, app):
        self.uri = uri
        self.info = sa_make_url(uri)
        self.options = self._cleanup_options(
            echo=False,
            pool_size=None,
            pool_timeout=None,
            pool_recycle=None,
            convert_unicode=True,
        )

        self._initialized = True
        self._IS_OK_ = True
        self.connector = None
        self._engine_lock = active_alchemy.threading.Lock()
        self.session = active_alchemy._create_scoped_session(self, query_cls=active_alchemy.BaseQuery)
        self.Model.db, self.BaseModel.db = self, self
        self.Model._query, self.BaseModel._query = self.session.query, self.session.query
        self.init_app(app)


# ------------------------------------------------------------------------------
# StorageObjectType 
开发者ID:mardix,项目名称:assembly,代码行数:25,代码来源:_db.py

示例6: get_db_name

# 需要导入模块: from sqlalchemy.engine import url [as 别名]
# 或者: from sqlalchemy.engine.url import make_url [as 别名]
def get_db_name():
    """Return an sqlalchemy name of the database from configuration

    db_name or db_url

    :rtype: name of the database
    :exception: ConfigurationException
    """
    url = Configuration.get('db_url', None)
    db_name = Configuration.get('db_name', None)

    if db_name is not None:
        return db_name

    if url:
        url = make_url(url)
        if url.database:
            return url.database

    raise ConfigurationException("No database name defined") 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:22,代码来源:config.py

示例7: get_engine

# 需要导入模块: from sqlalchemy.engine import url [as 别名]
# 或者: from sqlalchemy.engine.url import make_url [as 别名]
def get_engine(self):
        with self._lock:
            uri = self.get_uri()
            echo = self._app.config['SQLALCHEMY_ECHO']
            if (uri, echo) == self._connected_for:
                return self._engine
            info = make_url(uri)
            options = {'convert_unicode': True}
            self._sa.apply_pool_defaults(self._app, options)
            self._sa.apply_driver_hacks(self._app, info, options)
            if echo:
                options['echo'] = echo
            self._engine = rv = sqlalchemy.create_engine(info, **options)
            if _record_queries(self._app):
                _EngineDebuggingSignalEvents(self._engine,
                                             self._app.import_name).register()
            self._connected_for = (uri, echo)
            return rv 
开发者ID:yfauser,项目名称:planespotter,代码行数:20,代码来源:__init__.py

示例8: validate_database_precondition

# 需要导入模块: from sqlalchemy.engine import url [as 别名]
# 或者: from sqlalchemy.engine.url import make_url [as 别名]
def validate_database_precondition(url, db_kwargs, connect_timeout=5):
    """
    Validates that we can connect to the given database URL and the database meets our precondition.

    Raises an exception if the validation fails.
    """
    db_kwargs = db_kwargs.copy()
    try:
        driver = _db_from_url(
            url, db_kwargs, connect_timeout=connect_timeout, allow_retry=False, allow_pooling=False
        )
        driver.connect()
        pre_condition_check = PRECONDITION_VALIDATION.get(make_url(url).drivername)
        if pre_condition_check:
            pre_condition_check(driver)

    finally:
        try:
            driver.close()
        except:
            pass 
开发者ID:quay,项目名称:quay,代码行数:23,代码来源:database.py

示例9: get_core

# 需要导入模块: from sqlalchemy.engine import url [as 别名]
# 或者: from sqlalchemy.engine.url import make_url [as 别名]
def get_core(self, dburl):
        """Instantiates an appropriate core based on given database url

        Parameters
        ----------
        dburl : str
            Database url used to configure backend connection

        Returns
        -------
        core : :code:`geomancer.backend.cores.DBCore`
            DBCore instance to access DB-specific methods
        """
        name = make_url(dburl).get_backend_name()
        Core = CORES[name]
        return Core(dburl, self.options) 
开发者ID:thinkingmachines,项目名称:geomancer,代码行数:18,代码来源:base.py

示例10: __init__

# 需要导入模块: from sqlalchemy.engine import url [as 别名]
# 或者: from sqlalchemy.engine.url import make_url [as 别名]
def __init__(self, dburl, options=None):
        """Initialize the database core

        Parameters
        ----------
        dburl : str
            Database url used to configure backend connection
        options : :class:`geomancer.backend.settings.Config`, optional
            Specify configuration for interacting with the database backend.
            Auto-detected if not set.
        """
        self.dburl = make_url(dburl)
        if not options:
            options = {"bigquery": BQConfig(), "sqlite": SQLiteConfig()}[
                self.dburl.get_backend_name()
            ]
        self.options = options 
开发者ID:thinkingmachines,项目名称:geomancer,代码行数:19,代码来源:base.py

示例11: provisioned_database_url

# 需要导入模块: from sqlalchemy.engine import url [as 别名]
# 或者: from sqlalchemy.engine.url import make_url [as 别名]
def provisioned_database_url(self, base_url, ident):
        """Return a provisioned database URL.

        Given the URL of a particular database backend and the string
        name of a particular 'database' within that backend, return
        an URL which refers directly to the named database.

        For hostname-based URLs, this typically involves switching just the
        'database' portion of the URL with the given name and creating
        an engine.

        For URLs that instead deal with DSNs, the rules may be more custom;
        for example, the engine may need to connect to the root URL and
        then emit a command to switch to the named database.

        """

        url = sa_url.make_url(str(base_url))
        url.database = ident
        return url 
开发者ID:openstack,项目名称:oslo.db,代码行数:22,代码来源:provision.py

示例12: test_sqlite_memory_pool_args

# 需要导入模块: from sqlalchemy.engine import url [as 别名]
# 或者: from sqlalchemy.engine.url import make_url [as 别名]
def test_sqlite_memory_pool_args(self):
        for _url in ("sqlite://", "sqlite:///:memory:"):
            engines._init_connection_args(
                url.make_url(_url), self.args,
                max_pool_size=10, max_overflow=10)

            # queuepool arguments are not peresnet
            self.assertNotIn(
                'pool_size', self.args)
            self.assertNotIn(
                'max_overflow', self.args)

            self.assertEqual(False,
                             self.args['connect_args']['check_same_thread'])

            # due to memory connection
            self.assertIn('poolclass', self.args) 
开发者ID:openstack,项目名称:oslo.db,代码行数:19,代码来源:test_sqlalchemy.py

示例13: _create_new_database

# 需要导入模块: from sqlalchemy.engine import url [as 别名]
# 或者: from sqlalchemy.engine.url import make_url [as 别名]
def _create_new_database(cls, url):
        """Used by testing to create a new database."""
        purl = sqlalchemy_url.make_url(
            cls.dress_url(
                url))
        purl.database = purl.database + str(uuid.uuid4()).replace('-', '')
        new_url = str(purl)
        sqlalchemy_utils.create_database(new_url)
        return new_url 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:11,代码来源:sqlalchemy.py

示例14: dress_url

# 需要导入模块: from sqlalchemy.engine import url [as 别名]
# 或者: from sqlalchemy.engine.url import make_url [as 别名]
def dress_url(url):
        # If no explicit driver has been set, we default to pymysql
        if url.startswith("mysql://"):
            url = sqlalchemy_url.make_url(url)
            url.drivername = "mysql+pymysql"
            return str(url)
        if url.startswith("postgresql://"):
            url = sqlalchemy_url.make_url(url)
            url.drivername = "postgresql+psycopg2"
            return str(url)
        return url 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:13,代码来源:sqlalchemy.py

示例15: __init__

# 需要导入模块: from sqlalchemy.engine import url [as 别名]
# 或者: from sqlalchemy.engine.url import make_url [as 别名]
def __init__(self, url):
        self.table = Table('__tablename__', MetaData(),
                           Column('taskid', String(64), primary_key=True, nullable=False),
                           Column('url', String(1024)),
                           Column('result', Text()),
                           Column('updatetime', Float(32)),
                           mysql_engine='InnoDB',
                           mysql_charset='utf8'
                           )

        self.url = make_url(url)
        if self.url.database:
            database = self.url.database
            self.url.database = None
            try:
                engine = create_engine(self.url, convert_unicode=True, pool_recycle=3600)
                conn = engine.connect()
                conn.execute("commit")
                conn.execute("CREATE DATABASE %s" % database)
            except sqlalchemy.exc.SQLAlchemyError:
                pass
            self.url.database = database
        self.engine = create_engine(url, convert_unicode=True,
                                    pool_recycle=3600)

        self._list_project() 
开发者ID:binux,项目名称:pyspider,代码行数:28,代码来源:resultdb.py


注:本文中的sqlalchemy.engine.url.make_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。