Basic Adapters and Adapter Operations
Functions
|
|
DOES_NOT_SUPPORT
IMPLEMENTATION_ERROR
NO_ADAPTER_NEEDED
composeAdapters
minimumAdapter
updateWithSimplestAdapter
|
|
DOES_NOT_SUPPORT
|
DOES_NOT_SUPPORT ( obj, protocol )
Prevent obj from supporting protocol
|
|
IMPLEMENTATION_ERROR
|
IMPLEMENTATION_ERROR ( obj, protocol )
Raise NotImplementedError when adapting obj to protocol
Exceptions
|
|
NotImplementedError( "Can't adapt", obj, protocol )
|
|
|
NO_ADAPTER_NEEDED
|
NO_ADAPTER_NEEDED ( obj, protocol )
Assume obj implements protocol directly
|
|
composeAdapters
|
composeAdapters (
baseAdapter,
baseProtocol,
extendingAdapter,
)
Return the composition of 'baseAdapter'+extendingAdapter
|
|
minimumAdapter
|
minimumAdapter (
a1,
a2,
d1=0,
d2=0,
)
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.
Exceptions
|
|
TypeError( "Ambiguous adapter choice", a1, a2, d1, d2 )
|
|
|
updateWithSimplestAdapter
|
updateWithSimplestAdapter (
mapping,
key,
adapter,
depth,
)
Replace 'mapping[key]' w/adapter @ depth , return true if changed
|
Classes
|
|
Adapter |
Convenient base class for adapters
|
StickyAdapter |
Adapter that attaches itself to its subject for repeated use
|
|
|