Source

crossroads / crossroads / low.py

Diff from to

crossroads/low.py

             return getr(self, key)
         except AttributeError:
             try:
-                this = bigxsget(key.upper())
+                newkey = key.upper()
+                this = bigxsget(newkey)
                 if this in XS.TYPES:
-                    return self._setter(key.lower(), self._open, this)
+                    return self._setter(key.lower(), self._open, this, newkey)
             except AttributeError:
                 raise AttributeError(key)
 
             else:
                 raise xs.XSOperationError(msg)
 
-    def _open(self, stype, **options):
-        return Socket(self, stype, **options)
+    def _open(self, stype, key, **options):
+        return Socket(self, stype, key, **options)
 
     def close(self):
         rc = xs.term(self._ctx)
 
 class Socket(Setter):
 
-    def __init__(self, context, stype, **options):
+    def __init__(self, context, stype, newkey, **options):
         self.context = context
         self._type = stype
+        self._type_name = newkey
         self._socket = xs.socket(context._ctx, stype)
         options.update(context._options)
         _set = self._set
         except AttributeError:
             setr(self, key, value)
 
+    def __repr__(self):
+        return '{self._type_name}@{self._socket}'.format(self=self)
+
     def _opt_type(self, key):
         opt_key = bigxsget(key.upper())
         if opt_key in XS.INT:
             opt_type = c_int64
         elif opt_key in XS.BINARY:
             opt_type = c_char_p
+        else:
+            raise AttributeError(
+                '{0} is not a valid socket attribute'.format(key)
+            )
         return opt_key, opt_type
 
     def _get(self, key):
 
     def recvmsg(self, nowait=False):
         msg = MessageXS()
-        try:
-            msg.last_rc = self.last_rc = self._recvmsg(
-                msg.dest, XS.DONTWAIT if nowait else 0,
-            )
-            msg.more = self.rcvmore
-        finally:
-            msg.close()
+        msg.last_rc = self.last_rc = self._recvmsg(
+            msg.dest, XS.DONTWAIT if nowait else 0,
+        )
+        msg.more = self.rcvmore
         return msg
 
     def shutdown(self, sid):