[pypy-svn] r42966 - in pypy/dist/pypy/lib/distributed: . test

fijal at codespeak.net fijal at codespeak.net
Wed May 9 20:37:02 CEST 2007


Author: fijal
Date: Wed May  9 20:37:01 2007
New Revision: 42966

Added:
   pypy/dist/pypy/lib/distributed/support.py
Modified:
   pypy/dist/pypy/lib/distributed/socklayer.py
   pypy/dist/pypy/lib/distributed/test/test_socklayer.py
Log:
Make slighlty better interface for lib/distributed


Modified: pypy/dist/pypy/lib/distributed/socklayer.py
==============================================================================
--- pypy/dist/pypy/lib/distributed/socklayer.py	(original)
+++ pypy/dist/pypy/lib/distributed/socklayer.py	Wed May  9 20:37:01 2007
@@ -60,12 +60,13 @@
     s = socket(AF_INET, SOCK_STREAM)
     print "Connecting %s" % (address,)
     s.connect(address)
-
+    
     return SenderWrapper(s).send, ReceiverWrapper(s).receive
 
 def connect(address, socket=socket):
+    from distributed.support import get_remote_view
     from distributed import RemoteProtocol
-    return RemoteProtocol(*socket_connecter(address, socket))
+    return get_remote_view(RemoteProtocol(*socket_connecter(address, socket)))
 
 def spawn_remote_side(code, gw):
     """ A very simple wrapper around greenexecnet to allow

Added: pypy/dist/pypy/lib/distributed/support.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lib/distributed/support.py	Wed May  9 20:37:01 2007
@@ -0,0 +1,14 @@
+
+""" Some random support functions
+"""
+
+def get_remote_view(protocol):
+    # this is dynamic to provide needed level of laziness
+    class RemoteView(object):
+        pass
+
+    for key in protocol.remote_keys():
+        getter = lambda self: protocol.get_remote(key)
+        setattr(RemoteView, key, property(getter))
+
+    return RemoteView()

Modified: pypy/dist/pypy/lib/distributed/test/test_socklayer.py
==============================================================================
--- pypy/dist/pypy/lib/distributed/test/test_socklayer.py	(original)
+++ pypy/dist/pypy/lib/distributed/test/test_socklayer.py	Wed May  9 20:37:01 2007
@@ -27,6 +27,7 @@
 
         def two():
             rp = connect(('127.0.0.1', 21211), GreenSocket)
-            assert rp.get_remote('x').z == 3
+            assert rp.x.z == 3
+            assert [i for i in dir(rp) if not i.startswith('__')] == ['x']
 
         oneof(one, two)


More information about the pypy-svn mailing list