[PEAK] naming.lookup() vs config.lookupComponent()

Doug Quale quale1 at charter.net
Mon Jun 21 23:02:38 EDT 2004

"Phillip J. Eby" <pje at telecommunity.com> writes:

> At 06:53 PM 6/21/04 -0500, Doug Quale wrote:
> >Why does the naming.lookup() try fail, and what is the difference
> >between root.lookupComponent() and naming.lookup()?
> By default, anObj.lookupComponent() "suggests" to the found component
> that 'anObj' is the found component's "parent" component.
> naming.lookup() just looks up the object in question.
> I'm surprised, though, that your experiment hangs, as opposed to
> producing some kind of error complaining about the absence of a
> configuration root.

Thanks for the explanation.  I was scratching my head over this, but
it appears that the sequence

root = config.makeRoot()
cx = naming.lookup(root, URL)
cu = cx(my_query)

leaves cu bound to a SQLCursor whose parentComponent is the cx
PsycopgConnection whose parent is the SQLCursor.  When I break the
hang with ^C:

Python 2.3.4 (#2, Jun 19 2004, 18:15:30) 
[GCC 3.3.4 (Debian)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> ## working on region in file /tmp/python-14881DNB.py...
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/tmp/python-14881DNB.py", line 10, in ?
    cu = cx('select * from pg_tables')
  File "/usr/local/lib/python2.3/site-packages/peak/storage/connections.py", line 265, in __call__
  File "/usr/local/lib/python2.3/site-packages/peak/storage/SQL.py", line 130, in execute
  File "/usr/local/lib/python2.3/site-packages/peak/storage/connections.py", line 232, in joinTxn
    return self.joinedTxn
  File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 112, in _once.BaseDescriptor.__get__
  File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 100, in _once.__get__
  File "/usr/local/lib/python2.3/site-packages/peak/storage/transactions.py", line 382, in joinedTxn
    ts = self.txnSvc
  File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 112, in _once.BaseDescriptor.__get__
  File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 100, in _once.__get__
  File "/usr/local/lib/python2.3/site-packages/peak/binding/components.py", line 524, in computeValue
    return self.targetName.findComponent(obj, self.default)
  File "/usr/local/lib/python2.3/site-packages/peak/binding/components.py", line 395, in findComponent
    return config.lookup(component, self.ob, default)
  File "/usr/local/lib/python2.3/site-packages/peak/config/config_components.py", line 87, in lookup
    for value in iterValues(component, configKey):
  File "/usr/local/lib/python2.3/site-packages/peak/config/config_components.py", line 62, in iterValues
    for component in iterParents(component):
  File "/usr/local/lib/python2.3/site-packages/peak/config/config_components.py", line 52, in iterParents
    component = getParentComponent(component)
  File "/usr/local/lib/python2.3/site-packages/peak/binding/components.py", line 139, in getParentComponent
    return gpc()
  File "/usr/local/lib/python2.3/site-packages/peak/binding/components.py", line 881, in getParentComponent
    return self.__parentComponent
>>> cx
<peak.storage.SQL.PsycopgConnection object at 0x40592dec>
>>> cx.getParentComponent()
<peak.storage.SQL.SQLCursor object at 0x4059288c>
>>> cx.getParentComponent().getParentComponent()
<peak.storage.SQL.PsycopgConnection object at 0x40592dec>
>>> cx.getParentComponent().getParentComponent().getParentComponent()
<peak.storage.SQL.SQLCursor object at 0x4059288c>

I'm not sure how the cursor gets to be the connection's parent.

More information about the PEAK mailing list