Trivial Interfaces and Adaptation from PyProtocols.
This package is a subset of the files from Phillip J. Eby’s PyProtocols package. They are only included here to help remove dependencies on external packages from the Traits package. The code has been reorganized to address circular imports that were discovered when explicit relative imports were added.
Basic Adapters and Adapter Operations
Set up ‘callback’ to be passed the containing class upon creation
This function is designed to be called by an “advising” function executed in a class suite. The “advising” function supplies a callback that it wishes to have executed when the containing class is created. The callback will be given one argument: the newly created containing class. The return value of the callback will be used in place of the class, so the callback should return the input if it does not wish to replace the class.
The optional ‘depth’ argument to this function determines the number of frames between this function and the targeted class suite. ‘depth’ defaults to 2, since this skips this function’s frame and one calling function frame. If you use this function from a function called directly in the class suite, the default will be correct, otherwise you will need to determine the correct depth yourself.
This function works by installing a special class factory function in place of the ‘__metaclass__’ of the containing class. Therefore, only callbacks after the last ‘__metaclass__’ assignment in the containing class will be executed. Be sure that classes using “advising” functions declare any ‘__metaclass__’ first, to ensure all callbacks are run.
Wrapper for metaclass method that might be confused w/instance method
Reduce a list of base classes to its ordered minimum equivalent
Determine metaclass from 1+ bases and optional explicit __metaclass__
Return (kind,module,locals,globals) for a frame
‘kind’ is one of “exec”, “module”, “class”, “function call”, or “unknown”.
Declaration support for Python built-in types
Autogenerated protocols from type+method names, URI, sequence, etc.
Return a protocol representing a subset of methods of a specific type
Return a unique protocol object representing the supplied URI/UUID
Return a protocol representing an sequence of a given base protocol
Bases: traits.protocols.protocols.Interface
Non-string, iterable object sequence
Bases: traits.protocols.protocols.Protocol
Protocol representing a URI, UUID, or other unique textual identifier
Bases: traits.protocols.protocols.Protocol
Protocol representing some set of a type’s methods
Bases: traits.protocols.generate.TypeSubset, object
TypeSubset that accepts any object with the right attributes
Convert iterable ‘ob’ into list of objects implementing ‘proto’
Bases: traits.protocols.protocols.Protocol
Protocol representing a “sequence of” some base protocol
Implement Interfaces and define the interfaces used by the package
Basic Adapters and Adapter Operations
Assume ‘obj’ implements ‘protocol’ directly
Prevent ‘obj’ from supporting ‘protocol’
Bases: object
Convenient base class for adapters
Shortest route to implementation, ‘a1’ @ depth ‘d1’, or ‘a2’ @ ‘d2’?
Assuming both a1 and a2 are interchangeable adapters (i.e. have the same source and destination protocols), return the one which is preferable; that is, the one with the shortest implication depth, or, if the depths are equal, then the adapter that is composed of the fewest chained adapters. If both are the same, then prefer ‘NO_ADAPTER_NEEDED’, followed by anything but ‘DOES_NOT_SUPPORT’, with ‘DOES_NOT_SUPPORT’ being least preferable. If there is no unambiguous choice, and ‘not a1 is a2’, TypeError is raised.
Return the composition of ‘baseAdapter’+’extendingAdapter’
Replace ‘mapping[key]’ w/’adapter’ @ ‘depth’, return true if changed
Bases: object
Adapter that attaches itself to its subject for repeated use
Bases: exceptions.NotImplementedError, exceptions.TypeError
A suitable implementation/adapter could not be found
Backward compatibility: wrap ‘adapter’ to support old 2-arg signature
PEP 246-alike: Adapt ‘obj’ to ‘protocol’, return ‘default’
If ‘default’ is not supplied and no implementation is found, the result of ‘factory(obj,protocol)’ is returned. If ‘factory’ is also not supplied, ‘NotImplementedError’ is then raised.
Declare that ‘adapter’ adapts instances of ‘typ’ to ‘protocol’
Declare that ‘adapter’ adapts ‘proto’ to ‘protocol’
Declare that ‘adapter’ adapts ‘ob’ to ‘protocol’
Declare information about a class, type, or ‘IOpenImplementor’
‘factory’ is an IAdapterFactory providing ‘provides’ protocols
Tell an object what it does or doesn’t provide
Bases: traits.protocols.protocols.AbstractBaseMeta
Metaclass for ‘Interface’ - a non-instantiable protocol
(Note that this should not be used as an explicit metaclass - always subclass from ‘AbstractBase’ or ‘Interface’ instead.)
Bases: object
Base class for a protocol that’s a class
Bases: traits.protocols.protocols.Protocol, type
Metaclass for ‘AbstractBase’ - a protocol that’s also a class
(Note that this should not be used as an explicit metaclass - always subclass from ‘AbstractBase’ or ‘Interface’ instead.)
Bases: traits.protocols.protocols.Interface
Callable that can adapt an object to a protocol
Bases: traits.protocols.protocols.Interface
Object usable as a protocol by ‘adapt()’
Bases: traits.protocols.protocols.IProtocol
A protocol that potentially knows how to adapt some object to itself
Bases: traits.protocols.protocols.IAdaptingProtocol
A protocol that be told what it implies, and what supports it
Note that these methods are for the use of the declaration APIs only, and you should NEVER call them directly.
Bases: traits.protocols.protocols.Interface
An object that can be told how to adapt to protocols
Bases: traits.protocols.protocols.Interface
Object/type that can be told how its instances adapt to protocols
Bases: traits.protocols.protocols.Protocol
A variation of a base protocol - “inherits” the base’s adapters
See the ‘LocalProtocol’ example in the reference manual for more info.