<s> """<STR_LIT>""" <EOL> try : <EOL> from xmlrpc . client import Fault <EOL> except ImportError : <EOL> from xmlrpclib import Fault <EOL> from django . contrib . auth import authenticate <EOL> from django . utils . translation import gettext as _ <EOL> AUTHENTICATION_FAILED_CODE = <NUM_LIT> <EOL> PERMISSION_DENIED_CODE = <NUM_LIT> <EOL> class AuthenticationFailedException ( Fault ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> Fault . __init__ ( self , AUTHENTICATION_FAILED_CODE , <EOL> _ ( '<STR_LIT>' ) ) <EOL> class PermissionDeniedException ( Fault ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> Fault . __init__ ( self , PERMISSION_DENIED_CODE , _ ( '<STR_LIT>' ) ) <EOL> def xmlrpc_method ( returns = '<STR_LIT:string>' , args = None , name = None ) : <EOL> """<STR_LIT>""" <EOL> if args is None : <EOL> args = [ ] <EOL> def _xmlrpc_func ( func ) : <EOL> """<STR_LIT>""" <EOL> func . _xmlrpc_signature = { <EOL> '<STR_LIT>' : returns , <EOL> '<STR_LIT:args>' : args <EOL> } <EOL> return func <EOL> return _xmlrpc_func <EOL> xmlrpc_func = xmlrpc_method <EOL> def permission_required ( perm = None ) : <EOL> """<STR_LIT>""" <EOL> def _dec ( func ) : <EOL> """<STR_LIT>""" <EOL> def __authenticated_call ( username , password , * args ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> user = authenticate ( username = username , password = password ) <EOL> if not user : <EOL> raise AuthenticationFailedException <EOL> if perm and not user . has_perm ( perm ) : <EOL> raise PermissionDeniedException <EOL> except AuthenticationFailedException : <EOL> raise <EOL> except PermissionDeniedException : <EOL> raise <EOL> except : <EOL> raise AuthenticationFailedException <EOL> return func ( user , * args ) <EOL> if hasattr ( func , '<STR_LIT>' ) : <EOL> sig = func . _xmlrpc_signature <EOL> sig [ '<STR_LIT:args>' ] = ( [ '<STR_LIT:string>' ] * <NUM_LIT:2> ) + sig [ '<STR_LIT:args>' ] <EOL> __authenticated_call . _xmlrpc_signature = sig <EOL> if func . __doc__ : <EOL> __authenticated_call . __doc__ = func . __doc__ + "<STR_LIT>" "<STR_LIT>" <EOL> if perm : <EOL> __authenticated_call . __doc__ += ( '<STR_LIT>' <EOL> '<STR_LIT>' % perm ) <EOL> return __authenticated_call <EOL> return _dec </s>
