From 1f8536956af7e122007da369d35924c28dd99c25 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Wed, 29 Dec 2010 17:47:35 -0500 Subject: simplify guard logic for __action_decorator__ --- pyramid/config.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pyramid/config.py b/pyramid/config.py index e1005102b..e717556d9 100644 --- a/pyramid/config.py +++ b/pyramid/config.py @@ -4,7 +4,6 @@ import re import sys import threading import traceback -from types import FunctionType import venusian @@ -940,14 +939,17 @@ class Configurator(object): action_decorator = getattr(handler, '__action_decorator__', None) if action_decorator is not None: - class_or_static = getattr(action_decorator, 'im_self', - None) is not None - if not class_or_static: - class_or_static = isinstance(action_decorator, FunctionType) - if not class_or_static: - raise ConfigurationError( - 'The "__action_decorator__" callable on a handler class ' - 'MUST be defined as a classmethod or a staticmethod.') + if hasattr(action_decorator, 'im_self'): + # instance methods have an im_self == None + # classmethods have an im_self == cls + # staticmethods have no im_self + # instances have no im_self + if action_decorator.im_self is not handler: + raise ConfigurationError( + 'The "__action_decorator__" attribute of a handler ' + 'must not be an instance method (must be a ' + 'staticmethod, classmethod, function, or an instance ' + 'which is a callable') path_has_action = ':action' in pattern or '{action}' in pattern -- cgit v1.2.3