[sagenb] 43/179: simplified the _require_ldap decorator

felix salfelder felix-guest at moszumanska.debian.org
Tue May 6 12:05:08 UTC 2014


This is an automated email from the git hooks/post-receive script.

felix-guest pushed a commit to branch master
in repository sagenb.

commit 6b657ff88f3dbd0580a3f8339de205147422540e
Author: Robin Martinjak <rob at rmartinjak.de>
Date:   Tue Dec 4 00:28:07 2012 +0100

    simplified the _require_ldap decorator
---
 sagenb/notebook/auth.py | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/sagenb/notebook/auth.py b/sagenb/notebook/auth.py
index 5bde75b..3d576ae 100644
--- a/sagenb/notebook/auth.py
+++ b/sagenb/notebook/auth.py
@@ -37,27 +37,23 @@ class LdapAuth(AuthMethod):
     search string
     """
 
-    def _require_ldap(retval):
+    def _require_ldap(default_return):
         """
         function decorator to
             - disable LDAP auth
-            - return the decorator argument "retval" instead of calling the
-              actual function
+            - return a "default" value (decorator argument)
         if importing ldap fails
         """
         def wrap(f):
-            try:
-                from ldap import __version__ as ldap_version
-
-                def wrapped_f(self, *args, **kwargs):
-                    return f(self, *args, **kwargs)
-
-            except ImportError:
-
-                def wrapped_f(self, *args, **kwargs):
+            def wrapped_f(self, *args, **kwargs):
+                try:
+                    from ldap import __version__ as ldap_version
+                except ImportError:
+                    print "cannot 'import ldap', disabling LDAP auth"
                     self._conf['auth_ldap'] = False
-                    return retval
-
+                    return default_return
+                else:
+                    return f(self, *args, **kwargs)
             return wrapped_f
         return wrap
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/sagenb.git



More information about the debian-science-commits mailing list