From e3fbf4f5db5f9700e4e0354774d740e14c33163e Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Sat, 24 Mar 2012 21:15:04 +0100 Subject: [PATCH] J'ai rendu la lecture plus propre depuis la modif avec les retcodes et errmsg --- client.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/client.py b/client.py index fb4764b..407f55f 100755 --- a/client.py +++ b/client.py @@ -45,7 +45,7 @@ def checkidentity(a): def hello(socket,version): socket.send('hello "%s"'%(version)) - return json.loads(a.read()) + return lit(a) def login(socket,user,mdp="",typ="bdd"): if user in ["20-100","moibdd"]: @@ -54,27 +54,25 @@ def login(socket,user,mdp="",typ="bdd"): a.write('login ["vincent","mdp","special"]') else: a.write('login ["%s","%s","%s"]'%(user,mdp,typ)) - return json.loads(a.read()) + return lit(a) def search(socket,term): a.write("search %s"%(term)) return json.loads(a.read()) -def lit(socket,noprint=False): +def lit(socket): try: t=a.read() - if noprint: - return json.loads(t) + obj=json.loads(t) + if obj["retcode"]==0: + return obj['msg'] else: - obj=json.loads(t) - if type(obj)==unicode: - print obj - else: - pprint(obj) + print obj["errmsg"] + return obj["msg"] except ssl.SSLError: - print "Rien à lire" + return "Rien à lire" except ValueError: - print "Serveur mort ?" + return "Serveur mort ?" def challenge(a): _,pub=monRSA.litcles(None,client_config.server_rsa_pub_key) -- 2.39.2