python编码实用程序的集合

pytilities的Python项目详细描述


pytilities是python3实用程序库。

功能

  • 面向方面编程:
    • 创建方面以捆绑建议
    • 将通知应用于实例的任何属性或类的所有实例。 甚至可以应用于实例上不存在的属性(即 创建它)。也可以应用于对象的任何属性。
  • 事件调度:带有包装器的类似观察者/主题的事件调度 用于隐藏调度器上的事件和组合调度器
  • 函数重载
  • 基本几何:矢量,矩形类
  • 各种:跨平台无穷大数,…

更改日志

1.2.0

pytilities.aop

建议现在是更多的吻。你把你的建议编入一本简单的字典里,而不是 使用建议。“*”建议现在不存在了,您可以使用特殊的 类似字典的对象:pytilities.dictionary.functionmap。它允许“*” 建议等等。

Changed:
  • Aspect:
    • Added:
      • _advice_mappings: Mapping of (access, attribute_name) to advice. Note that ‘*’ is not a valid attribute_name, use FunctionMap instead of the old ‘*’ advice. If you use FunctionMap you should set _undefined_keys to True.
      • _undefined_keys: set to True if _advice_mappings provides infinite mappings
    • Removed:
      • _advise: use _advice_mappings instead
Fixed:
  • fixed a special case of invalid call advising, see pytilities.test.aop.calladvisespecialcase

pytilities.aop.方面
Fixed:
  • View: the aspect did not correctly enable its aspect upon calling callables through the view

pytilities.委派

代表团现在更亲了。复杂的profile类被删除 普通字典(以及pytilities.dictionary的字典)。配置文件中的 替换为更灵活的“接吻”>映射>。

Added:
  • mapped: adds an attribute to a mapping in a format that can be used as argument to DelegationAspect. You could also use it as a base for the _advice_mappings of your Aspect, …
  • mapped_class: required on a class for mapped to work
Changed:
  • DelegationAspect:
    • no longer expects a Profile parameter, instead it expects a mapping of (access, source_attribute_name) to target_attribute_name; where access is ‘get’, ‘set’, or ‘delete’, as opposed to ‘r’, ‘w’, or ‘d’.
Removed:
  • profile_carrier: use mapped_class instead
  • in_profile: use mapped instead
  • Profile: replaced by plain dictionaries (This is more flexible and KISS than the vague Profile interface)

pytilities.dictionary(新)

Added:
  • FunctionMap: A Mapping that uses a function to generate its values

pytilities.event

Changed:
  • DispatcherSwitch: now has its ‘delegation profile’ stored in public_mapping
  • Dispatcher: now has its ‘delegation profile’ stored in public_mapping and default_mapping

pytilities.测试
Changed:
  • is_private: now only returns True for names matching __name or _SomeClass_name.
Fixed:
  • is_special: returned False on special attributes

1.1.0

pytilities.aop

使AOP更容易理解、使用(和维护):

  • 类和实例建议之间的区别现在可能会被遗忘,有 只有忠告。类现在充当通配符,例如aspect.apply(类)意味着 应用于类和类本身的所有实例。
  • 现在可以将方面应用于类中的所有实例,然后排除 从那条建议中举例说,事后不采纳它。

提高了测试覆盖率(现在减少了bug)。

Added:
  • advisor.get_applied_aspects(obj)
  • AOPException
  • yield suppress_aspect: context manager that prevents the current aspect from having its advice executed till the end of the context
  • yield advised_attribute: replaces (yield name, yield advised).
  • yield advised_instance: returns the instance to which the aspect was applied (or the class in case the advised is a static/class method)
Changed:
  • Aspect:
    • _advise: You can no longer advise a member more than once. This includes trying to advise ‘*’ and some regular member at the same time. (this makes Aspect more KISS, you can workaround this limitation using multiple aspects)
    • is_enabled: now returns False for objects to which it is not applied
    • apply: now applies the aspect to all instances of cls and cls itself when supplied a class
    • unapply: now unapplies the aspect on all instances of cls and cls itself when supplied a class
    • unapply_all: now unapplies all aspects on all instances of cls and cls itself when supplied a class
    • is_applied: returns True, if given object is in advisor.get_applied_aspects(obj)
