當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。