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


Python datastructures.ImmutableDict方法代码示例

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


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

示例1: obj_ref

# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import ImmutableDict [as 别名]
def obj_ref(obj):
    """Returns a tuple identifying a category/event/contrib/subcontrib"""
    from indico_livesync.models.queue import EntryType
    if isinstance(obj, Category):
        ref = {'type': EntryType.category, 'category_id': obj.id}
    elif isinstance(obj, Event):
        ref = {'type': EntryType.event, 'event_id': obj.id}
    elif isinstance(obj, Session):
        ref = {'type': EntryType.session, 'session_id': obj.id}
    elif isinstance(obj, Contribution):
        ref = {'type': EntryType.contribution, 'contrib_id': obj.id}
    elif isinstance(obj, SubContribution):
        ref = {'type': EntryType.subcontribution, 'subcontrib_id': obj.id}
    else:
        raise ValueError('Unexpected object: {}'.format(obj.__class__.__name__))
    return ImmutableDict(ref) 
开发者ID:indico,项目名称:indico-plugins,代码行数:18,代码来源:util.py

示例2: object_ref

# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import ImmutableDict [as 别名]
def object_ref(self):
        """Return the reference of the changed object."""
        return ImmutableDict(type=self.type, category_id=self.category_id, event_id=self.event_id,
                             session_id=self.session_id, contrib_id=self.contrib_id, subcontrib_id=self.subcontrib_id) 
开发者ID:indico,项目名称:indico-plugins,代码行数:6,代码来源:queue.py

示例3: run

# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import ImmutableDict [as 别名]
def run(
        self,
        requirements,
        identity=None,
        throws=None,
        on_fail=None,
        f_args=(),
        f_kwargs=ImmutableDict(),  # noqa: B008
        use_on_fail_return=True,
    ):
        """
        Used to preform a full run of the requirements and the options given,
        this method will invoke on_fail and/or throw the appropriate exception
        type. Can be passed arguments to call on_fail with via f_args (which are
        passed positionally) and f_kwargs (which are passed as keyword).

        :param requirements: The requirements to check
        :param identity: Optional. A specific identity to use for the check
        :param throws: Optional. A specific exception to throw for this check
        :param on_fail: Optional. A callback to invoke after failure,
            alternatively a value to return when failure happens
        :param f_args: Positional arguments to pass to the on_fail callback
        :param f_kwargs: Keyword arguments to pass to the on_fail callback
        :param use_on_fail_return: Boolean (default True) flag to determine
            if the return value should be used. If true, the return value
            will be considered, else failure will always progress to
            exception raising.
        """

        throws = throws or self.throws
        on_fail = _make_callable(on_fail) if on_fail is not None else self.on_fail

        if not self.fulfill(requirements, identity):
            result = on_fail(*f_args, **f_kwargs)
            if use_on_fail_return and result is not None:
                return result
            raise throws 
开发者ID:justanr,项目名称:flask-allows,代码行数:39,代码来源:allows.py

示例4: __new__

# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import ImmutableDict [as 别名]
def __new__(cls, unit, qty, price, groupby, metadata):
        return _DataPointBase.__new__(
            cls,
            unit or "undefined",
            # NOTE(peschk_l): avoids floating-point issues.
            decimal.Decimal(str(qty) if isinstance(qty, float) else qty),
            decimal.Decimal(str(price) if isinstance(price, float) else price),
            datastructures.ImmutableDict(groupby),
            datastructures.ImmutableDict(metadata),
        ) 
开发者ID:openstack,项目名称:cloudkitty,代码行数:12,代码来源:dataframe.py

示例5: desc

# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import ImmutableDict [as 别名]
def desc(self):
        output = dict(self.metadata)
        output.update(self.groupby)
        return datastructures.ImmutableDict(output) 
开发者ID:openstack,项目名称:cloudkitty,代码行数:6,代码来源:dataframe.py

示例6: as_dict

# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import ImmutableDict [as 别名]
def as_dict(self, legacy=False, mutable=False):
        output = {
            "period": {"begin": self.start, "end": self.end},
            "usage": {
                key: [v.as_dict(legacy=legacy, mutable=mutable) for v in val]
                for key, val in self._usage.items()
            },
        }
        return output if mutable else datastructures.ImmutableDict(output) 
开发者ID:openstack,项目名称:cloudkitty,代码行数:11,代码来源:dataframe.py

示例7: test_as_dict_immutable

# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import ImmutableDict [as 别名]
def test_as_dict_immutable(self):
        point_dict = dataframe.DataPoint(**self.default_params).as_dict()
        self.assertIsInstance(point_dict, datastructures.ImmutableDict)
        self.assertEqual(dict(point_dict), {
            "vol": {"unit": "undefined", "qty": decimal.Decimal(0)},
            "rating": {"price": decimal.Decimal(0)},
            "groupby": {},
            "metadata": {},
        }) 
开发者ID:openstack,项目名称:cloudkitty,代码行数:11,代码来源:test_dataframe.py

示例8: test_default_converters

# 需要导入模块: from werkzeug import datastructures [as 别名]
# 或者: from werkzeug.datastructures import ImmutableDict [as 别名]
def test_default_converters(self):
        class MyMap(r.Map):
            default_converters = r.Map.default_converters.copy()
            default_converters['foo'] = r.UnicodeConverter
        assert isinstance(r.Map.default_converters, ImmutableDict)
        m = MyMap([
            r.Rule('/a/<foo:a>', endpoint='a'),
            r.Rule('/b/<foo:b>', endpoint='b'),
            r.Rule('/c/<c>', endpoint='c')
        ], converters={'bar': r.UnicodeConverter})
        a = m.bind('example.org', '/')
        assert a.match('/a/1') == ('a', {'a': '1'})
        assert a.match('/b/2') == ('b', {'b': '2'})
        assert a.match('/c/3') == ('c', {'c': '3'})
        assert 'foo' not in r.Map.default_converters 
开发者ID:GeekTrainer,项目名称:Flask,代码行数:17,代码来源:routing.py


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