Software /
code /
prosody-modules
Comparison
mod_auth_external/examples/python/prosody-auth-example.py @ 1194:f5eadba27120
mod_auth_external: Add example Python script
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 19 Sep 2013 16:04:45 +0100 |
comparison
equal
deleted
inserted
replaced
1193:bbe278a56b0a | 1194:f5eadba27120 |
---|---|
1 #!/usr/bin/env python2 | |
2 | |
3 import sys | |
4 | |
5 def auth(username, password): | |
6 if username == "someone": | |
7 return "1" | |
8 return "0" | |
9 | |
10 def respond(ret): | |
11 sys.stdout.write(ret+"\n") | |
12 sys.stdout.flush() | |
13 | |
14 methods = { | |
15 "auth": { "function": auth, "parameters": 2 } | |
16 } | |
17 | |
18 while 1: | |
19 line = sys.stdin.readline().rstrip("\n") | |
20 method, sep, data = line.partition(":") | |
21 if method in methods: | |
22 method_info = methods[method] | |
23 split_data = data.split(":", method_info["parameters"]) | |
24 if len(split_data) == method_info["parameters"]: | |
25 respond(method_info["function"](*split_data)) | |
26 else: | |
27 respond("error: incorrect number of parameters to method '%s'"%method) | |
28 else: | |
29 respond("error: method '%s' not implemented"%method) |