def _box(self, obj): # boxing """store a local object in such a way that it could be recreated on the remote party either by-value or by-reference""" if brine.dumpable(obj): return consts.LABEL_VALUE, obj if type(obj) is tuple: return consts.LABEL_TUPLE, tuple(self._box(item) for item in obj) elif isinstance(obj, netref.BaseNetref) and obj.____conn__ is self: return consts.LABEL_LOCAL_REF, obj.____id_pack__ else: id_pack = get_id_pack(obj) self._local_objects.add(id_pack, obj) return consts.LABEL_REMOTE_REF, id_pack
def _handle_del(self, obj, count=1): # request handler self._local_objects.decref(get_id_pack(obj), count)
def __init__(self, class_obj): self._class_obj = class_obj self._class_type_name = get_id_pack(type(self._class_obj))[0]
cursor = len(name_pack) while cursor != -1: _module = sys.modules.get(name_pack[:cursor]) if _module is None: cursor = name_pack[:cursor].rfind('.') continue _class_name = name_pack[cursor + 1:] _class = getattr(_module, _class_name, None) if _class is not None and hasattr(_class, '__class__'): class_descriptor = NetrefClass(_class) break ns['__class__'] = class_descriptor netref_name = class_descriptor.owner.__name__ if class_descriptor is not None else name_pack # create methods that must perform a syncreq for name, doc in methods: name = str(name) # IronPython issue #10 # only create methods that wont shadow BaseNetref during merge for mro if name not in LOCAL_ATTRS: # i.e. `name != __class__` ns[name] = _make_method(name, doc) return type(netref_name, (BaseNetref, ), ns) for _builtin in _builtin_types: _id_pack = get_id_pack(_builtin) _name_pack = _id_pack[0] _normalized_builtin_types[_name_pack] = _builtin _builtin_methods = get_methods(LOCAL_ATTRS, _builtin) # assume all normalized builtins are classes builtin_classes_cache[_name_pack] = class_factory(_id_pack, _builtin_methods)
types.GeneratorType, types.MethodType, types.CodeType, types.FrameType, types.TracebackType, types.ModuleType, types.FunctionType, type(int.__add__), # wrapper_descriptor type((1).__add__), # method-wrapper type(iter([])), # listiterator type(iter(())), # tupleiterator type(iter(set())), # setiterator ] """a list of types considered built-in (shared between connections)""" _builtin_type_name_pack = get_id_pack(type)[0] try: BaseException except NameError: pass else: _builtin_types.append(BaseException) if is_py3k: _builtin_types.extend([ bytes, bytearray, type(iter(range(10))), memoryview, ])