[pypy-svn] r42403 - in pypy/dist/pypy/lib/distributed: . test
fijal at codespeak.net
fijal at codespeak.net
Sat Apr 28 19:41:09 CEST 2007
Author: fijal
Date: Sat Apr 28 19:41:09 2007
New Revision: 42403
Modified:
pypy/dist/pypy/lib/distributed/faker.py
pypy/dist/pypy/lib/distributed/test/test_distributed.py
Log:
A bit of support for bases. two-liner file server would work by now
Modified: pypy/dist/pypy/lib/distributed/faker.py
==============================================================================
--- pypy/dist/pypy/lib/distributed/faker.py (original)
+++ pypy/dist/pypy/lib/distributed/faker.py Sat Apr 28 19:41:09 2007
@@ -40,12 +40,8 @@
""" Wrap type to transpotable entity, taking
care about descriptors
"""
- # XXX forget about bases right now
- bases = []
dict_w = {}
- # XXX we do dir here because we've forgotten about basis
- # above
- for item in dir(tp):
+ for item in tp.__dict__.keys():
value = getattr(tp, item)
if ignore(item):
# we've got shortcut for method
@@ -57,7 +53,8 @@
dict_w[item] = ('set', name)
else:
dict_w[item] = protocol.wrap(value)
- return tp_id, tp.__name__, dict_w, bases
+ bases_w = [protocol.wrap(i) for i in tp.__bases__ if i is not object]
+ return tp_id, tp.__name__, dict_w, bases_w
def unwrap_descriptor_gen(desc_class):
def unwrapper(protocol, data):
@@ -73,14 +70,16 @@
def unwrap_type(objkeeper, protocol, type_id, name_, dict_w, bases_w):
""" Unwrap remote type, based on it's description
"""
- # XXX sanity check
- assert bases_w == []
+ if bases_w == []:
+ bases = (object,)
+ else:
+ bases = tuple([protocol.unwrap(i) for i in bases_w])
d = dict.fromkeys(dict_w)
# XXX we do it in two steps to avoid cyclic dependencies,
# probably there is some smarter way of doing this
if '__doc__' in dict_w:
d['__doc__'] = protocol.unwrap(dict_w['__doc__'])
- tp = type(name_, (object,), d)
+ tp = type(name_, bases, d)
objkeeper.register_remote_type(tp, type_id)
for key, value in dict_w.items():
if key != '__doc__':
Modified: pypy/dist/pypy/lib/distributed/test/test_distributed.py
==============================================================================
--- pypy/dist/pypy/lib/distributed/test/test_distributed.py (original)
+++ pypy/dist/pypy/lib/distributed/test/test_distributed.py Sat Apr 28 19:41:09 2007
@@ -231,7 +231,6 @@
xa.m(xA)
def test_instantiate_remote_type(self):
- skip("Will not work unless we take care about __basis__")
class C:
def __init__(self, y):
self.y = y
@@ -254,11 +253,7 @@
assert l
def test_remote_file_access(self):
- # cannot do test_env({'file':file}) yet :)
- def f(name):
- return open(name)
-
- protocol = self.test_env({'f':f})
+ protocol = self.test_env({'f':open})
xf = protocol.get_remote('f')
data = xf('/etc/passwd').read()
assert data
@@ -279,3 +274,16 @@
xx = protocol.get_remote('x')
assert xx.x == 3
+ def test_bases(self):
+ class X(object):
+ pass
+
+ class Y(X):
+ pass
+
+ y = Y()
+ protocol = self.test_env({'y':y, 'X':X})
+ xy = protocol.get_remote('y')
+ xX = protocol.get_remote('X')
+ assert isinstance(xy, xX)
+
More information about the Pypy-commit
mailing list