From e2fca426d9361e9180457d5a89b90be836cdf034 Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Wed, 21 Nov 2012 14:43:37 +0100 Subject: [PATCH 1/3] Return early for attributes that begin with two underscores (typically '__conform__'). --- plone/dexterity/content.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plone/dexterity/content.py b/plone/dexterity/content.py index bdb1bda..5bf69c2 100644 --- a/plone/dexterity/content.py +++ b/plone/dexterity/content.py @@ -177,10 +177,12 @@ class DexterityContent(DAVResourceMixin, PortalContent, DefaultDublinCoreImpl, C description = u'' def __getattr__(self, name): - # attribute was not found; try to look it up in the schema and return # a default - + + if not name.startswith('__'): + raise AttributeError(name) + schema = SCHEMA_CACHE.get(self.portal_type) if schema is not None: field = schema.get(name, None) From 8b85633bfefca7ec0f1f255b472c9ee33f9128f7 Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Wed, 21 Nov 2012 15:02:57 +0100 Subject: [PATCH 2/3] Include a small comment on this optimization. --- plone/dexterity/content.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plone/dexterity/content.py b/plone/dexterity/content.py index 5bf69c2..8bbc632 100644 --- a/plone/dexterity/content.py +++ b/plone/dexterity/content.py @@ -177,12 +177,15 @@ class DexterityContent(DAVResourceMixin, PortalContent, DefaultDublinCoreImpl, C description = u'' def __getattr__(self, name): - # attribute was not found; try to look it up in the schema and return - # a default - + # optimization: sometimes we're asked for special attributes + # such as __conform__ that we can disregard (because we + # wouldn't be in here if the class had such an attribute + # defined). if not name.startswith('__'): raise AttributeError(name) + # attribute was not found; try to look it up in the schema and return + # a default schema = SCHEMA_CACHE.get(self.portal_type) if schema is not None: field = schema.get(name, None) From 00a098bc151f911135666877599613bc432f2d67 Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Fri, 23 Nov 2012 14:32:50 +0100 Subject: [PATCH 3/3] Update plone/dexterity/content.py Oops. --- plone/dexterity/content.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plone/dexterity/content.py b/plone/dexterity/content.py index 8bbc632..cf1caf6 100644 --- a/plone/dexterity/content.py +++ b/plone/dexterity/content.py @@ -181,7 +181,7 @@ class DexterityContent(DAVResourceMixin, PortalContent, DefaultDublinCoreImpl, C # such as __conform__ that we can disregard (because we # wouldn't be in here if the class had such an attribute # defined). - if not name.startswith('__'): + if name.startswith('__'): raise AttributeError(name) # attribute was not found; try to look it up in the schema and return