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


Python Registry.getConfig方法代码示例

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


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

示例1: find

# 需要导入模块: from twistar.registry import Registry [as 别名]
# 或者: from twistar.registry.Registry import getConfig [as 别名]
    def find(klass, id=None, where=None, group=None, limit=None, orderby=None):
        """
        Find instances of a given class.

        @param id: The integer of the C{klass} to find.  For instance, C{Klass.find(1)}
        will return an instance of Klass from the row with an id of 1 (unless it isn't
        found, in which case C{None} is returned).

        @param where: A C{list} whose first element is the string version of the
        condition with question marks in place of any parameters.  Further elements
        of the C{list} should be the values of any parameters specified.  For instance,
        C{['first_name = ? AND age > ?', 'Bob', 21]}.

        @param group: A C{str} describing the grouping, like C{group='first_name'}.

        @param limit: An C{int} specifying the limit of the results.  If this is 1,
        then the return value will be either an instance of C{klass} or C{None}.

        @param orderby: A C{str} describing the ordering, like C{orderby='first_name DESC'}.        

        @return: A C{Deferred} which returns the following to a callback:
        If id is specified (or C{limit} is 1) then a single
        instance of C{klass} will be returned if one is found that fits the criteria, C{None}
        otherwise.  If id is not specified and C{limit} is not 1, then a C{list} will
        be returned with all matching results.
        """
        config = Registry.getConfig()
        d = config.select(klass.tablename(), id, where, group, limit, orderby)
        return d.addCallback(createInstances, klass)
开发者ID:eallik,项目名称:twistar,代码行数:31,代码来源:dbobject.py

示例2: __init__

# 需要导入模块: from twistar.registry import Registry [as 别名]
# 或者: from twistar.registry.Registry import getConfig [as 别名]
    def __init__(self, inst, propname, givenargs):
        """
        Constructor.

        @param inst: The L{DBObject} instance.
        
        @param propname: The property name in the L{DBObject} instance that
        results in this class being created.

        @param givenargs: Any arguments given (through the use of a C{dict}
        in the class variable in L{DBObject} rather than a string to describe
        the relationship).  The given args can include, for all relationships,
        a C{class_name}.  Depending on the relationship, C{association_foreign_key}
        and C{foreign_key} might also be used.
        """
        self.infl = Inflector()
        self.inst = inst
        self.dbconfig = Registry.getConfig()

        ## Set args
        self.args = {
            'class_name': propname,
            'association_foreign_key': self.infl.foreignKey(self.infl.singularize(propname)),
            'foreign_key': self.infl.foreignKey(self.inst.__class__.__name__),
            'polymorphic': False
        }
        self.args.update(givenargs)

        otherklassname = self.infl.classify(self.args['class_name'])
        if not self.args['polymorphic']:
            self.otherklass = Registry.getClass(otherklassname)
        self.othername = self.args['association_foreign_key']
        self.thisclass = self.inst.__class__
        self.thisname = self.args['foreign_key']
开发者ID:ChillingChua,项目名称:twistar,代码行数:36,代码来源:relationships.py

示例3: commit

# 需要导入模块: from twistar.registry import Registry [as 别名]
# 或者: from twistar.registry.Registry import getConfig [as 别名]
    def commit(self):
        self._assertCorrectThread()

        if not self._parent.is_active:
            raise TransactionError("This transaction is inactive")

        Registry.getConfig().txnGuard.txn = self._actual_parent
        self._do_commit()
        self.is_active = False
开发者ID:Paranaix,项目名称:twistar,代码行数:11,代码来源:transaction.py

示例4: rollback

# 需要导入模块: from twistar.registry import Registry [as 别名]
# 或者: from twistar.registry.Registry import getConfig [as 别名]
    def rollback(self):
        self._assertCorrectThread()

        if not self._parent.is_active:
            return

        Registry.getConfig().txnGuard.txn = self._actual_parent
        self._do_rollback()
        self.is_active = False
开发者ID:Paranaix,项目名称:twistar,代码行数:11,代码来源:transaction.py

示例5: _transaction

