1. desmaj
  2. orbited


desmaj  committed 0748fc9

A few quick changes to get us working again after some Twisted deprecations got real

  • Participants
  • Parent commits 1a8a478
  • Branches default

Comments (0)

Files changed (3)

File daemon/orbited/cometsession.py

View file
  • Ignore whitespace
 import uuid
 from zope.interface import implements
+from twisted.internet import base
 from twisted.internet import reactor, interfaces
 from twisted.internet.protocol import Protocol, Factory
 from twisted.internet.error import CannotListenError
     root.putChild('tcp', TCPResource(port))
     return site
-class Port(object):    
+class Port(base.BasePort):    
     """ A cometsession.Port object can be used in two different ways.
     # Method 1
     reactor.listenWith(cometsession.Port, 9999, SomeFactory())
     logger = logging.getLogger('orbited.cometsession.Port')
     def __init__(self, port=None, factory=None, backlog=50, interface='', reactor=None, resource=None, childName=None):
+        super(Port, self).__init__(reactor=reactor)
         self.port = port
         self.factory = factory
         self.backlog = backlog
             if self.port:
                 self.logger.debug('creating new site and resource')
                 self.wrapped_factory = setup_site(self)
-                self.wrapped_port = reactor.listenTCP(
+                self.wrapped_port = self.reactor.listenTCP(
         elif self.resource:
             # TODO: self.resource.removeChild(self.childName) ?
     def connectionMade(self, transportProtocol):
             proto is the tcp-emulation protocol
         if path not in self.connections:
             if 'htmlfile' in request.path:
                 return transports.htmlfile.CloseResource();
-            return error.NoResource("<script>alert('whoops');</script>")
+            return resource.NoResource("<script>alert('whoops');</script>")
 #        print 'returning self.connections[%s]' % (path,)
         return self.connections[path]

File daemon/orbited/proxy.py

View file
  • Ignore whitespace
                 host, port = data.split(':')
                 port = int(port)
                 self.completedHandshake = True
-            except:
+            except Exception as exc:
                 self.logger.error("failed to connect on handshake")
                 self.transport.write("0" + str(ERRORS['InvalidHandshake']))

File daemon/orbited/start.py

View file
  • Ignore whitespace
         if config.map['[global]'].get('%s.enabled' % config_key) == '1':
             port_class = _import(port_class_import)
             factory_class = _import(factory_class_import)
-            reactor.listenWith(port_class, factory=factory_class(), resource=root, childName=child_path)
+            # reactor.listenWith(port_class, factory=factory_class(), resource=root, childName=child_path)
+            # reactor.listenWith is deprecated since Twisted 10.1. All it really does is call the port_type
+            # constructor, passing itself as a 'reactor' keyword argument. So that's what we'll do here.
+            port = port_class(factory=factory_class(), reactor=reactor, resource=root, childName=child_path)
+            port.startListening()
             logger.info('%s protocol active' % config_key)
 def _setup_static(root, config):