reviewed imports, tolerant on some that are hard to get on a mac
[sfa.git] / sfa / util / soapprotocol.py
1 # SOAP-specific code for SFA Client
2
3 from httplib import HTTPSConnection
4 from ZSI.client import Binding
5
6 def xmlrpc_like_callable (soap_callable, *x):
7     soap_result = soap_callable(*x)
8     xmlrpc_result = soap_result['Result']
9     return xmlrpc_result
10         
11 class SFACallable:
12      def __init__(self, soap_callable):
13         self.soap_callable = soap_callable
14
15      def __call__(self, *args):
16          outer_result = self.soap_callable(*args)
17          return outer_result['Result']
18
19
20 class SFASoapBinding(Binding):
21     def __getattr__(self, attr):
22         soap_callable = Binding.__getattr__(self, attr)
23         return SFACallable(soap_callable)
24
25
26 def get_server(url, key_file, cert_file):
27     auth = {
28         'transport' : HTTPSConnection,
29         'transdict' : {'cert_file' : cert_file, 
30                        'key_file' : key_file
31                       },
32      }
33
34     return SFASoapBinding(url=url, **auth)
35