Changeset - 1341be63734a
[Not reviewed]
default
0 1 0
Søren Løvborg - 9 years ago 2017-01-02 21:43:53
sorenl@unity3d.com
cleanup: use standard NotImplementedError for abstract methods

From the Python docs on NotImplementedError:

In user defined base classes, abstract methods should raise this
exception when they require derived classes to override the method.
1 file changed with 2 insertions and 4 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/auth.py
Show inline comments
 
@@ -813,26 +813,25 @@ class PermsDecorator(object):
 
        if self.check_permissions():
 
            log.debug('Permission granted for %s %s', cls, self.user)
 
            return func(*fargs, **fkwargs)
 

	
 
        else:
 
            log.debug('Permission denied for %s %s', cls, self.user)
 
            if self.user.is_default_user:
 
                raise _redirect_to_login(_('You need to be signed in to view this page'))
 
            else:
 
                raise HTTPForbidden()
 

	
 
    def check_permissions(self):
 
        """Dummy function for overriding"""
 
        raise Exception('You have to write this function in child class')
 
        raise NotImplementedError()
 

	
 

	
 
class HasPermissionAnyDecorator(PermsDecorator):
 
    """
 
    Checks for access permission for any of given predicates. In order to
 
    fulfill the request any of predicates must be meet
 
    """
 

	
 
    def check_permissions(self):
 
        if self.required_perms.intersection(self.user_perms.get('global')):
 
            return True
 
        return False
 
@@ -921,26 +920,25 @@ class PermsFunction(object):
 
        log.debug('checking cls:%s %s usr:%s %s @ %s', cls_name,
 
                  self.required_perms, user, check_scope,
 
                  check_location)
 
        self.user_perms = user.permissions
 

	
 
        result = self.check_permissions()
 
        result_text = 'granted' if result else 'denied'
 
        log.debug('Permission to %s %s for user: %s @ %s',
 
            check_scope, result_text, user, check_location)
 
        return result
 

	
 
    def check_permissions(self):
 
        """Dummy function for overriding"""
 
        raise Exception('You have to write this function in child class')
 
        raise NotImplementedError()
 

	
 
    def _scope(self):
 
        return '(unknown scope)'
 

	
 

	
 
class HasPermissionAny(PermsFunction):
 
    def check_permissions(self):
 
        if self.required_perms.intersection(self.user_perms.get('global')):
 
            return True
 
        return False
 

	
 
    def _scope(self):
0 comments (0 inline, 0 general)