# 需要导入模块: from twistar.registry import Registry [as 别名]
# 或者: from twistar.registry.Registry import getConfig [as 别名]
 def _transaction(txn, args, kwargs):
     config = Registry.getConfig()
     config.txn = txn
     # get the result of the functions *synchronously*, since this is in a transaction
     try:
         result = threads.blockingCallFromThread(reactor, interaction, txn, *args, **kwargs)
         config.txn = None
         return result
     except Exception, e:
         config.txn = None
         raise TransactionError(str(e))
开发者ID:yombo,项目名称:twistar,代码行数:13,代码来源:utils.py

示例6: deleteAll

# 需要导入模块: from twistar.registry import Registry [as 别名]
# 或者: from twistar.registry.Registry import getConfig [as 别名]
    def deleteAll(klass, where=None, transaction=None):
        """
        Delete all instances of C{klass} in the database.

        @param where: Conditionally delete instances.  This parameter is of the same form
        found in L{find}.

        @return: A C{Deferred}.        
        """
        config = Registry.getConfig()
        tablename = klass.tablename()
        return config.delete(tablename, where, transaction)
开发者ID:flaviogrossi,项目名称:twistar,代码行数:14,代码来源:dbobject.py

示例7: count

# 需要导入模块: from twistar.registry import Registry [as 别名]
# 或者: from twistar.registry.Registry import getConfig [as 别名]
    def count(klass, where=None):
        """
        Count instances of a given class.

        @param where: An optional C{list} whose first element is the string version of the
        condition with question marks in place of any parameters.  Further elements
        of the C{list} should be the values of any parameters specified.  For instance,
        C{['first_name = ? AND age > ?', 'Bob', 21]}.

        @return: A C{Deferred} which returns the total number of db records to a callback.
        """
        config = Registry.getConfig()
        return config.count(klass.tablename(), where=where)
开发者ID:eallik,项目名称:twistar,代码行数:15,代码来源:dbobject.py

示例8: deleteAll

# 需要导入模块: from twistar.registry import Registry [as 别名]
# 或者: from twistar.registry.Registry import getConfig [as 别名]
    def deleteAll(klass, where=None):
        """
        Delete all instances of C{klass} in the database without instantiating the records
        first or invoking callbacks (L{beforeDelete} is not called). This will run a single
        SQL DELETE statement in the database.

        @param where: Conditionally delete instances.  This parameter is of the same form
        found in L{find}.

        @return: A C{Deferred}.        
        """
        config = Registry.getConfig()
        tablename = klass.tablename()
        return config.delete(tablename, where)
开发者ID:eallik,项目名称:twistar,代码行数:16,代码来源:dbobject.py

示例9: connect

# 需要导入模块: from twistar.registry import Registry [as 别名]
# 或者: from twistar.registry.Registry import getConfig [as 别名]
    def connect(cls, connection, *args, **kwargs):
        "This is how we instantiate a DatastoreSQL object with connection"
        obj = cls(connection, *args, **kwargs)

        Registry.DBPOOL = adbapi.ConnectionPool(
            'pyodbc',
            obj.config['connection'],
            autocommit=True,
            cp_reconnect=True
        )
        obj.raw_db = Registry.DBPOOL  # Accessible if we need *really* low-level access to DB.
        obj.db = Registry.getConfig()

        return obj
开发者ID:jdrago999,项目名称:lightning,代码行数:16,代码来源:sql.py

示例10: transaction

