大脑属性和 ipdb 自动完成

Brain attributes and ipdb autocomplete

为什么 ipdb 会话不显示具有自动完成功能的大脑的每个属性? 例如 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']

大脑的元数据不直接存储在 "brain" 上。它们存储在目录上的 Btree(data 属性)中。您可以访问存储在数据存储 through 大脑中的所有信息。

因此,如果您尝试访问大脑中不存在的属性,如果密钥可用,它将尝试 return 元数据存储中的值,否则 AttributeError 被引发.

奇迹发生在某处here (ZCatalog)

同时检查第 77 行:

# The catalog maintains a BTree of object meta_data for convenient display on result pages. meta_data attributes are turned into brain objects and returned by searchResults.

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

更新:

摆弄目录:

>>> 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)