r47323 - Merge runner-rpcserver-deprecation-8123-3: Deprecate twisted.runner RPCServer and RPCServicesConf.

adiroiban-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org Tue, 26 Apr 2016 00:22:15 -0600 (MDT)
Newsgroups gmane.comp.python.twisted.commits
Message-ID <[email protected]>
Author: adiroiban
Date: Tue Apr 26 00:21:57 2016
New Revision: 47323

Added:
   trunk/twisted/runner/test/test_inetdconf.py
   trunk/twisted/runner/test/test_inetdtap.py
   trunk/twisted/runner/topfiles/8123.removal
Modified:
   trunk/twisted/runner/inetdconf.py
   trunk/twisted/runner/inetdtap.py

Log:
Merge runner-rpcserver-deprecation-8123-3: Deprecate twisted.runner RPCServer and RPCServicesConf.

Author: adiroiban
Reviewer: glyph
Fixes: #8123

Modified: trunk/twisted/runner/inetdconf.py
==============================================================================
--- trunk/twisted/runner/inetdconf.py	(original)
+++ trunk/twisted/runner/inetdconf.py	Tue Apr 26 00:21:57 2016
@@ -1,14 +1,14 @@
+# -*- test-case-name: twisted.runner.test.test_inetdconf -*-
 # Copyright (c) Twisted Matrix Laboratories.
 # See LICENSE for details.
 
-# 
 """
 Parser for inetd.conf files
+"""
 
-Maintainer: Andrew Bennetts
+from twisted.python.deprecate import deprecatedModuleAttribute
+from twisted.python.versions import Version
 
-Future Plans: xinetd configuration file support?
-"""
 
 # Various exceptions
 class InvalidConfError(Exception):
@@ -23,8 +23,16 @@
     """Invalid services file"""
 
 
+
 class InvalidRPCServicesConfError(InvalidConfError):
-    """Invalid rpc services file"""
+    """
+    DEPRECATED. Invalid rpc services file
+    """
+    deprecatedModuleAttribute(
+        Version("Twisted", 16, 2, 0),
+        "The RPC service configuration is no longer maintained.",
+        __name__, "InvalidRPCServicesConfError")
+
 
 
 class UnknownService(Exception):
@@ -170,23 +178,29 @@
             self.services[(alias, protocol)] = port
 
 
+
 class RPCServicesConf(SimpleConfFile):
-    """/etc/rpc parser
+    """
+    DEPRECATED. /etc/rpc parser
 
     @ivar self.services: dict mapping rpc service names to rpc ports.
     """
+    deprecatedModuleAttribute(
+        Version("Twisted", 16, 2, 0),
+        "The RPC service configuration is no longer maintained.",
+        __name__, "RPCServicesConf")
 
     defaultFilename = '/etc/rpc'
 
     def __init__(self):
         self.services = {}
-    
+
     def parseFields(self, name, port, *aliases):
         try:
             port = long(port)
         except:
             raise InvalidRPCServicesConfError, 'Invalid port:' + repr(port)
-                        
+
         self.services[name] = port
         for alias in aliases:
             self.services[alias] = port

Modified: trunk/twisted/runner/inetdtap.py
==============================================================================
--- trunk/twisted/runner/inetdtap.py	(original)
+++ trunk/twisted/runner/inetdtap.py	Tue Apr 26 00:21:57 2016
@@ -1,38 +1,42 @@
+# -*- test-case-name: twisted.runner.test.test_inetdtap -*-
 # Copyright (c) Twisted Matrix Laboratories.
 # See LICENSE for details.
 
-# 
-
 """
 Twisted inetd TAP support
 
-Maintainer: Andrew Bennetts
-
-Future Plans: more configurability.
+The purpose of inetdtap is to provide an inetd-like server, to allow Twisted to
+invoke other programs to handle incoming sockets.
+This is a useful thing as a "networking swiss army knife" tool, like netcat.
 """
 
-import os, pwd, grp, socket
+import pwd, grp, socket
 
 from twisted.runner import inetd, inetdconf
 from twisted.python import log, usage
+from twisted.python.deprecate import deprecatedModuleAttribute
+from twisted.python.versions import Version
 from twisted.internet.protocol import ServerFactory
 from twisted.application import internet, service as appservice
 
