• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python conversions.copy函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中MySQLdb.converters.conversions.copy函数的典型用法代码示例。如果您正苦于以下问题:Python copy函数的具体用法?Python copy怎么用?Python copy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: load_environment

def load_environment(global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config``
    object
    """
    config = PylonsConfig()

    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    # setup themes
    template_paths = [os.path.join(root, 'templates')]
    themesbase = app_conf.get('baruwa.themes.base', None)
    if themesbase and os.path.isabs(themesbase):
        templatedir = os.path.join(themesbase, 'templates')
        if os.path.isdir(templatedir):
            template_paths.append(templatedir)
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=template_paths)

    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package='baruwa', paths=paths)

    config['routes.map'] = make_map(config)
    config['pylons.app_globals'] = app_globals.Globals(config)
    config['pylons.h'] = baruwa.lib.helpers

    # Setup cache object as early as possible
    import pylons
    pylons.cache._push_object(config['pylons.app_globals'].cache)

    # Create the Mako TemplateLookup, with the default auto-escaping
    config['pylons.app_globals'].mako_lookup = TemplateLookup(
        directories=paths['templates'],
        error_handler=handle_mako_error,
        module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
        input_encoding='utf-8', default_filters=['escape'],
        imports=['from webhelpers.html import escape'])

    # Setup the SQLAlchemy database engine
    surl = config['sqlalchemy.url']
    if surl.startswith('mysql'):
        conv = conversions.copy()
        conv[246] = float
        engine = create_engine(surl, pool_recycle=1800,
                    connect_args=dict(conv=conv))
    else:
        engine = engine_from_config(config, 'sqlalchemy.', poolclass=NullPool)
    init_model(engine)

    # CONFIGURATION OPTIONS HERE (note: all config options will override
    # any Pylons config options)

    return config
开发者ID:baruwaproject,项目名称:baruwa2,代码行数:54,代码来源:environment.py


示例2: getConnection

 def getConnection(self):
     '''
     '''
     my_conv = mysqlconversions.copy()
     
     dbConn = MySQLdb.connect(conv=my_conv,
                          host=self.config.db["host"],
                          user=self.config.db["user"],
                          passwd=self.config.db["password"],
                          db=self.config.db["database"])
     
     return dbConn
开发者ID:cabumtz,项目名称:ParseCensocath,代码行数:12,代码来源:daoutil.py


示例3: __init__

 def __init__(self):
     self.dbconn = None
     self.cursor = None
     self.plain_cursor = None
     self.escape_string = self.escape_fake
     self.connection_data = {}
     self.conversion_dict = conversions.copy()
     self.conversion_dict[FIELD_TYPE.DECIMAL] = int
     self.conversion_dict[FIELD_TYPE.LONG] = int
     self.conversion_dict[FIELD_TYPE.LONGLONG] = int
     self.conversion_dict[FIELD_TYPE.FLOAT] = float
     self.conversion_dict[FIELD_TYPE.NEWDECIMAL] = float
开发者ID:Sabayon,项目名称:packages-website,代码行数:12,代码来源:mysql.py


示例4: _init_conversions

 def _init_conversions(self):
     """Register our type conversions."""
     self.m_conversions = conversions.copy()
     self.m_conversions[FIELD_TYPE.BLOB] = [(FLAG.BINARY, create_buffer),
                                            (None, None)]
     self.m_conversions[FIELD_TYPE.DATETIME] = pytimes.DateTime_or_None
     self.m_conversions[FIELD_TYPE.DATE] = pytimes.Date_or_None
     self.m_conversions[FIELD_TYPE.TIME] = pytimes.Time_or_None
     self.m_conversions[FIELD_TYPE.TIMESTAMP] = create_datetime
     self.m_conversions[datetime.date] = mysql_stringify
     self.m_conversions[datetime.time] = mysql_stringify
     self.m_conversions[datetime.datetime] = mysql_stringify
     self.m_conversions[datetime.timedelta] = mysql_stringify
开发者ID:geertj,项目名称:draco2,代码行数:13,代码来源:dbmysqldb.py


示例5: __init__

 def __init__(self):
     self.dbconn = None
     self.cursor = None
     self.plain_cursor = None
     self.escape_string = self.escape_fake
     self.connection_data = {}
     self.mysql = MySQLdb
     self.mysql_exceptions = _mysql_exceptions
     self.FIELD_TYPE = FIELD_TYPE
     self.conversion_dict = conversions.copy()
     self.conversion_dict[self.FIELD_TYPE.DECIMAL] = int
     self.conversion_dict[self.FIELD_TYPE.LONG] = int
     self.conversion_dict[self.FIELD_TYPE.FLOAT] = float
     self.conversion_dict[self.FIELD_TYPE.NEWDECIMAL] = float
开发者ID:Sabayon,项目名称:pastebin-website,代码行数:14,代码来源:Portal.py


示例6: __init__

    def __init__(self, host, port, user, passwd, db, charset):
        self.conn_params = conn_params = dict(
                host=host, user=user, port=port,
                db=db, init_command='set names %s'%charset,
        )
        if passwd :
            conn_params['passwd'] = passwd
        conv = conversions.copy()
        conv.update({
             FIELD_TYPE.TIMESTAMP: None,
             FIELD_TYPE.DATETIME: None,
             FIELD_TYPE.TIME: None,
             FIELD_TYPE.DATE: None,
        })

        conn_params['conv'] = conv
        conn_params['maxusage'] = False
        self._cursor = None 
开发者ID:cheshang,项目名称:cheshang,代码行数:18,代码来源:connnect.py


示例7: filterwarnings

# Raise exceptions for database warnings if DEBUG is on
from django.conf import settings
if settings.DEBUG:
    from warnings import filterwarnings
    filterwarnings("error", category=Database.Warning)

DatabaseError = Database.DatabaseError
IntegrityError = Database.IntegrityError

# MySQLdb-1.2.1 supports the Python boolean type, and only uses datetime
# module for time-related columns; older versions could have used mx.DateTime
# or strings if there were no datetime module. However, MySQLdb still returns
# TIME columns as timedelta -- they are more like timedelta in terms of actual
# behavior as they are signed and include days -- and Django expects time, so
# we still need to override that.
django_conversions = conversions.copy()
django_conversions.update({
    FIELD_TYPE.TIME: util.typecast_time,
    FIELD_TYPE.DECIMAL: util.typecast_decimal,
    FIELD_TYPE.NEWDECIMAL: util.typecast_decimal,
})

# This should match the numerical portion of the version numbers (we can treat
# versions like 5.0.24 and 5.0.24a as the same). Based on the list of version
# at http://dev.mysql.com/doc/refman/4.1/en/news.html and
# http://dev.mysql.com/doc/refman/5.0/en/news.html .
server_version_re = re.compile(r'(\d{1,2})\.(\d{1,2})\.(\d{1,2})')

# MySQLdb-1.2.1 and newer automatically makes use of SHOW WARNINGS on
# MySQL-4.1 and newer, so the MysqlDebugWrapper is unnecessary. Since the
# point is to raise Warnings as exceptions, this can be done with the Python
开发者ID:AloneRoad,项目名称:Inforlearn,代码行数:31,代码来源:base.py


示例8: Database

"""
import MySQLdb as dbapi
from MySQLdb.converters import conversions
from MySQLdb.constants import FIELD_TYPE

from kalapy.db.engines import utils
from kalapy.db.engines.relational import RelationalDatabase


__all__ = ('DatabaseError', 'IntegrityError', 'Database')


DatabaseError = dbapi.DatabaseError
IntegrityError = dbapi.IntegrityError

CONV = conversions.copy()
CONV.update({
    FIELD_TYPE.DECIMAL: utils.decimal_to_python,
})

class Database(RelationalDatabase):

    data_types = {
        "key"       :   "INTEGER AUTO_INCREMENT PRIMARY KEY",
        "reference" :   "INTEGER",
        "char"      :   "VARCHAR(%(size)s)",
        "text"      :   "LONGTEXT",
        "integer"   :   "INTEGER",
        "float"     :   "DOUBLE",
        "decimal"   :   "DECIMAL(%(max_digits)s, %(decimal_places)s)",
        "boolean"   :   "BOOL",
开发者ID:lafada,项目名称:kalapy,代码行数:31,代码来源:_database.py


示例9: connect_by_uri

def connect_by_uri(uri):
    """General URI syntax:

    mysql://user:[email protected]:port/db?opt1=val1&opt2=val2&...

    where opt_n is in the list of options supported by MySQLdb:

        host,user,passwd,db,compress,connect_timeout,read_default_file,
        read_default_group,unix_socket,port

    NOTE: the authority and the path parts of the URI have precedence
    over the query part, if an argument is given in both.

        conv,quote_conv,cursorclass
    are not (yet?) allowed as complex Python objects are needed, hard to
    transmit within an URI...

    See for description of options:
        http://dustman.net/andy/python/MySQLdb_obsolete/doc/MySQLdb-3.html#ss3.1
        http://mysql-python.svn.sourceforge.net/viewvc/mysql-python/trunk/MySQLdb/doc/MySQLdb.txt?revision=438&view=markup&pathrev=438

    """
    puri = urisup.uri_help_split(uri)
    params = __dict_from_query(puri[QUERY])
    if puri[AUTHORITY]:
        user, passwd, host, port = puri[AUTHORITY]
        if user:
            params['user'] = user
        if passwd:
            params['passwd'] = passwd
        if host:
            params['host'] = host
        if port:
            params['port'] = port
    if puri[PATH]:
        params['db'] = puri[PATH]
        if params['db'] and params['db'][0] == '/':
            params['db'] = params['db'][1:]
    __apply_types(params, __typemap)

    # The next affectation work around a bug in python-mysqldb which
    # happens when using an unicode charset: the conv parameter is
    # defaulted to the common dictionary MySQLdb.converters.conversions
    # when not explicitly given to the __init__() of
    # MySQLdb.connections.Connection, the _mysql module just store it in
    # the .converter member in the __init__() method of the base class
    # _mysql.connection, and later, back in the __init__() of
    # MySQLdb.connections.Connection, some children of .converter, which
    # are lists, are prepended by dynamically generated functions. The net
    # result is that every times a new Mysql connection is asked for with
    # no individualised conversion dictionary passed to the conv parameter,
    # a bunch of new functions and tuples are created, on which the process
    # will keep references forever, effectively leaking some memory as some
    # won't be used anymore after the termination of any connection.
    # This work around is believed to be effective because the only
    # references to the dynamically created conversion functions generated
    # by MySQLdb.connections will be in this instance-specific copy of
    # MySQLdb.converters.conversions. A unique reference to this copy will
    # be held by the connection instance, so when the latter is garbage
    # collected, the copied conversion dictionary is freed, and eventually
    # the now orphan tuples and generated functions are too.
    params['conv'] = CST_CONVERSIONS.copy()
    params['cursorclass'] = SSCursor

    return MySQLdb.connect(**params)
开发者ID:Eyepea,项目名称:xivo-gallifrey,代码行数:65,代码来源:backmysql.py


示例10: connect

def connect(module=config.sqlModule):
    if module == "MySQLdb":
        import MySQLdb.cursors

        conv = None
        try:
            from MySQLdb.converters import conversions
            from MySQLdb.constants import FIELD_TYPE

            # Patch.
            conv = conversions.copy()
            conv[FIELD_TYPE.LONG] = int  # Get rid of the longs.
        except:
            pass  # Moist / MysqlDB2 already do this.

        if config.sqlSocket:
            if conv:
                return adbapi.ConnectionPool(
                    module,
                    host=config.sqlHost,
                    unix_socket=config.sqlSocket,
                    db=config.sqlDatabase,
                    user=config.sqlUsername,
                    passwd=config.sqlPassword,
                    cp_min=config.sqlMinConnections,
                    cp_max=config.sqlMaxConnections,
                    cp_reconnect=True,
                    cp_noisy=config.sqlDebug,
                    cursorclass=MySQLdb.cursors.DictCursor,
                    conv=conv,
                )
            else:
                return adbapi.ConnectionPool(
                    module,
                    host=config.sqlHost,
                    unix_socket=config.sqlSocket,
                    db=config.sqlDatabase,
                    user=config.sqlUsername,
                    passwd=config.sqlPassword,
                    cp_min=config.sqlMinConnections,
                    cp_max=config.sqlMaxConnections,
                    cp_reconnect=True,
                    cp_noisy=config.sqlDebug,
                    cursorclass=MySQLdb.cursors.DictCursor,
                )
        else:
            if conv:
                return adbapi.ConnectionPool(
                    module,
                    host=config.sqlHost,
                    db=config.sqlDatabase,
                    user=config.sqlUsername,
                    passwd=config.sqlPassword,
                    cp_min=config.sqlMinConnections,
                    cp_max=config.sqlMaxConnections,
                    cp_reconnect=True,
                    cp_noisy=config.sqlDebug,
                    cursorclass=MySQLdb.cursors.DictCursor,
                    conv=conv,
                )
            else:
                return adbapi.ConnectionPool(
                    module,
                    host=config.sqlHost,
                    db=config.sqlDatabase,
                    user=config.sqlUsername,
                    passwd=config.sqlPassword,
                    cp_min=config.sqlMinConnections,
                    cp_max=config.sqlMaxConnections,
                    cp_reconnect=True,
                    cp_noisy=config.sqlDebug,
                    cursorclass=MySQLdb.cursors.DictCursor,
                )
    elif module == "mysql-ctypes":
        import MySQLdb.cursors

        return adbapi.ConnectionPool(
            "MySQLdb",
            host=config.sqlHost,
            port=3306,
            db=config.sqlDatabase,
            user=config.sqlUsername,
            passwd=config.sqlPassword,
            cp_min=config.sqlMinConnections,
            cp_max=config.sqlMaxConnections,
            cp_reconnect=True,
            cp_noisy=config.sqlDebug,
            cursorclass=MySQLdb.cursors.DictCursor,
            conv=conv,
        )

    elif module == "oursql":
        try:
            import oursql
        except ImportError:
            print "Falling oursql back to MySQLdb"
            return connect("MySQLdb")

        from MySQLdb.constants import FIELD_TYPE
        from MySQLdb.converters import conversions
#.........这里部分代码省略.........
开发者ID:novasdream,项目名称:PyOT,代码行数:101,代码来源:sql.py


示例11: ImproperlyConfigured

"""
MySQL database backend for Django.
Requires mysqlclient: https://pypi.python.org/pypi/mysqlclient/
MySQLdb is supported for Python 2 only: http://sourceforge.net/projects/mysql-python
"""
from __future__ import unicode_literals
import datetime
import re
import sys
import warnings
from django.conf import settings
from django.db import utils
from django.db.backends import utils as backend_utils
from django.db.backends.base.base import BaseDatabaseWrapper
from django.utils import six, timezone
from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.encoding import force_str
from django.utils.functional import cached_property
from django.utils.safestring import SafeBytes, SafeText
try:
    import MySQLdb as Database
except ImportError as e:
    from django.core.exceptions import ImproperlyConfigured
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
from MySQLdb.constants import CLIENT, FIELD_TYPE                # isort:skip
from MySQLdb.converters import Thing2Literal, conversions       # isort:skip
# Some of these import MySQLdb, so import them after checking if it's installed.
from .client import DatabaseClient                          # isort:skip
from .creation import DatabaseCreation                      # isort:skip
from .features import DatabaseFeatures                      # isort:skip
开发者ID:letouriste001,项目名称:SmartForest_2.0,代码行数:30,代码来源:base.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python MythTV.VideoMetadata类代码示例发布时间:2022-05-24
下一篇:
Python MySQLdb.thwart函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap