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


Python info.get_cls_info函数代码示例

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


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

示例1: run_test

        def run_test():
            yield tables.runCreateTable(Node)

            count = tables.count(Node)
            self.assertEqual(count, 0)

            store = config.main.zstorm.get('main_store')
            nodetest = Node()
            nodetest.name = u"test"
            nodetest.description = u"test"
            nodetest.hidden_service = u"test"
            nodetest.public_site = u"test"
            nodetest.email = u"[email protected]"
            nodetest.private_stats_update_time = 30 # minutes
            nodetest.public_stats_update_time = 120 # minutes
            nodetest.languages = [ { "code" : "it" , "name": "Italiano"}, { "code" : "en" , "name" : "English" }]
            store.add(nodetest)

            count = tables.count(Node)
            self.assertEqual(count, 1)

            # select & verify
            node = store.find(Node, 1 == Node.id).one()
            cls_info = get_cls_info(Node)
            for name in cls_info.attributes.iterkeys():
                self.assertEqual(getattr(node, name, ""), getattr(nodetest, name, ""))
开发者ID:hellais,项目名称:GLBackend,代码行数:26,代码来源:test_node.py

示例2: _load_object

    def _load_object(self, cls_info, result, values):
        """Create an object from values loaded from the database.

        @param cls_info: The C{ClassInfo} for the row being loaded.
        @param result: The database result set.
        @param values: The database values.
        @return: A new instances of the class mapped to the table being
            loaded.
        """
        if not any(values):
            # We've got a row full of NULLs, so consider that the object
            # wasn't found.  This is useful for joins, where non-existent rows
            # are represented like that.
            return None

        # Build a new instance.  We need the cls_info columns for the class of
        # the actual object, not from a possible wrapper (e.g. an alias).
        cls = cls_info.cls
        cls_info = get_cls_info(cls)
        index = {}
        for attributeName, propertyColumn in cls_info.attributes.iteritems():
            index[propertyColumn.name] = attributeName

        # Build a new instance and populate it with values from the database.
        obj = cls.__new__(cls)
        for column, value in zip(cls_info.columns, values):
            variable = column.variable_factory(value=value, from_db=True)
            attributeName = index[column.name]
            setattr(obj, attributeName, variable.get())
        return obj
开发者ID:fluidinfo,项目名称:fluiddb,代码行数:30,代码来源:readonly.py

示例3: determine_table_and_fragment

def determine_table_and_fragment(table, ftq):
    table = get_cls_info(table).table
    if ftq:
        query_fragment = "ftq(?)"
    else:
        query_fragment = "?::tsquery"
    return table, query_fragment
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:7,代码来源:stormexpr.py

示例4: __init__

    def __init__(self, local_key, remote_key, many, on_remote):
        assert type(local_key) is tuple and type(remote_key) is tuple

        self.local_key = local_key
        self.remote_key = remote_key

        self.local_cls = getattr(self.local_key[0], "cls", None)
        self.remote_cls = self.remote_key[0].cls
        self.remote_key_is_primary = False

        primary_key = get_cls_info(self.remote_cls).primary_key
        if len(primary_key) == len(self.remote_key):
            for column1, column2 in zip(self.remote_key, primary_key):
                if column1.name != column2.name:
                    break
            else:
                self.remote_key_is_primary = True

        self.many = many
        self.on_remote = on_remote

        # XXX These should probably be weak dictionaries.
        self._local_columns = {}
        self._remote_columns = {}

        self._l_to_r = {}
        self._r_to_l = {}
开发者ID:paiser,项目名称:component-management,代码行数:27,代码来源:references.py

示例5: event_key

    def event_key(self):
        """See `ILongPollEvent`.

        Constructs the key from the table name of the Storm class.
        """
        cls_info = get_cls_info(self.source)
        return generate_event_key(
            cls_info.table.name.lower())
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:8,代码来源:storm.py

示例6: __getattr__

 def __getattr__(self, attr):
     if attr.startswith("__"):
         raise AttributeError(attr)
     elif attr == "id":
         cls_info = get_cls_info(self._cls)
         return cls_info.primary_key[0]
     else:
         return getattr(self._cls, attr)
开发者ID:Jokymon,项目名称:timetracker,代码行数:8,代码来源:sqlobject.py

示例7: get_foreign_columns

    def get_foreign_columns(self):
        info = get_cls_info(self.orm_type)
        for name, attr in info.attributes.items():
            if not name.endswith('ID'):
                continue

            name = name[:-2]
            ref = getattr(self.orm_type, name)
            other_class = ref._remote_key.split('.')[0]
            yield name, other_class
开发者ID:leandrorchaves,项目名称:stoq,代码行数:10,代码来源:pylint_stoq.py

示例8: clear

 def clear(self, *args, **kwargs):
     store = Store.of(self._local)
     if store is None:
         raise NoStoreError("Can't perform operation without a store")
     where = self._relation1.get_where_for_remote(self._local)
     if args or kwargs:
         filter = get_where_for_args(args, kwargs, self._target_cls)
         join = self._relation2.get_where_for_join()
         table = get_cls_info(self._target_cls).table
         where &= Exists(Select(SQLRaw("*"), join & filter, tables=table))
     store.find(self._link_cls, where).remove()
开发者ID:paiser,项目名称:component-management,代码行数:11,代码来源:references.py