Removed:
  • yield name: Removed in favor of the clearer yield advised_attribute

  • yield advised: Removed in favor of the clearer yield advised_attribute

  • yield obj: Removed in favor of the clearer yield advised_instance

  • Support for advising modules: It has become too hard too maintain this feature while there are decent workarounds for this lack:

    • Put your functions in a class with staticmethods or classmethods
    • Or use the singleton pattern.

    And then apply the aspect to that class.

Fixes:
  • advisor.unapply_all: forgot to implement it
  • yield advised returned the wrong callable on call access
  • When trying to get an unexisting attribute after having had advice applied and unapplied to it, the object would no longer throw AttributeError on get access
  • Aspect.enable and Aspect.disable had no effect

pytilities.aop.方面
Added:
  • ImmutableAttributeException
Changed:
  • ImmutableAspect: as required by the fix (see below): - it can now only be applied on objects with AOPMeta as metaclass - it now raises ImmutableAttributeException on attempts to mutate
Fixes:
  • create_view: did not enable its aspect on access
  • ImmutableAspect: it only worked for detecting change on setters, it now detects every change.

pytilities.描述符

添加和重构测试

Added:
  • DereferencedBoundDescriptor: like BoundDescriptor but takes 2 descriptors as args that are dereferenced(/read/getted) on each call.
Changed:
  • BoundDescriptor:

    • special_dereference parameter was removed
    • instance arg will no longer be dereferenced when a descriptor arg is passed

    If you need any of the two above, use DereferencedBoundDescriptor. (splitting the class in two like this would make it more intuitive to use)

1.0.1

在版本中包含project.py,以便可以运行单元测试

1.0.0

库移到python3,旧的python版本不再受支持。 有很多变化,打破了相当多以前的界面。全部 更改如下所示。

效用

Added:
  • get_annotations: gets annotations of an object, allows to add new ones, …
  • get_attr_name, get_attr_value, has_attr_name, has_attr_value: gets an attribute, bypassing regular lookup (no descriptor.__get__, …, does support inheritance though)
Removed:
  • AttributeCollection, AttributeCollectionBase: use aop instead (see User Guide)
Changed:
  • mangle:
    • You can now pass an instance as well.
    • Small fix involving class names that start with a ‘_’

pytilities.aop

这个包为python带来了面向方面的语言特性(非常方便 格式)。您可以对类和实例应用建议,使用可以 应用和未应用、启用、禁用,…

Added:
  • advisor: singleton that aspects use to give advice (you shouldn’t use this directly, derive from Aspect and use its methods instead)
  • proceed, return_close, return_, arguments, advised, obj, name yields for advice functions
  • Aspect: base class to write your own aspects with (you are not required to use this, but it is greatly recommended)
  • AOPMeta: classes that are given * advice require to have AOPMeta as metaclass, other advised classes may benefit from this metaclass as it reduces memory usage

pytilities.委派
Added:
  • DelegationAspect: delegate attributes from a source instance/cls to a target. Only supports direct mappings (mappings with the same source and target attributes).
  • in_profile, profile_carrier: used to more easily place some profiles on a class
Changed:
  • Profile
Removed:
  • Delegator, DelegatorFactory: use delegate or any of the other possibilities listed in the User Guide instead
  • delegator_factory: use profile_carrier instead.
  • delegated: use in_profile instead.
  • delegate: use DelegationAspect instead. You may want to read about AOP in the user guide first

pytilities.descriptors(新)

Added:
  • AttributeDescriptor: turns a regular attribute into a descriptor
  • DereferencedDescriptor: returns inner_desc.get.get, sets inner_desc.get.set, …
  • BoundDescriptor: binds an instance to a descriptor, much like bound methods
  • RestrictedDescriptor: strip of the get, set or del of a descriptor

