Plone 大脑属性和ipdb自动完成

Plone 大脑属性和ipdb自动完成,plone,Plone,为什么ipdb会话不能用autocomplete显示大脑的每个属性? 例如,brain.UID存在,但未在ipdb自动完成中列出。 这是大脑代码上的黑魔法吗?使用ipdb,您可以自动完成大脑的所有属性: >>> dir(brain) ['__add__', '__allow_access_to_unprotected_subobjects__', '__class__', '__cmp__', '__contains__', '__delattr__', '__delitem_

为什么ipdb会话不能用autocomplete显示大脑的每个属性? 例如,brain.UID存在,但未在ipdb自动完成中列出。
这是大脑代码上的黑魔法吗?

使用ipdb,您可以自动完成大脑的所有属性:

>>> dir(brain)
['__add__', '__allow_access_to_unprotected_subobjects__', '__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__getslice__', '__getstate__', '__hash__', '__implemented__', '__init__', '__len__', '__module__', '__mul__', '__new__', '__of__', '__providedBy__', '__provides__', '__record_schema__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_unrestrictedGetObject', 'getObject', 'getPath', 'getRID', 'getURL', 'has_key']
大脑的元数据不会直接存储在“大脑”中。它们存储在目录的Btree(
数据
属性)中。您可以通过大脑访问存储在数据存储器
中的所有信息

因此,如果您试图访问大脑中不存在的属性,如果该键可用,它将尝试从元数据存储返回值,否则将引发
AttributeError

魔法发生在某处

同时检查第77行:

#目录维护一个对象元数据的B树 在结果页面上方便地显示。元数据属性 被转化成大脑的物体,然后通过 搜索结果

portal_catalog
工具上的ZMI中,有一个
元数据
选项卡,显示所有可访问的元数据信息

更新:

摆弄目录:

>>> plone = app.Plone
>>> catalog = plone.portal_catalog
>>> _catalog = catalog._catalog
>>> brain = catalog()[0]

# Metadata are stored in the data BTree, key is the RID of the brain.
>>> rid = brain.getRID()
>>> rid
704953343

>>> _catalog.data
<BTrees.IOBTree.IOBTree object at 0x10b158150>

>>> _catalog.data[rid]
# The UID is part of this tuple.
('2015-07-22T09:27:09+02:00', 'admin', '2015-07-22T15:12:07+02:00', '', 'None', 'None', '2015-07-22T15:12:07+02:00', (), 'xxx', u'xxx', '38e87a4b80704681b60781b66d37346c', DateTime('2015/07/22 09:27:9.236886 GMT+2'), DateTime('1969/12/31 00:00:00 GMT+2'), Missing.Value, Missing.Value, DateTime('2499/12/31 00:00:00 GMT+2'), '', 'xxx', '0 KB', Missing.Value, 'xxx', True, ('admin',), Missing.Value, 'Dexterity Container', DateTime('2015/07/22 15:12:7.787001 GMT+2'), 'xxx', Missing.Value, Missing.Value, Missing.Value, 0, None, (), Missing.Value, Missing.Value, Missing.Value, Missing.Value)
>plone=app.plone
>>>catalog=plone.portal\u目录
>>>_catalog=目录。_catalog
>>>brain=catalog()[0]
#元数据都存储在数据树中,关键是去掉大脑。
>>>rid=brain.getRID()
>>>摆脱
704953343
>>>_目录数据
>>>_目录数据[rid]
#UID是这个元组的一部分。
(‘2015-07-22T09:27:09+02:00’、‘管理员’、‘2015-07-22T15:07+02:00’、‘无’、‘无’、‘2015-07-22T15:12:07+02:00’、‘xxx’、‘u'xxx’、‘38e87a4b80704681b60781b66d37346c’、‘日期时间’、‘2015/07/22 09:27:9.236886 GMT+2’、‘日期时间’、‘1969/12/31 00:00 GMT+2’、‘缺失的.值、缺失的.值、日期时间(‘2499/12/31:00+2’),'''xxx',0 KB',Missing.Value,'xxx',True,('admin',),Missing.Value,'dextrity Container',DateTime('2015/07/22 15:12:7.787001 GMT+2'),'xxx',Missing.Value,Missing.Value,Missing.Value,0,None,(),Missing.Value,Missing.Value,Missing.Value,Missing.Value)

hi@Mathias,谢谢你的帖子,我学到了很多东西,但我没有给出正确的答案,因为
dir(brain)
不显示所有属性(UID不存在)有没有办法通过ipdb会话访问存储在Btree中的元数据?嗯,UID也不是brain上的属性,它是一个索引,因此只能通过大脑访问。是的,您可以调试:
\u catalog=plonesite.portal\u catalog.\u catalog
,现在,\u catalog有一个属性
data
,它保存所有大脑的所有元数据信息。顺便说一句,关键是去掉大脑。brain.schema()的作用是:)ipdb>brain.schema()['Title','exclude_from_nav','Type','id','end','Description','listCreators','is_folderish','getId','start','ExpirationDate','Date','getRemoteUrl','location','EffectiveDate','portal_Type','expires','ModificationDate','getObjSize','UID','effective','Creator','getIcon','created','modified','meta Type','creati淹没“,”主题“]