def register(self, perm_func=None, model=None, allow_staff=None, allow_superuser=None,<EOL>allow_anonymous=None, unauthenticated_handler=None, request_types=None, name=None,<EOL>replace=False, _return_entry=False):
allow_staff = _default(allow_staff, self._allow_staff)<EOL>allow_superuser = _default(allow_superuser, self._allow_superuser)<EOL>allow_anonymous = _default(allow_anonymous, self._allow_anonymous)<EOL>unauthenticated_handler = _default(unauthenticated_handler, self._unauthenticated_handler)<EOL>request_types = _default(request_types, self._request_types)<EOL>if perm_func is None:<EOL><INDENT>return (<EOL>lambda perm_func_:<EOL>self.register(<EOL>perm_func_, model, allow_staff, allow_superuser, allow_anonymous,<EOL>unauthenticated_handler, request_types, name, replace, _return_entry)<EOL>)<EOL><DEDENT>name = _default(name, perm_func.__name__)<EOL>if name == '<STR_LIT>':<EOL><INDENT>raise PermissionsError('<STR_LIT>')<EOL><DEDENT>elif name in self._registry and not replace:<EOL><INDENT>raise DuplicatePermissionError(name)<EOL><DEDENT>view_decorator = self._make_view_decorator(<EOL>name, perm_func, model, allow_staff, allow_superuser, allow_anonymous,<EOL>unauthenticated_handler, request_types)<EOL>entry = Entry(<EOL>name, perm_func, view_decorator, model, allow_staff, allow_superuser, allow_anonymous,<EOL>unauthenticated_handler, request_types, set())<EOL>self._registry[name] = entry<EOL>@wraps(perm_func)<EOL>def wrapped_func(user, instance=NO_VALUE):<EOL><INDENT>if user is None:<EOL><INDENT>return False<EOL><DEDENT>if not allow_anonymous and user.is_anonymous():<EOL><INDENT>return False<EOL><DEDENT>test = lambda: perm_func(user) if instance is NO_VALUE else perm_func(user, instance)<EOL>return (<EOL>allow_staff and user.is_staff or<EOL>allow_superuser and user.is_superuser or<EOL>test()<EOL>)<EOL><DEDENT>register.filter(name, wrapped_func)<EOL>log.debug('<STR_LIT>'.format(name))<EOL>return entry if _return_entry else wrapped_func<EOL>
Register permission function & return the original function.

        This is typically used as a decorator::

            permissions = PermissionsRegistry()
            @permissions.register
            def can_do_something(user):
                ...

        For internal use only: you can pass ``_return_entry=True`` to
        have the registry :class:`.Entry` returned instead of
        ``perm_func``.