spacepaste

  1.  
  2. def monkeypatch_method_if_not_set(cls):
  3. def decorator(func):
  4. print '!!! patching %s with %s' % (cls, func.__name__)
  5. if not hasattr(cls, func.__name__):
  6. setattr(cls, func.__name__, func)
  7. return func
  8. return decorator
  9. from rpyc.core.netref import builtin_classes_cache
  10. netref_list = builtin_classes_cache[('list', '__builtin__')]
  11. print 'got', netref_list
  12. @monkeypatch_method_if_not_set(netref_list)
  13. def __tojava__(self, java_type):
  14. print '__tojava__ on', type(self)
  15. # from PySequence.java in Jython's source code
  16. if java_type.isArray():
  17. component = java_type.getComponentType()
  18. print '... got component as', type(component), repr(component)
  19. import array
  20. return array.array(component, self)
  21. UHOH
  22.