[PEAK] Using attribute bindings within constructor when using Component Factories

Wayne Larsen wayne at larsen.st
Sat Jan 17 19:43:51 EST 2004


Hi,

I've been learning PEAK by 'peakifying' an existing app.  I really like 
what I've seen so far.  However, I believe I've encountered a bug -- if 
it isn't, can you tell me where I went wrong?  The problem is - when 
using the Component Factories method of initialization, accessing an 
attribute binding from the constructor causes the following exception:

   File "/usr/lib/python2.3/site-packages/peak/config/interfaces.py", 
line 107, in noMoreValues
     raise exceptions.InvalidRoot(
peak.exceptions.InvalidRoot: Root component <test1.TestService object at 
0x404f514c> does not implement 'IConfigurationRoot' (was looking up 
peak.naming.initialContextFactory for <test1.TestService object at 
0x404f514c>)

test1.ini
---------

[helloworld]
message = "Hello, world!"

[peak.logs]
* = logs.LogStream(stream=importString('sys.stderr'),level=logs.DEBUG)

[peak.running]
app = importString("test1.Test")

[Component Factories]
test1.ITestService = "test1.TestService"

test1.py
---------

from peak.api import *

class ITestService(protocols.Interface):
     def hello(self):
         """ Say Hello """

class TestService(binding.Component):
     protocols.advise(
         instancesProvide=[ITestService]
         )

     log = binding.Obtain('logger:TestService')
     message = binding.Obtain(PropertyName('helloworld.message'))

     def __init__(self, *__a, **__k):
         binding.Component.__init__(self, *__a, **__k)
	# Removing the following line allows the
         # Component Factories to work properly
         self.log.info(self.message)

     def hello(self):
         self.log.info(self.message)

class Test(running.commands.AbstractCommand):
     log = binding.Obtain('logger:helloworld')
     ts = binding.Obtain(ITestService)

     def _run(self):
         TestService(self).hello()    # This line works fine
         self.ts.hello()	             # This line does not

Thanks,
Wayne






More information about the PEAK mailing list