示例9: set_from_template

    def set_from_template(self, template):
        if not template:
            return

        for column in get_cls_info(template.__class__).columns:
            if column.name in ['product_tax_template_id', 'te_id', 'id']:
                continue

            value = getattr(template, column.name)
            setattr(self, column.name, value)

        self.set_initial_values()
开发者ID:leandrorchaves,项目名称:stoq,代码行数:12,代码来源:taxes.py

示例10: gen_reload_queries

def gen_reload_queries(objects):
    """Prepare queries to reload the given objects."""
    for object_type, objects in collate(objects, get_type):
        primary_key = get_cls_info(object_type).primary_key
        if len(primary_key) != 1:
            raise AssertionError(
                "Compound primary keys are not supported: %s." %
                object_type.__name__)
        primary_key_column = primary_key[0]
        primary_key_column_getter = primary_key_column.__get__
        for store, objects in collate(objects, Store.of):
            primary_keys = map(primary_key_column_getter, objects)
            condition = primary_key_column.is_in(primary_keys)
            yield store.find(object_type, condition)
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:14,代码来源:bulk.py

示例11: add_class

 def add_class(self, cls):
     """Register properties of C{cls} so that they may be found by C{get()}.
     """
     suffix = cls.__module__.split(".")
     suffix.append(cls.__name__)
     suffix.reverse()
     suffix = ".%s." % ".".join(suffix)
     cls_info = get_cls_info(cls)
     for attr in cls_info.attributes:
         prop = cls_info.attributes[attr]
         prop_ref = weakref.KeyedRef(prop, self._remove, None)
         pair = (attr+suffix, prop_ref)
         prop_ref.key = pair
         insort_left(self._properties, pair)
开发者ID:Jokymon,项目名称:timetracker,代码行数:14,代码来源:properties.py

示例12: _primary_key

def _primary_key(object_type, allow_compound=False):
    """Get a primary key our helpers can use.

    :raises AssertionError if the key is missing or unusable.
    """
    primary_key = get_cls_info(object_type).primary_key
    if len(primary_key) == 1:
        return primary_key[0]
    else:
        if not allow_compound:
            raise AssertionError(
                "Compound primary keys are not supported: %s." %
                object_type.__name__)
        return primary_key
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:14,代码来源:bulk.py

示例13: create

def create(columns, values, get_objects=False,
           get_primary_keys=False):
    """Create a large number of objects efficiently.

    :param columns: The Storm columns to insert values into. Must be from a
        single class.
    :param values: A list of lists of values for the columns.
    :param get_objects: Return the created objects.
    :param get_primary_keys: Return the created primary keys.
    :return: A list of the created objects if get_created, otherwise None.
    """
    # Flatten Reference faux-columns into their primary keys.
    db_cols = list(chain.from_iterable(map(dbify_column, columns)))
    clses = set(col.cls for col in db_cols)
    if len(clses) != 1:
        raise ValueError(
            "The Storm columns to insert values into must be from a single "
            "class.")
    if get_objects and get_primary_keys:
        raise ValueError(
            "get_objects and get_primary_keys are mutually exclusive.")

    if len(values) == 0:
        return [] if (get_objects or get_primary_keys) else None

    [cls] = clses
    primary_key = get_cls_info(cls).primary_key

    # Mangle our value list into compilable values. Normal columns just
    # get passed through the variable factory, while References get
    # squashed into primary key variables.
    db_values = [
        list(chain.from_iterable(
            dbify_value(col, val) for col, val in zip(columns, value)))
        for value in values]

    if get_objects or get_primary_keys:
        result = IStore(cls).execute(
            Returning(Insert(
                db_cols, values=db_values, primary_columns=primary_key)))
        keys = map(itemgetter(0), result) if len(primary_key) == 1 else result
        if get_objects:
            return load(cls, keys)
        else:
            return list(keys)
    else:
        IStore(cls).execute(Insert(db_cols, values=db_values))
        return None
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:48,代码来源:bulk.py

示例14: set_item_tax

    def set_item_tax(self, invoice_item, template=None):
        """ Set the tax of an invoice item.

        :param invoice_item: the item of in/out invoice
        """
        template = template or self.get_tax_template(invoice_item)
        if not template:
            return

        for column in get_cls_info(template.__class__).columns:
            if column.name in ['product_tax_template_id', 'te_id', 'id']:
                continue

            value = getattr(template, column.name)
            setattr(self, column.name, value)

        self.set_initial_values(invoice_item)
开发者ID:hackedbellini,项目名称:stoq,代码行数:17,代码来源:taxes.py

示例15: clone

    def clone(self):
        """Get a persistent copy of an existent object. Remember that we can
        not use copy because this approach will not activate ORMObject
        methods which allow creating persitent objects. We also always
        need a new id for each copied object.

        :returns: the copy of ourselves
        """
        warnings.warn("don't use this", DeprecationWarning, stacklevel=2)
        kwargs = {}
        for column in get_cls_info(self.__class__).columns:
            # FIXME: Make sure this is cloning correctly
            name = column.name
            if name in ["id", "identifier", "te_id"]:
                continue
            if name.endswith("_id"):
                name = name[:-3]
            kwargs[name] = getattr(self, name)

        klass = type(self)
        return klass(store=self.store, **kwargs)
开发者ID:stoq,项目名称:stoq,代码行数:21,代码来源:base.py


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