本文整理汇总了Python中twisted.internet.protocol.ServerFactory.contextFactory方法的典型用法代码示例。如果您正苦于以下问题:Python ServerFactory.contextFactory方法的具体用法?Python ServerFactory.contextFactory怎么用?Python ServerFactory.contextFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.protocol.ServerFactory
的用法示例。
在下文中一共展示了ServerFactory.contextFactory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TLSServer
# 需要导入模块: from twisted.internet.protocol import ServerFactory [as 别名]
# 或者: from twisted.internet.protocol.ServerFactory import contextFactory [as 别名]
from twisted.internet import reactor, ssl
from twisted.internet.protocol import ServerFactory
from twisted.protocols.basic import LineReceiver
class TLSServer(LineReceiver):
def lineReceived(self, line):
print "received: " + line
if line == "STARTTLS":
print "-- Switching to TLS"
self.sendLine('READY')
self.transport.startTLS(self.factory.contextFactory)
if __name__ == '__main__':
with open("key.pem") as keyFile:
with open("selfcert.pem") as certFile:
cert = ssl.PrivateCertificate.loadPEM(
keyFile.read() + certFile.read())
factory = ServerFactory()
factory.protocol = TLSServer
factory.contextFactory = cert.options()
reactor.listenTCP(8001, factory)
reactor.run()