# 需要导入模块: from twistar.registry import Registry [as 别名]
# 或者: from twistar.registry.Registry import getConfig [as 别名]
def transaction(func=None, nested=False, thread_check=True):
    """Starts a new transaction.

    A Transaction object returned by this function can be used as a context manager,
    which will atomatically be commited or rolledback if an exception is raised.

    Transactions must only be used in db threads. This behaviour can be overriden by setting the
    'thread_check' to False, allowing transactions to be started in arbitrary threads which is
    useful to e.g simplify testcases.

    If this function is used as decorator, the decorated function will be executed in a db thread and
    gets the Transaction passed as first argument. Decorated functions are allowed to return Deferreds.
    E.g:
        @transaction
        def someFunc(txn, param1):
            # Runs in a db thread

        d = someFunc(1)  # will be calledback (in mainthread) when someFunc returns

    You have to make sure, that you use blockingCallFromThread() or use synchronization if you need to
    interact with code which runs in the mainthread. Also care has to be taken when waiting for Deferreds.
    You must assure that the callbacks will be invoked from the db thread.

    Per default transactions can be nested: Commiting such a "nested" transaction will simply do nothing,
    but a rollback on it will rollback the outermost transaction. This allow creation of functions which will
    either create a new transaction or will participate in an already ongoing tranaction which is handy for library code.

    SAVEPOINT transactions can be used by either setting the 'nested' flag to true or by calling the 'nested_transaction' function.
    """
    if nested and Registry.DBPOOL.dbapi.__name__ == "sqlite3":
        # needs some modification on our side, see:
        # http://docs.sqlalchemy.org/en/latest/dialects/sqlite.html#serializable-isolation-savepoints-transactional-ddl
        raise NotImplementedError("sqlite currently not supported")

    if func is None:
        conn_pool = Registry.DBPOOL
        cfg = Registry.getConfig()

        if cfg.txnGuard.txn is None:
            conn = conn_pool.connectionFactory(conn_pool)
            return _RootTransaction(conn_pool, conn, thread_check=thread_check)
        elif nested:
            return _SavepointTransaction(cfg.txnGuard.txn, thread_check=thread_check)
        else:
            return _Transaction(cfg.txnGuard.txn, thread_check=thread_check)
    else:
        return _transaction_dec(func, functools.partial(transaction, nested=nested, thread_check=thread_check))
开发者ID:Paranaix,项目名称:twistar,代码行数:49,代码来源:transaction.py

示例11: __init__

# 需要导入模块: from twistar.registry import Registry [as 别名]
# 或者: from twistar.registry.Registry import getConfig [as 别名]
    def __init__(self, **kwargs):
        """
        Constructor.  DO NOT OVERWRITE.  Use the L{DBObject.afterInit} method.
        
        @param kwargs: An optional dictionary containing the properties that
        should be initially set for this object.

        @see: L{DBObject.afterInit}
        """
        self.id = None
        self._deleted = False
        self.errors = Errors()
        self.updateAttrs(kwargs)
        self._config = Registry.getConfig()

        if self.__class__.RELATIONSHIP_CACHE is None:
            self.__class__.initRelationshipCache()
开发者ID:eallik,项目名称:twistar,代码行数:19,代码来源:dbobject.py

示例12: __init__

# 需要导入模块: from twistar.registry import Registry [as 别名]
# 或者: from twistar.registry.Registry import getConfig [as 别名]
    def __init__(self, parent, thread_check=True):
        # Transactions must be started in db thread unless explicitely permitted
        if thread_check and threading.current_thread() not in Registry.DBPOOL.threadpool.threads:
            raise TransactionError("Transaction must only be started in a db pool thread")

        if parent is None:
            self._root = self
        else:
            self._root = parent._root

        self._actual_parent = parent
        self.is_active = True
        self._threadId = threadable.getThreadID()
        self._savepoint_seq = 0

        if not self._parent.is_active:
            raise TransactionError("Parent transaction is inactive")

        Registry.getConfig().txnGuard.txn = self
开发者ID:Paranaix,项目名称:twistar,代码行数:21,代码来源:transaction.py

示例13: setUp

# 需要导入模块: from twistar.registry import Registry [as 别名]
# 或者: from twistar.registry.Registry import getConfig [as 别名]
 def setUp(self):
     yield initDB(self)
     self.user = yield User(first_name="First", last_name="Last", age=10).save()
     self.avatar = yield Avatar(name="an avatar name", user_id=self.user.id).save()
     self.picture = yield Picture(name="a pic", size=10, user_id=self.user.id).save()        
     self.dbconfig = Registry.getConfig()
开发者ID:davec82,项目名称:twistar,代码行数:8,代码来源:test_dbconfig.py

示例14: __init__

# 需要导入模块: from twistar.registry import Registry [as 别名]
# 或者: from twistar.registry.Registry import getConfig [as 别名]
 def __init__(self, driver, **kwargs):
     conf = { 'cp_reconnect': True, 'charset': 'utf8' }
     conf.update(kwargs)
     Registry.DBPOOL = adbapi.ConnectionPool(driver, **conf)
     self.dbconfig = Registry.getConfig()
开发者ID:duydb2,项目名称:txque,代码行数:7,代码来源:sql.py


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