[PEAK] ZConfig and peak naming

Roché Compaan roche at upfrontsystems.co.za
Fri Jul 30 03:59:22 EDT 2004


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", 
>>        adaptTo=naming.IStreamFactory)
>>        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.

That was premature joy :-( I get the following error:

protocols.adapters.AdaptationFailure: ("Can't adapt", 
'pkgfile:jack/notes.txt', <class 'peak.naming.interfaces.IStreamFactory'>)

So now I create a naming.URL instance from 'fileURL', and that adapts 
fine to 'IStreamFactory':

class Process(binding.Component):
     ...
     fileURL = binding.Require("URL needed")
     file = binding.Obtain(naming.Indirect('_fileURL'),
         adaptTo=naming.IStreamFactory)

     def _fileURL(self):
         from peak.naming.factories.openable import FileURL
         return naming.toName(self.fileURL, FileURL.fromFilename)
     _fileURL = binding.Make(_fileURL)

But if there is a sweet 2 liner that can do the job, I'd like to know 
about it :-)

-- 
Roché Compaan
Upfront Systems                 http://www.upfrontsystems.co.za



More information about the PEAK mailing list