Quelques exemples de code SOAP…
[progfou.git] / soap / soap-server.py
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Debian-Depends: python-soaplib
4 # Debian-Suggests: python-wsgiref
5 from soaplib.wsgi_soap import SimpleWSGISoapApp
6 from soaplib.service import soapmethod
7 from soaplib.serializers.primitive import String, Integer, Array
8 from random import choice
9 from crypt import crypt
10
11 class CryptService(SimpleWSGISoapApp):
12
13 def make_salt(self, count=16):
14 choices = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ./'
15 return ''.join([choice(choices) for x in range(count)])
16
17 def crypt(self, username, password, method):
18 return crypt(password, '$%s$%s$' % (method, self.make_salt()) )
19
20 @soapmethod(String, String, _returns=String)
21 def crypt1(self, username, password):
22 """
23 GNU libc's crypt function, method 1 (SHA-160).
24 @param username the username
25 @param password the password
26 @return the encrypted password
27 """
28 return self.crypt(username, password, '1')
29
30 @soapmethod(String, String, _returns=String)
31 def crypt5(self, username, password):
32 """
33 GNU libc's crypt function, method 5 (SHA-256).
34 @param username the username
35 @param password the password
36 @return the encrypted password
37 """
38 return self.crypt(username, password, '5')
39
40 @soapmethod(String, String, _returns=String)
41 def crypt6(self, username, password):
42 """
43 GNU libc's crypt function, method 6 (SHA-512).
44 @param username the username
45 @param password the password
46 @return the encrypted password
47 """
48 return self.crypt(username, password, '6')
49
50 application = CryptService()
51
52 if __name__=='__main__':
53 from wsgiref.simple_server import make_server
54 server = make_server('', 8000, application)
55 server.serve_forever()