diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-10-21 18:55:34 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-10-21 18:55:34 +0000 |
| commit | b06b260b83bfc2f40105c6e730f5e7e8eccd61d9 (patch) | |
| tree | ea0d681dbc83e0c88b76135561f41f0bfe90cf46 /repoze/bfg/zcml.py | |
| parent | 0ff9a894dbe1a1d6b71b74649a05bce2a91f5808 (diff) | |
| download | pyramid-b06b260b83bfc2f40105c6e730f5e7e8eccd61d9.tar.gz pyramid-b06b260b83bfc2f40105c6e730f5e7e8eccd61d9.tar.bz2 pyramid-b06b260b83bfc2f40105c6e730f5e7e8eccd61d9.zip | |
- Fix bug encountered during "scan" (when ``<scan ..>`` directive is
used in ZCML) introduced in 1.1a7. Symptom: ``AttributeError:
object has no attribute __provides__`` raised at startup time.
Diffstat (limited to 'repoze/bfg/zcml.py')
| -rw-r--r-- | repoze/bfg/zcml.py | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/repoze/bfg/zcml.py b/repoze/bfg/zcml.py index d08a61303..6bf180b3a 100644 --- a/repoze/bfg/zcml.py +++ b/repoze/bfg/zcml.py @@ -707,8 +707,13 @@ class BFGClassGrokker(object): found = BFGViewGrokker().grok(name, class_, **kw) # grok any decorations attached to the class' method (direct - # methods only, not methods of any base class) - methods = inspect.getmembers(class_, inspect.ismethod) + # methods only, not methods of any base class); we can't use + # inspect.getmembers here because it doesn't deal with a + # corner case where objects that inherit from Persistent + # advertises a '__provides__' as per dir(ob) but getattr(ob, + # '__provides__') raises an AttributeError. Unknown why this + # happens, but it doesn't matter: need to deal with it. + methods = getmembers(class_, inspect.ismethod) classmethods = class_.__dict__.keys() for method_name, method in methods: if method_name in classmethods: @@ -739,3 +744,19 @@ class Uncacheable(object): this class only exists for backwards compatibility (<0.8.1)""" file_configure = zcml_configure # backwards compat (>0.8.1) + +def getmembers(object, predicate=None): + """Return all members of an object as (name, value) pairs sorted + by name. Optionally, only return members that satisfy a given + predicate. Differs from inspect.getmembers inasmuch as it ignores + AttributeErrors.""" + results = [] + for key in dir(object): + try: + value = getattr(object, key) + except AttributeError: + continue + if not predicate or predicate(value): + results.append((key, value)) + results.sort() + return results |
