""" An abstraction layer over OS-dependent file-like objects, that provides a consistent view of a *duplex byte stream*. """ import sys import os import socket import time import errno from rpyc.lib import safe_import from rpyc.lib.compat import select, select_error, BYTES_LITERAL, get_exc_errno, maxint win32file = safe_import("win32file") win32pipe = safe_import("win32pipe") msvcrt = safe_import("msvcrt") ssl = safe_import("ssl") retry_errnos = (errno.EAGAIN, errno.EWOULDBLOCK) class Stream(object): """Base Stream""" __slots__ = () def close(self): """closes the stream, releasing any system resources associated with it""" raise NotImplementedError() @property def closed(self): """tests whether the stream is closed or not""" raise NotImplementedError()
import threading try: from thread import interrupt_main except ImportError: try: from _thread import interrupt_main except ImportError: # assume jython (#83) from java.lang import System interrupt_main = System.exit from rpyc import Connection, Channel, SocketStream, TunneledSocketStream, PipeStream, VoidService from rpyc.utils.registry import UDPRegistryClient from rpyc.lib import safe_import ssl = safe_import("ssl") class DiscoveryError(Exception): pass #------------------------------------------------------------------------------ # API #------------------------------------------------------------------------------ def connect_channel(channel, service = VoidService, config = {}): """creates a connection over a given channel :param channel: the channel to use :param service: the local service to expose (defaults to Void) :param config: configuration dict
import os import socket import time import threading import errno import logging try: import Queue except ImportError: import queue as Queue from rpyc.core import SocketStream, Channel from rpyc.utils.registry import UDPRegistryClient from rpyc.utils.authenticators import AuthenticationError from rpyc.lib import safe_import, spawn, spawn_waitready from rpyc.lib.compat import poll, get_exc_errno signal = safe_import("signal") gevent = safe_import("gevent") class Server(object): """Base server implementation :param service: the :class:`~rpyc.core.service.Service` to expose :param hostname: the host to bind to. Default is IPADDR_ANY, but you may want to restrict it only to ``localhost`` in some setups :param ipv6: whether to create an IPv6 or IPv4 socket. The default is IPv4 :param port: the TCP port to bind to :param backlog: the socket's backlog (passed to ``listen()``) :param reuse_addr: whether or not to create the socket with the ``SO_REUSEADDR`` option set. :param authenticator: the :ref:`api-authenticators` to use. If ``None``, no authentication
raise AuthenticationError("wrong magic word") return sock, None RPyC comes bundled with an authenticator for ``SSL`` (using certificates). This authenticator, for instance, both verifies the peer's identity and wraps the socket with an encrypted transport (which replaces the original socket). Authenticators are used by :class:`~rpyc.utils.server.Server` to validate an incoming connection. Using them is pretty trivial :: s = ThreadedServer(...., authenticator = magic_word_authenticator) s.start() """ import sys from rpyc.lib import safe_import ssl = safe_import("ssl") class AuthenticationError(Exception): """raised to signal a failed authentication attempt""" pass class SSLAuthenticator(object): """An implementation of the authenticator protocol for ``SSL``. The given socket is wrapped by ``ssl.wrap_socket`` and is validated based on certificates :param keyfile: the server's key file :param certfile: the server's certificate file :param ca_certs: the server's certificate authority file
""" *Channel* is an abstraction layer over streams that works with *packets of data*, rather than an endless stream of bytes, and adds support for compression. """ from rpyc.lib import safe_import from rpyc.lib.compat import Struct, BYTES_LITERAL zlib = safe_import("zlib") # * 64 bit length field? # * separate \n into a FlushingChannel subclass? # * add thread safety as a subclass? class Channel(object): """Channel implementation. Note: In order to avoid problems with all sorts of line-buffered transports, we deliberately add ``\\n`` at the end of each frame. """ COMPRESSION_THRESHOLD = 3000 COMPRESSION_LEVEL = 1 FRAME_HEADER = Struct("!LB") FLUSHER = BYTES_LITERAL( "\n") # cause any line-buffered layers below us to flush __slots__ = ["stream", "compress"] def __init__(self, stream, compress=True): self.stream = stream if not zlib: compress = False
""" An abstraction layer over OS-dependent file-like objects, that provides a consistent view of a *duplex byte stream*. """ import sys import os import socket import time import errno from rpyc.lib import safe_import from rpyc.lib.compat import select, select_error, BYTES_LITERAL, get_exc_errno, maxint win32file = safe_import("win32file") win32pipe = safe_import("win32pipe") msvcrt = safe_import("msvcrt") ssl = safe_import("ssl") retry_errnos = (errno.EAGAIN, errno.EWOULDBLOCK) class Stream(object): """Base Stream""" __slots__ = () def close(self): """closes the stream, releasing any system resources associated with it""" raise NotImplementedError() @property def closed(self): """tests whether the stream is closed or not"""
import os from subprocess import Popen, PIPE from rpyc.lib import safe_import from rpyc.lib.compat import BYTES_LITERAL signal = safe_import("signal") # modified from the stdlib pipes module for windows _safechars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@%_-+=:,./' _funnychars = '"`$\\' def shquote(text): if not text: return "''" for c in text: if c not in _safechars: break else: return text if "'" not in text: return "'" + text + "'" def escaped(c): if c in _funnychars: return '\\' + c else: return c res = "".join(escaped(c) for c in text) return '"' + res + '"' class ProcessExecutionError(Exception): """raised by :func:`SshContext.execute` should the executed process terminate with an error""" pass
""" An abstraction layer over OS-dependent file-like objects, that provides a consistent view of a *duplex byte stream*. """ import sys import os import socket import errno from rpyc.lib import safe_import, Timeout, socket_backoff_connect from rpyc.lib.compat import poll, select_error, BYTES_LITERAL, get_exc_errno, maxint # noqa: F401 from rpyc.core.consts import STREAM_CHUNK win32file = safe_import("win32file") win32pipe = safe_import("win32pipe") win32event = safe_import("win32event") retry_errnos = (errno.EAGAIN, errno.EWOULDBLOCK) class Stream(object): """Base Stream""" __slots__ = () def close(self): """closes the stream, releasing any system resources associated with it""" raise NotImplementedError() @property def closed(self): """tests whether the stream is closed or not"""
import os import socket import time import threading import errno import logging try: import Queue except ImportError: import queue as Queue from rpyc.core import SocketStream, Channel, Connection from rpyc.utils.registry import UDPRegistryClient from rpyc.utils.authenticators import AuthenticationError from rpyc.lib import safe_import from rpyc.lib.compat import poll, get_exc_errno signal = safe_import("signal") class Server(object): """Base server implementation :param service: the :class:`service <service.Service>` to expose :param hostname: the host to bind to. Default is IPADDR_ANY, but you may want to restrict it only to ``localhost`` in some setups :param ipv6: whether to create an IPv6 or IPv4 socket. The default is IPv4 :param port: the TCP port to bind to :param backlog: the socket's backlog (passed to ``listen()``) :param reuse_addr: whether or not to create the socket with the ``SO_REUSEADDR`` option set. :param authenticator: the :ref:`api-authenticators` to use. If ``None``, no authentication is performed. :param registrar: the :class:`registrar <rpyc.utils.registry.RegistryClient>` to use.
""" abstraction layer over OS-depenedent byte streams """ import sys import os import socket import time import errno from rpyc.lib import safe_import from rpyc.lib.compat import select win32file = safe_import("win32file") win32pipe = safe_import("win32pipe") msvcrt = safe_import("msvcrt") ssl = safe_import("ssl") tlsapi = safe_import("tlslite.api") retry_errnos = set([errno.EAGAIN]) if hasattr(errno, "WSAEWOULDBLOCK"): retry_errnos.add(errno.WSAEWOULDBLOCK) class Stream(object): __slots__ = () def close(self): raise NotImplementedError() @property def closed(self): raise NotImplementedError()
""" channel - an abstraction layer over streams that works with data frames (rather than bytes) and supports compression. Note: in order to avoid problems with all sorts of line-buffered transports, we deliberately add \\n at the end of each frame. note: unlike previous versions, this is no longer thread safe (thread-safety was moved up to the Connection class) """ from rpyc.lib import safe_import from rpyc.lib.compat import Struct zlib = safe_import("zlib") # * 64 bit length field? # * separate \n into a FlushingChannel subclass? # * add thread safety as a subclass? class Channel(object): COMPRESSION_THRESHOLD = 3000 COMPRESSION_LEVEL = 1 FRAME_HEADER = Struct("!LB") FLUSHER = "\n" # cause any line-buffered layers below us to flush __slots__ = ["stream", "compress"] def __init__(self, stream, compress = True): self.stream = stream if not zlib: compress = False self.compress = compress def close(self): self.stream.close()
""" abstraction layer over OS-depenedent byte streams """ import sys import os import socket import time import errno from rpyc.lib import safe_import from rpyc.lib.compat import select win32file = safe_import("win32file") win32pipe = safe_import("win32pipe") msvcrt = safe_import("msvcrt") ssl = safe_import("ssl") tlsapi = safe_import("tlslite.api") retry_errnos = set([errno.EAGAIN]) if hasattr(errno, "WSAEWOULDBLOCK"): retry_errnos.add(errno.WSAEWOULDBLOCK) class Stream(object): __slots__ = () def close(self): raise NotImplementedError() @property def closed(self): raise NotImplementedError() def fileno(self): raise NotImplementedError()
import socket import time import threading import errno import logging from contextlib import closing try: import Queue except ImportError: import queue as Queue from rpyc.core import SocketStream, Channel from rpyc.utils.registry import UDPRegistryClient from rpyc.utils.authenticators import AuthenticationError from rpyc.lib import safe_import, spawn, spawn_waitready from rpyc.lib.compat import poll, get_exc_errno signal = safe_import("signal") gevent = safe_import("gevent") class Server(object): """Base server implementation :param service: the :class:`~rpyc.core.service.Service` to expose :param hostname: the host to bind to. Default is IPADDR_ANY, but you may want to restrict it only to ``localhost`` in some setups :param ipv6: whether to create an IPv6 or IPv4 socket. The default is IPv4 :param port: the TCP port to bind to :param backlog: the socket's backlog (passed to ``listen()``) :param reuse_addr: whether or not to create the socket with the ``SO_REUSEADDR`` option set. :param authenticator: the :ref:`api-authenticators` to use. If ``None``, no authentication
encrypts the transport. the credentials returned alongside with the new socket can be any object. it will be stored in the rpyc connection configruation under the key "credentials", and may be used later by the service logic. if no credentials are applicable, just return None as in the example above. rpyc includes integration with tlslite, a TLS/SSL library: the VdbAuthenticator class authenticates clients based on username-password pairs. """ import os import sys import anydbm from rpyc.lib import safe_import tlsapi = safe_import("tlslite.api") ssl = safe_import("ssl") class AuthenticationError(Exception): pass class SSLAuthenticator(object): def __init__(self, keyfile, certfile, ca_certs = None, ssl_version = None): self.keyfile = keyfile self.certfile = certfile self.ca_certs = ca_certs if ca_certs: self.cert_reqs = ssl.CERT_REQUIRED else:
""" An abstraction layer over OS-dependent file-like objects, that provides a consistent view of a *duplex byte stream*. """ import sys import os import socket import errno from rpyc.lib import safe_import, Timeout from rpyc.lib.compat import poll, select_error, BYTES_LITERAL, get_exc_errno, maxint win32file = safe_import("win32file") win32pipe = safe_import("win32pipe") win32event = safe_import("win32event") retry_errnos = (errno.EAGAIN, errno.EWOULDBLOCK) class Stream(object): """Base Stream""" __slots__ = () def close(self): """closes the stream, releasing any system resources associated with it""" raise NotImplementedError() @property def closed(self): """tests whether the stream is closed or not""" raise NotImplementedError() def fileno(self): """returns the stream's file descriptor"""
encrypts the transport. the credentials returned alongside with the new socket can be any object. it will be stored in the rpyc connection configruation under the key "credentials", and may be used later by the service logic. if no credentials are applicable, just return None as in the example above. rpyc includes integration with tlslite, a TLS/SSL library: the VdbAuthenticator class authenticates clients based on username-password pairs. """ import os import sys import anydbm from rpyc.lib import safe_import tlsapi = safe_import("tlslite.api") ssl = safe_import("ssl") class AuthenticationError(Exception): pass class SSLAuthenticator(object): def __init__(self, keyfile, certfile, ca_certs=None, ssl_version=None): self.keyfile = keyfile self.certfile = certfile self.ca_certs = ca_certs if ca_certs: self.cert_reqs = ssl.CERT_REQUIRED else: