具有堆叠上下文数据的python dict
py-context的Python项目详细描述
具有堆叠上下文数据的python dict
- 自由软件:麻省理工学院许可证
- Github:https://github.com/dealertrack/py-context
安装
您可以使用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_initialized,pre_context_changed, post_context_changed和context_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。
开发领导
- 米罗斯拉夫·舒伯内茨基-https://github.com/miki725
贡献者
- 谢尔坎·霍斯卡-https://github.com/shosca
版权所有(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.