pytilities.event

Removed:
  • dispatcher, dispatcherswitch (decorators): normally you’d send events from an aspect as it’s a crosscutting concern, so these no longer have to be supported. Use a custom Aspect + DelegationAspect instead.

pytilities.几何图形
Added:
  • DiscreteVector, DiscreteRectangle: A Vector/Rectangle with a discrete coordinate space. All aspects and views for Vector/Rectangle work on these as well.
  • verbose_rectangle_aspect, verbose_vector_aspect: Aspects to make a Rectangle/Vector send out (change) events.
  • ImmutableRectangle, ImmutableVector: immutable views of a Rectangle/Vector
  • immutable_rectangle_aspect, immutable_vector_aspect: makes a Rectangle/Vector immutable
Changed:
  • Vector, Rectangle: Due to a change in int division mechanisms in python3, these classes will always operate with a continuous coordinate space. I.e if your vector has coords (3, 1), then when divided by 2 they become (1.5, 0.5) and not (1, 0) as they used to be in previous versions. Use DiscreteVector and DiscreteRectangle instead, to get similar behaviour back.
  • Vector, DiscreteVector: have an extra overload for assign that accepts (x,y) as args
Removed:
  • BoundVector: use Vector directly instead (use its bound properties overload)
  • VerboseVector: make a Vector and do verbose_vector_aspect.apply(v) instead. This works for DiscreteVectors as well.
  • VerboseRectangle: make a Rectangle and do verbose_rectangle_aspect.apply(v) instead. This works for DiscreteVectors as well.

pytilities.重载

Changed:
  • overloaded: its returned function now has a process_args method as well
  • Parameter: its ctor was incorrectly overloaded (ironically). This has been fixed, its overloads changed slightly because of this.

pytilities.infinity(新)

提供了float('inf')的跨平台替代方案。

Added:
  • infinity, negative_infinity, nan
  • is_infinity

pytilities.测试
Added:
  • is_public, is_protected, is_private, is_special: attribute name checks

0.1.4

  • mangle、mangle和event.dispatcher:修复了一个轻微的名称冲突
  • 经过全面检查的测试,现在更易于使用
  • 删除了delegatorfactory的继承特性,太模糊了
  • 删除了初始授权配置文件,还有其他方法可以达到同样的效果 事情
  • 更改了delegatorfactory接口,希望它更直观 使用
  • 已将所有集合运算符添加到委托人简介
  • 添加了更多测试并修复了一些docstring
  • restricteddispatcher:允许和不允许互斥。它使不 指定两者的意义

0.1.3

  • 添加了HTML参考文档

0.1.2

  • 添加了runtests.py,它允许运行单元测试
  • 添加了Types软件包(在上一个版本中忘记了这一点)

0.1.1

  • 修正:最后一个版本无法解析

0.1.0

  • 初始版本:委派工具、事件、重载,…

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

推荐PyPI第三方库


热门话题
java使用McClickListener单击了什么元素   Java时间戳在Oracle时间戳中不同情况下存储12 PM的奇怪行为   java无法使用事件总线对运行在不同机器上的垂直体进行通信   java Mockserver:收到请求后进行回调   java无法将Json字符串转换为Map<string,Object>   java如何按升序排列输出?   java视图行,带有oracle键。jbo。在SrCategoryParentIterator中找不到键[300100120394155]   javafxmysql连接示例   java正在等待加载完成   java是否可以将同一个有状态会话bean实例注入多个其他会话bean?   java无法让万向节检测离开或进入区域   使用JavaCV和OpenCV的java提供了dyld:lazy符号绑定失败:找不到符号:__sincos_stret   xml解析无法使用Java读取xml文档   java无法更改工具栏的颜色   javaapachesshd和JSCH   java无法在firebase存储中检索图像url   java问题与executeUpdate   同一应用程序中不同活动之间的java SharedReference