-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathproxy.py
More file actions
37 lines (32 loc) · 1.22 KB
/
proxy.py
File metadata and controls
37 lines (32 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
""" This module provides a directly callable class that implements a remote method invokation.
"""
import xmlrpc.client
try:
from xmlrpclib import ServerProxy
from xmlrpclib import Fault
except ImportError:
from xmlrpc.client import ServerProxy
from xmlrpc.client import Fault
class Proxy(object):
""" This directly callable class implements a remote method invokation.
"""
def __init__(self, session, dispatcher):
self.session = session
self.dispatcher = dispatcher
def __call__(self, module, method, where=None, set=None):
backend = self.dispatcher.get_backend(module)
remote = getattr(ServerProxy(backend), module + '.' + method)
ticket = self.session.get_ticket()
user = self.session.get_user()
try:
if (where is None) and (set is None):
result = remote(user, ticket)
elif where is None:
result = remote(user, ticket, set)
elif set is None:
result = remote(user, ticket, where)
else:
result = remote(user, ticket, set, where)
except xmlrpc.client.Fault as e:
raise Exception('HS Error' + e.faultString)
return result