コード例 #1
0
 def import_ns(self, namespace):
     """
     """
     pythonshare._send(Request_ns(namespace), self._to_server)
     rv = pythonshare._recv(self._from_server)
     if isinstance(rv, Ns_rv) and rv.status:
         return True
     else:
         raise pythonshare.PythonShareError(rv.errormsg)
コード例 #2
0
ファイル: client.py プロジェクト: heivi/fMBT
 def import_ns(self, namespace):
     """
     """
     cPickle.dump(Request_ns(namespace), self._to_server)
     self._to_server.flush()
     rv = cPickle.load(self._from_server)
     if isinstance(rv, Ns_rv) and rv.status:
         return True
     else:
         raise pythonshare.PythonShareError(rv.errormsg)
コード例 #3
0
    def unlock_ns(self, namespace):
        """Unlock namespace on the remote peer

        Parameters:

          namespace (string)
                  Namespace to be unlocked, can be local or
                  remote to the server.

        Returns True on success or raises an exception.
        """
        pythonshare._send(Server_ctl("unlock", namespace), self._to_server)
        rv = pythonshare._recv(self._from_server)
        if isinstance(rv, Server_ctl_rv) and rv.status == 0:
            return True
        else:
            raise pythonshare.PythonShareError(rv.message)
コード例 #4
0
    def drop_ns(self, namespace):
        """Delete namespace from the remote peer

        Parameters:

          namespace (string)
                  Namespace to be dropped, can be local or
                  remote to the server.

        Returns True on success or raises an exception.
        """
        pythonshare._send(Drop_ns(namespace), self._to_server)
        rv = pythonshare._recv(self._from_server)
        if isinstance(rv, Ns_rv) and rv.status:
            return True
        else:
            raise pythonshare.PythonShareError(rv.errormsg)
コード例 #5
0
    def export_ns(self, namespace):
        """Export namespace to remote peer

        Parameters:

          namespace (string)
                  Namespace to be exported, can be local or
                  remote to current host.

        Returns True on success or raises an exception.  If succeeded,
        this connection becomes a server for requests from remote
        peer. (The remote peer accesses registered namespace through
        this connection object.)
        """
        pythonshare._send(Register_ns(namespace), self._to_server)
        rv = pythonshare._recv(self._from_server)
        if isinstance(rv, Ns_rv) and rv.status:
            return True
        else:
            raise pythonshare.PythonShareError(rv.errormsg)
コード例 #6
0
ファイル: client.py プロジェクト: heivi/fMBT
                  lock the namespace from others until this execution
                  has finished. The default is True.

        Returns return value from expr or None.

        Raise RemoteExecError or RemoteEvalError if code or expr caused
        an exception in remote end, respectively.

        """
        try:
            cPickle.dump(Exec(namespace, code, expr, async=async, lock=lock),
                         self._to_server)
            self._to_server.flush()
            return self.make_local(cPickle.load(self._from_server))
        except EOFError:
            raise pythonshare.PythonShareError(
                'No connection to namespace "%s"' % (namespace, ))

    def eval_(self, expr, **kwargs):
        """Evaluate expr in the default namespace.

        See eval_in for optional parameters."""
        return self.eval_in(self._ns, expr, **kwargs)

    def eval_in(self, namespace, expr, async=False, lock=True):
        """Evaluate expr in a namespace.

        Parameters:

          namespace (string)
                  namespace in which the expression will be evaluated.
コード例 #7
0
        Raise RemoteExecError or RemoteEvalError if code or expr caused
        an exception in remote end, respectively.

        """
        if namespace == None:
            namespace = self.namespace()
        pythonshare._check_hook("before:client.exec_in", {"code": code, "expr": expr, "namespace": namespace, "async": async, "lock": lock})
        try:
            pythonshare._send(Exec(
                namespace, code, expr, async=async, lock=lock,
                recv_caps=pythonshare.messages.RECV_CAP_COMPRESSION), self._to_server)
            response = pythonshare._recv_with_info(self._from_server)
            obj = self.make_local(response)
            if isinstance(obj, Auth_rv) and obj.success == False:
                raise pythonshare.PythonShareError('Authentication failed: %s'
                                                   % (obj.errormsg,))
            return obj
        except EOFError:
            raise pythonshare.PythonShareError(
                'No connection to namespace "%s"' % (namespace,))

    def eval_(self, expr, **kwargs):
        """Evaluate expr in the default namespace.

        See eval_in for optional parameters."""
        return self.eval_in(self._ns, expr, **kwargs)

    def eval_in(self, namespace, expr, async=False, lock=True):
        """Evaluate expr in a namespace.

        Parameters: