from twisted.internet import protocol, reactor

factory = protocol.ServerFactory()
factory.protocol = protocol.Protocol

reactor.listenTCP(8000, factory)
reactor.run()

from twisted.internet import endpoints, protocol, reactor

class UpperProtocol(protocol.Protocol):
    pass

factory = protocol.ServerFactory()
factory.protocol = UpperProtocol

endpoints.serverFromString(reactor, 'tcp:8000').listen(factory)
reactor.run()

Convert to endpoints API and use custom protocol class
Convert to endpoints API and use custom protocol class

- from twisted.internet import protocol, reactor
+ from twisted.internet import endpoints, protocol, reactor
+ 
+ class UpperProtocol(protocol.Protocol):
+     pass
  
  factory = protocol.ServerFactory()
- factory.protocol = protocol.Protocol
+ factory.protocol = UpperProtocol
  
- reactor.listenTCP(8000, factory)
+ endpoints.serverFromString(reactor, 'tcp:8000').listen(factory)
  reactor.run()
  
Convert to endpoints API and use custom protocol class
## Code Before:
from twisted.internet import protocol, reactor

factory = protocol.ServerFactory()
factory.protocol = protocol.Protocol

reactor.listenTCP(8000, factory)
reactor.run()

## Instruction:
Convert to endpoints API and use custom protocol class
## Code After:
from twisted.internet import endpoints, protocol, reactor

class UpperProtocol(protocol.Protocol):
    pass

factory = protocol.ServerFactory()
factory.protocol = UpperProtocol

endpoints.serverFromString(reactor, 'tcp:8000').listen(factory)
reactor.run()
