def requires_auth(f):
@wraps(f)<EOL>def decorated(self, *args, **kwargs):<EOL><INDENT>"""<STR_LIT:U+0020>"""<EOL>auth_options = {}<EOL>nipap_args = {}<EOL>if len(args) == <NUM_LIT:1>:<EOL><INDENT>nipap_args = args[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>self.logger.debug("<STR_LIT>" % len(args))<EOL>raise Fault(<NUM_LIT:1000>, ("<STR_LIT>") % len(args))<EOL><DEDENT>if type(nipap_args) != dict:<EOL><INDENT>self.logger.debug("<STR_LIT>")<EOL>raise Fault(<NUM_LIT:1000>, ("<STR_LIT>" %<EOL>type(nipap_args).__name__ ))<EOL><DEDENT>try:<EOL><INDENT>auth_options = nipap_args['<STR_LIT>']<EOL>if type(auth_options) is not dict:<EOL><INDENT>raise ValueError()<EOL><DEDENT><DEDENT>except (KeyError, ValueError):<EOL><INDENT>self.logger.debug("<STR_LIT>")<EOL>raise Fault(<NUM_LIT:1000>, ("<STR_LIT>"))<EOL><DEDENT>try:<EOL><INDENT>auth_source = auth_options['<STR_LIT>']<EOL><DEDENT>except KeyError:<EOL><INDENT>self.logger.debug("<STR_LIT>")<EOL>raise Fault(<NUM_LIT:1000>, ("<STR_LIT>"))<EOL><DEDENT>if not request.authorization:<EOL><INDENT>return authenticate()<EOL><DEDENT>af = AuthFactory()<EOL>auth = af.get_auth(request.authorization.username,<EOL>request.authorization.password, auth_source, auth_options or {})<EOL>if not auth.authenticate():<EOL><INDENT>self.logger.debug("<STR_LIT>")<EOL>raise Fault(<NUM_LIT>, ("<STR_LIT>"))<EOL><DEDENT>new_args = dict(args[<NUM_LIT:0>])<EOL>new_args['<STR_LIT>'] = auth<EOL>return f(self, *(new_args,), **kwargs)<EOL><DEDENT>return decorated<EOL>
Class decorator for XML-RPC functions that requires auth