[client-connection] handle the lack of connection id while not open
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Thu, 27 Jun 2013 11:02:30 +0200
changeset 9099 b7f7aa1b1123
parent 9098 5467fb901931
child 9100 8a1132c7cbd1
[client-connection] handle the lack of connection id while not open the connection id is computed at opening and forgotten when closing. We can't rely on it in various messages … like the "connection closed" exception.
repoapi.py
--- a/repoapi.py	Wed Jun 26 11:21:39 2013 +0200
+++ b/repoapi.py	Thu Jun 27 11:02:30 2013 +0200
@@ -175,9 +175,15 @@
             self.__exit__(None, None, None)
 
     def __repr__(self):
-        if self.anonymous_connection:
+        # XXX we probably want to reference the user of the session here
+        if self._open is None:
+            return '<ClientConnection (not open yet)>'
+        elif not self._open:
+            return '<ClientConnection (closed)>'
+        elif self.anonymous_connection:
             return '<ClientConnection %s (anonymous)>' % self._cnx.connectionid
-        return '<ClientConnection %s>' % self._cnx.connectionid
+        else:
+            return '<ClientConnection %s>' % self._cnx.connectionid
     # end silly BC
 
     @property
@@ -188,7 +194,7 @@
         TRANSITIONAL PURPOSE, This will be dropped once we use standalone
         session object"""
         if not self._open:
-            raise ProgrammingError('Closed connection %s' % self._cnxid)
+            raise ProgrammingError('Closed connection')
         yield self._cnx
 
     # Main Connection purpose in life #########################################