具有堆叠上下文数据的python dict

py-context的Python项目详细描述


https://badge.fury.io/py/py-context.pnghttps://travis-ci.org/dealertrack/py-context.png?branch=masterhttps://coveralls.io/repos/dealertrack/py-context/badge.png?branch=master

具有堆叠上下文数据的python dict

安装

您可以使用pip:

安装py-context
$ pip install py-context

示例

>>> context = Context({'user': 'Fred', 'city': 'Bedrock'})
>>> context['user']
'Fred'
>>> context['city']
'Bedrock'
>>> context.push({'user': 'Barney'})
>>> context['user']
'Barney'
>>> context['city']
'Bedrock'
>>> context.pop()
{'user': 'Barney'}
>>> context['user']
'Fred'

上下文也支持信号。 信号处理器可以全局附加:

>>> @context_key_changed.connect
... def handler(sender, context, key, new, old):
...     print(key, new, old)

>>> context = Context()
>>> context['hello'] = 'world'
hello world <Missing>

或单个上下文实例:

>>> def handler(sender, context, key, new, old):
...     print(key, new, old)
>>> context = Context()
>>> context_key_changed.connect(handler, sender=context)

支持的信号:

>>> @context_initialized.connect
... def handler(sender, context):
...     pass

>>> @pre_context_changed.connect
... def handler(sender, context):
...     pass

>>> @post_context_changed.connect
... def handler(sender, context):
...     pass

>>> @context_key_changed.connect
... def handler(sender, context, key, new, old):
...     pass

另外,ClassSignallingContext可以用于订阅信号 按发件人类,而不是实例:

>>> class TestContext(ClassSignallingContext):
...     pass
>>> def context_key_changed_handler(sender, context, key, new, old):
...     print(key, new, old)
>>> _ = context_key_changed.connect(context_key_changed_handler, sender=TestContext)

>>> context = Context()
>>> class_context = TestContext()

>>> context['foo'] = 'bar'
>>> class_context['foo'] = 'bar'
foo bar <Missing>

测试

要运行测试,您需要首先安装测试要求:

$ make install

然后,要运行测试,您可以使用nosetests或简单地使用makefile命令:

$ nosetests -sv
# or
$ make test

历史记录

0.3.1(2018-04-11)

  • Context.push()中添加了对*args**kwargs的支持。
  • 添加了__dir__支持。

0.3.0(2018-02-16)

  • 添加了信号支持-context_initializedpre_context_changedpost_context_changedcontext_key_changed。有关示例,请参阅自述文件。

0.2.1(2017-07-28)

  • 不包括正在安装的测试

0.2.0(2017-05-11)

  • 添加属性支持
  • 添加make watch target

0.1.0(2017-03-22)

  • pypi上的第一个版本。

学分

最初Context来自Genshi项目。 有关版权声明,请参见LICENSE

开发领导

贡献者

版权所有(c)2006-2010 Edgewall软件

版权所有(c)2017 Dealertrack Technologies,Inc.

保留所有权利。

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in
   the documentation and/or other materials provided with the
   distribution.
3. The name of the author may not be used to endorse or promote
   products derived from this software without specific prior
   written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Java:删除并重新创建对象   HttpObjectAggregator上的java Netty 4泄漏异常   即使测试失败,java Gradle也会在测试阶段后执行任务   java更新JComboBox后,如何刷新框的长度   java当我单击按钮时,我的应用程序意外停止   java SpringBoot 2.2.1 groovyMarkupConfigurer异常   java spring webflux:如何从同步调用发布事件以进行异步处理?   java Viewpager“ViewGroup”更改背景色运行时   JavaJTree:检查选择的级别   java我想在所有网站href链接上添加前缀   java如何生成无分支代码?   用Java在DrawingCanvas上创建线条   使用jpos api的java打包子字段   Java映射到对象而不是另一个对象的现有方法可选<>吗?   java添加更改图形颜色的按钮