-try:
-    import portmap
-    rpcOk = 1
-except ImportError:
-    rpcOk = 0
-
-
 # Protocol map
 protocolDict = {'tcp': socket.IPPROTO_TCP, 'udp': socket.IPPROTO_UDP}
 
 
 class Options(usage.Options):
+    """
+    To use it, create a file named `sample-inetd.conf` with:
+
+    8123 stream tcp wait some_user /bin/cat -
+
+    You can then run it as in the following example and port 8123 became an
+    echo server.
+
+    twistd -n inetd -f sample-inetd.conf
+    """
 
     optParameters = [
-        ['rpc', 'r', '/etc/rpc', 'RPC procedure table file'],
+        ['rpc', 'r', '/etc/rpc', 'DEPRECATED. RPC procedure table file'],
         ['file', 'f', '/etc/inetd.conf', 'Service configuration file']
     ]
 
@@ -42,72 +46,31 @@
         optActions={"file": usage.CompleteFiles('*.conf')}
         )
 
+
+
 class RPCServer(internet.TCPServer):
+    """
+    DEPRECATED.
+    """
+    deprecatedModuleAttribute(
+        Version("Twisted", 16, 2, 0),
+        "The RPC server is no longer maintained.",
+        __name__, "RPCServer")
+
 
-    def __init__(self, rpcVersions, rpcConf, proto, service):
-        internet.TCPServer.__init__(0, ServerFactory())
-        self.rpcConf = rpcConf
-        self.proto = proto
-        self.service = service
-
-    def startService(self):
-        internet.TCPServer.startService(self)
-        import portmap
-        portNo = self._port.getHost()[2]
-        service = self.service
-        for version in rpcVersions:
-            portmap.set(self.rpcConf.services[name], version, self.proto,
-                        portNo)
-            inetd.forkPassingFD(service.program, service.programArgs,
-                                os.environ, service.user, service.group, p)
 
 def makeService(config):
     s = appservice.MultiService()
     conf = inetdconf.InetdConf()
     conf.parseFile(open(config['file']))
 
-    rpcConf = inetdconf.RPCServicesConf()
-    try:
-        rpcConf.parseFile(open(config['rpc']))
-    except:
-        # We'll survive even if we can't read /etc/rpc
-        log.deferr()
-    
     for service in conf.services:
-        rpc = service.protocol.startswith('rpc/')
         protocol = service.protocol
 
-        if rpc and not rpcOk:
+        if service.protocol.startswith('rpc/'):
             log.msg('Skipping rpc service due to lack of rpc support')
             continue
 
-        if rpc:
-            # RPC has extra options, so extract that
-            protocol = protocol[4:]     # trim 'rpc/'
-            if not protocolDict.has_key(protocol):
-                log.msg('Bad protocol: ' + protocol)
-                continue
-            
-            try:
-                name, rpcVersions = service.name.split('/')
-            except ValueError:
-                log.msg('Bad RPC service/version: ' + service.name)
-                continue
-
-            if not rpcConf.services.has_key(name):
-                log.msg('Unknown RPC service: ' + repr(service.name))
-                continue
-
-            try:
-                if '-' in rpcVersions:
-                    start, end = map(int, rpcVersions.split('-'))
-                    rpcVersions = range(start, end+1)
-                else:
-                    rpcVersions = [int(rpcVersions)]
-            except ValueError:
-                log.msg('Bad RPC versions: ' + str(rpcVersions))
-                continue
-            
         if (protocol, service.socketType) not in [('tcp', 'stream'),
                                                   ('udp', 'dgram')]:
             log.msg('Skipping unsupported type/protocol: %s/%s'
@@ -148,12 +111,7 @@
                 continue
             factory = ServerFactory()
             factory.protocol = inetd.internalProtocols[service.name]
-        elif rpc:
-            i = RPCServer(rpcVersions, rpcConf, proto, service)
-            i.setServiceParent(s)
-            continue
         else:
-            # Non-internal non-rpc services use InetdFactory
             factory = inetd.InetdFactory(service)
 
         if protocol == 'tcp':