3 exposes a nice and easy interface to the internals of rpyc.
\r
4 this module, along with Utils, are the only modules most clients will need.
\r
7 from Stream import SocketStream, PipeStream
\r
8 from Channel import Channel
\r
9 from Connection import Connection
\r
10 from AsyncNetProxy import AsyncNetProxy
\r
11 from weakref import WeakValueDictionary
\r
12 from Lib import DEFAULT_PORT
\r
15 __all__ = ["SocketConnection", "AuthSocketConnection", "PipeConnection", "Async"]
\r
16 _async_proxy_cache = WeakValueDictionary()
\r
18 class LoginError(Exception):
\r
21 def SocketConnection(host, port = DEFAULT_PORT, **kw):
\r
22 """shorthand for creating a conneciton over a socket to a server"""
\r
23 return Connection(Channel(SocketStream.from_new_socket(host, port, **kw)))
\r
25 def _create_auth_connection(chan, username, password):
\r
26 from Authentication import login
\r
27 if not login(chan, username, password):
\r
28 raise LoginError("the server did not accept the login")
\r
29 return Connection(chan)
\r
31 def AuthSocketConnection(host, username, password, port = DEFAULT_PORT, **kw):
\r
32 """shorthand for creating a conneciton over a socket to a server, with authentication"""
\r
33 chan = Channel(SocketStream.from_new_socket(host, port, **kw))
\r
34 return _create_auth_connection(chan, username, password)
\r
36 def PipeConnection(incoming, outgoing):
\r
37 """shorthand for creating a conneciton over a pipe"""
\r
38 return Connection(Channel(PipeStream(incoming, outgoing)))
\r
40 def AuthPipeConnection(incoming, outgoing, username, password):
\r
41 """shorthand for creating a conneciton over a pipe"""
\r
42 chan = Channel(PipeStream(incoming, outgoing))
\r
43 return _create_auth_connection(chan, username, password)
\r
46 """a factory for creating asynchronous proxies for existing synchronous ones"""
\r
48 if key in _async_proxy_cache:
\r
49 return _async_proxy_cache[key]
\r
51 new_proxy = AsyncNetProxy(proxy)
\r
52 _async_proxy_cache[key] = new_proxy
\r