Exemple #1
0
def issubclass(cls, bases):
    """a version of issubclass that supports NetProxies"""
    if not orig_isinstance(bases, tuple):
        bases = (bases,)

    # is cls a proxy?
    if orig_isinstance(cls, NetProxy):
        return _remote_issubclass(cls, bases)

    # is one of the bases a proxy?
    for base in bases:
         if orig_isinstance(base, NetProxy):
            return _remote_issubclass(cls, bases)
    
    # plain old issubclass
    return orig_issubclass(cls, bases)
Exemple #2
0
def issubclass(cls, bases):
    """a version of issubclass that supports NetProxies"""
    if not orig_isinstance(bases, tuple):
        bases = (bases, )

    # is cls a proxy?
    if orig_isinstance(cls, NetProxy):
        return _remote_issubclass(cls, bases)

    # is one of the bases a proxy?
    for base in bases:
        if orig_isinstance(base, NetProxy):
            return _remote_issubclass(cls, bases)

    # plain old issubclass
    return orig_issubclass(cls, bases)
Exemple #3
0
def dir(*obj):
    """a version of dir() that supports NetProxies"""
    if not obj:
        return sorted(inspect.stack()[1][0].f_locals.keys())
    if not len(obj) == 1:
        raise TypeError("dir expected at most 1 arguments, got %d" % (len(obj),))
    obj = obj[0]
    if orig_isinstance(obj, NetProxy):
        return _get_conn(obj).modules.__builtin__.dir(obj)
    else:
        return orig_dir(obj)
Exemple #4
0
 def __call__(self, obj = None):
     if orig_isinstance(obj, NetProxy):
         print "Help on NetProxy object for an instance of %r:" % (obj.__getattr__("__class__").__name__,)
         print
         print "Doc:"
         print obj.__getattr__("__doc__")
         print
         print "Members:"
         print dir(obj)
     else:
         orig_help(obj)
Exemple #5
0
def dir(*obj):
    """a version of dir() that supports NetProxies"""
    if not obj:
        return sorted(inspect.stack()[1][0].f_locals.keys())
    if not len(obj) == 1:
        raise TypeError("dir expected at most 1 arguments, got %d" %
                        (len(obj), ))
    obj = obj[0]
    if orig_isinstance(obj, NetProxy):
        return _get_conn(obj).modules.__builtin__.dir(obj)
    else:
        return orig_dir(obj)
Exemple #6
0
 def __call__(self, obj=None):
     if orig_isinstance(obj, NetProxy):
         print "Help on NetProxy object for an instance of %r:" % (
             obj.__getattr__("__class__").__name__, )
         print
         print "Doc:"
         print obj.__getattr__("__doc__")
         print
         print "Members:"
         print dir(obj)
     else:
         orig_help(obj)
Exemple #7
0
def getattr(obj, name, *default):
    """a version of getattr() that supports NetProxies"""
    if len(default) > 1:
        raise TypeError("getattr expected at most 3 arguments, got %d" % (2 + len(default),))
    if orig_isinstance(obj, NetProxy):
        try:
            return obj.__getattr__(name)
        except AttributeError:
            if not default:
                raise
            return default[0]
    else:
        return orig_getattr(obj, name, *default)
Exemple #8
0
def _get_fullname(cls):
    """
    a heuristic to generate a unique identifier for classes, that is not 
    machine-, platform-, or runtime-dependent
    """
    if orig_isinstance(cls, NetProxy):
        modules = _get_conn(cls).modules.sys.modules
    else:
        modules = sys.modules
    try:
        filename = modules[cls.__module__].__file__
    except (KeyError, AttributeError):
        filename = cls.__module__
    return (filename, cls.__name__)
Exemple #9
0
def _get_fullname(cls):
    """
    a heuristic to generate a unique identifier for classes, that is not 
    machine-, platform-, or runtime-dependent
    """
    if orig_isinstance(cls, NetProxy):
        modules = _get_conn(cls).modules.sys.modules
    else:
        modules = sys.modules
    try:
        filename = modules[cls.__module__].__file__
    except (KeyError, AttributeError):
        filename = cls.__module__
    return (filename, cls.__name__)
Exemple #10
0
def getattr(obj, name, *default):
    """a version of getattr() that supports NetProxies"""
    if len(default) > 1:
        raise TypeError("getattr expected at most 3 arguments, got %d" %
                        (2 + len(default), ))
    if orig_isinstance(obj, NetProxy):
        try:
            return obj.__getattr__(name)
        except AttributeError:
            if not default:
                raise
            return default[0]
    else:
        return orig_getattr(obj, name, *default)
Exemple #11
0
def deliver(obj, conn):
    """
    delivers a local object to the other side of the connection. the object
    can be a function or any picklable object. deliver objects creates a remote
    copy of the objectm so changes made to the remote copy are not reflected on
    the local one. keep this in mind.
    
    obj - the object to deliver
    conn - the connection which obtains the object
    returns a proxy to the delivered object
    """
    if isproxy(obj):
        raise TypeError("can't deliver proxies")
    if orig_isinstance(obj, function):
        globals = conn.remote_conn._local_namespace
        dumped = _dump_function(obj)
        return conn.modules[__name__]._load_function(dumped, globals)
    else:
        return conn.modules.cPickle.loads(pickle.dumps(obj, pickle.HIGHEST_PROTOCOL))
Exemple #12
0
def reload(module):
    """a version of reload() that supports NetProxies"""
    if orig_isinstance(module, NetProxy):
        return _get_conn(module).modules.__builtin__.reload(module)
    else:
        return orig_reload(module)
Exemple #13
0
def isproxy(obj):
    """indicates whether the given object is a NetProxy"""
    return orig_isinstance(obj, NetProxy)
Exemple #14
0
def reload(module):
    """a version of reload() that supports NetProxies"""
    if orig_isinstance(module, NetProxy):
        return _get_conn(module).modules.__builtin__.reload(module)
    else:
        return orig_reload(module)