[PEAK] ZConfig and peak naming

Phillip J. Eby pje at telecommunity.com
Fri Jul 30 10:54:02 EDT 2004

At 11:52 AM 7/30/04 +0200, Roché Compaan wrote:

>Roché Compaan wrote:
>>Roché Compaan wrote:
>>>* Phillip J. Eby <pje at telecommunity.com> [2004-07-29 23:20]:
>>>>Do something like this:
>>>>    class Process(binding.Component):
>>>>        fileURL = binding.Require("URL needed",
>>>>        file = binding.Obtain(naming.Indirect('fileURL'))
>>>>And make the 'attribute' for 'file' be 'fileURL' instead.
>>>>'naming.Indirect("some_name")' translates to, "use the object you find 
>>>>at 'some_name' as a name to look up".
>>>Nice! Thanks a lot.

I goofed; the 'adaptTo=naming.IStreamFactory' should've been on 'file', not 

>I just tried a couple of shorter permutations:
>class Process(...):
>     ...
>     fileURL = binding.Require("URL needed")
>     file = binding.Obtain(
>         naming.toName(naming.Indirect('fileURL'), FileURL.fromFilename),
>         adaptTo=naming.IStreamFactory)
>         peak.exceptions.InvalidName: <peak.naming.names.Indirect object 
> at 0x4070102c>
>Then I tried:
>    file = binding.Obtain(
>        naming.Indirect('fileURL'),
>        adaptTo=[naming.IStreamFactory])
>protocols.adapters.AdaptationFailure: ("Can't adapt", 
><peak.naming.factories.openable.FileFactory object at 0x404f8bcc>, [<class 

Don't use '[]' on the adaptTo.  It accepts only a single protocol, not a 
list of protocols.

>Which is weird since, FileFactory's instances provide 
>naming.IStreamFactory. Why does adaptation fail if the instance provides 
>the correct interface?
>Ok, so looking at the error above, naming.Indirect('fileURL') already 
>resolves to a FileFactory.
>Finally, just:
>     file = binding.Obtain(naming.Indirect('fileURL'))
>worked! If I print "process.file" I correctly have a FileFactory. After 
>looking at naming.Indirect and binding.Obtain it made sense though.

Yep, and if you add 'adaptTo=naming.IStreamFactory', that will also work in 
cases where the URL doesn't directly create a stream factory, but can adapt 
to one.  (Not that I know of any such scenarios right now, I just generally 
prefer to specify what interface I'm looking for when loading objects from 
the naming system.)

More information about the PEAK mailing list