Version 0.3: Gestion des échecs de connexion
authorEric Mc Sween <eric.mcsween@auf.org>
Wed, 29 May 2013 18:18:16 +0000 (14:18 -0400)
committerEric Mc Sween <eric.mcsween@auf.org>
Wed, 29 May 2013 18:18:16 +0000 (14:18 -0400)
CHANGES [new file with mode: 0644]
README [new file with mode: 0644]
codaxmli/__init__.py
setup.py

diff --git a/CHANGES b/CHANGES
new file mode 100644 (file)
index 0000000..eee7ffd
--- /dev/null
+++ b/CHANGES
@@ -0,0 +1,14 @@
+Version 0.1
+===========
+
+* Version initiale du client XMLi
+
+Version 0.2
+===========
+
+* Packaging des classes Java
+
+Version 0.3
+===========
+
+* Gestion des échecs de connexion
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..47d155c
--- /dev/null
+++ b/README
@@ -0,0 +1,9 @@
+coda-xmli
+=========
+
+Client pour l'interface XMLi de Coda.
+
+Installation
+============
+
+coda-xmli requiert Java, idéalement la version 1.6.
index 3658ae7..ea0e9cc 100644 (file)
@@ -1,8 +1,9 @@
 import os
 import subprocess
 from tempfile import mkstemp
-from lxml import etree
 
+from lxml import etree
+from lxml.etree import XMLSyntaxError
 from pkg_resources import resource_filename
 
 
@@ -29,23 +30,34 @@ class Client(object):
             request = etree.tostring(request)
         if self.trace:
             print request
-        request_fd, request_path = mkstemp(prefix='xmli-')
+        request_fd, request_path = mkstemp(prefix='xmli-req-')
         os.write(request_fd, request)
         os.close(request_fd)
 
-        response_fd, response_path = mkstemp(prefix='xmli-')
+        response_fd, response_path = mkstemp(prefix='xmli-resp-')
+        error_fd, error_path = mkstemp(prefix='xmli-err-')
         subprocess.check_call([
             'java', '-classpath', CLASSPATH, 'com.coda.xml.router.Router',
             '-nsv:' + self.host, '-port:' + str(self.port),
             '-name:' + self.lsv_name, '-user:' + self.user,
             '-password:' + self.password, '-company:' + self.company,
             request_path
-        ], stdout=response_fd)
+        ], stdout=response_fd, stderr=error_fd)
         os.close(response_fd)
+        os.close(error_fd)
+
+        try:
+            response = etree.parse(response_path)
+        except XMLSyntaxError:
+            with open(error_path) as error_file:
+                error_str = error_file.read()
+            if 'COMMON_FW_INVALID_USER' in error_str:
+                raise LoginFailed()
+            raise
 
-        response = etree.parse(response_path)
         os.remove(request_path)
         os.remove(response_path)
+        os.remove(error_path)
 
         errors = response.findall('//Reason')
         if errors:
@@ -66,3 +78,9 @@ class Client(object):
 
 class XMLiError(Exception):
     pass
+
+
+class LoginFailed(XMLiError):
+
+    def __init__(self):
+        super(XMLiError, self).__init__('Login failed')
index 662f434..cf2487c 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@
 from setuptools import setup, find_packages
 
 name = 'coda-xmli'
-version = '0.2'
+version = '0.3'
 
 setup(
     name=name,