[PEAK] Feedback wanted: PyProtocols 1.0 convenience API
Phillip J. Eby
pje at telecommunity.com
Thu Oct 14 17:52:43 EDT 2004
Here are some quick samples of a "straw man" PyProtocols API for version
1.0, using Python 2.4 decorator syntax for function declarations. (For
backward compatibility w/2.3 and 2.2, the proposed "@"-style decorators
would also be usable using [decorator(args)] syntax.) Feedback from
PyProtocols users would be most helpful.
from protocols import performs, provides, module_provides
from protocols import instances_provide, class_provides
@performs(IFoo)
def afunc(...):
"""Perform the behavior defined by IFoo.__call__"""
@provides(
IFoo, IBaz,
for_protocols=[IBar],
for_types=[int],
)
def adapterfunc(ob):
"""Wrap 'ob' (an int or IBar) as an IFoo and IBaz"""
# This module provides IFoo
module_provides(IFoo)
class Foo:
instances_provide(
IFoo, IBaz, ISpam,
for_types=[int]
for_protocols=[IBar]
)
class_provides(IBar,ISpamClass)
class Bar:
instances_provide(IBar)
More information about the PEAK
mailing list