本文整理汇总了Python中socketserver.BaseServer.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python BaseServer.__init__方法的具体用法?Python BaseServer.__init__怎么用?Python BaseServer.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socketserver.BaseServer
的用法示例。
在下文中一共展示了BaseServer.__init__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from socketserver import BaseServer [as 别名]
# 或者: from socketserver.BaseServer import __init__ [as 别名]
def __init__(self, server_address, RequestHandlerClass, maxthreads=100, pemfile=None, rest_handlers=None, userpass=None):
try:
if pemfile: #HTTPS server
BaseServer.__init__(self, server_address, RequestHandlerClass)
ctx = SSL.Context(SSL.SSLv23_METHOD)
ctx.use_privatekey_file(pemfile)
ctx.use_certificate_file(pemfile)
self.socket = SSL.Connection(ctx, socket.socket(self.address_family, self.socket_type))
self.server_bind()
self.server_activate()
self.httpstyle = "HTTPS"
else: #HTTP server
BaseHTTPServer.__init__(self, server_address, RequestHandlerClass)
self.httpstyle = "HTTP"
except socket.error as e:
if e.errno == 98:
logging.log(logging.ERROR, "Cannot start HTTP server, address already in use")
return
else:
raise
self.lock = thread.allocate_lock()
self.maxthreads = maxthreads
self.threads = 0
self.rest_handlers = rest_handlers
self.userpass = userpass
示例2: __init__
# 需要导入模块: from socketserver import BaseServer [as 别名]
# 或者: from socketserver.BaseServer import __init__ [as 别名]
def __init__(self, server_address, HandlerClass):
BaseServer.__init__(self, server_address, HandlerClass)
ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
ctx.load_cert_chain(certfile=CERT, keyfile=KEY)
self.socket = ctx.wrap_socket(socket.socket(self.address_family, self.socket_type), server_side=True)
self.server_bind()
self.server_activate()
示例3: __init__
# 需要导入模块: from socketserver import BaseServer [as 别名]
# 或者: from socketserver.BaseServer import __init__ [as 别名]
def __init__(self, server_address, RequestHandlerClass, bind_and_activate=True):
BaseServer.__init__(self, server_address, RequestHandlerClass)
self.socket = ssl.wrap_socket(socket.socket(self.address_family, self.socket_type),
"./server.key", "./server.crt", True, ssl.CERT_REQUIRED,
ssl.PROTOCOL_TLSv1, "./trusted.crt")
if bind_and_activate:
self.server_bind()
self.server_activate()
示例4: __init__
# 需要导入模块: from socketserver import BaseServer [as 别名]
# 或者: from socketserver.BaseServer import __init__ [as 别名]
def __init__(self, server_address, HandlerClass):
BaseServer.__init__(self, server_address, HandlerClass)
self.socket = ssl.SSLSocket(
sock=socket.socket(self.address_family, self.socket_type),
ssl_version=ssl.PROTOCOL_TLSv1,
certfile='server.pem',
server_side=True)
self.server_bind()
self.server_activate()
示例5: __init__
# 需要导入模块: from socketserver import BaseServer [as 别名]
# 或者: from socketserver.BaseServer import __init__ [as 别名]
def __init__(self,address,handler):
BaseServer.__init__(self,address,handler)
self.socket = ssl.SSLSocket(
sock=socket.socket(self.address_family,self.socket_type),
ssl_version=ssl.PROTOCOL_TLSv1,
certfile=os.path.join(os.path.dirname(__file__), 'test.pem'),
server_side=True)
self.server_bind()
self.server_activate()
示例6: __init__
# 需要导入模块: from socketserver import BaseServer [as 别名]
# 或者: from socketserver.BaseServer import __init__ [as 别名]
def __init__(self, server_address, multicast_group, RequestHandlerClass, bind_and_activate=True, multicast_ttl = 1):
BaseServer.__init__(self, server_address, RequestHandlerClass)
self.socket = socket.socket(self.address_family,
self.socket_type,
self.protocol_type)
self.multicast_group = multicast_group
self.multicast_ttl = multicast_ttl
if bind_and_activate:
self.server_bind()
self.server_activate()
示例7: __init__
# 需要导入模块: from socketserver import BaseServer [as 别名]
# 或者: from socketserver.BaseServer import __init__ [as 别名]
def __init__(self, server_address, HandlerClass):
BaseServer.__init__(self, server_address, HandlerClass)
ctx = SSL.Context(SSL.SSLv23_METHOD)
fpem = MongoServer.pem
ctx.use_privatekey_file(fpem)
ctx.use_certificate_file(fpem)
self.socket = SSL.Connection(ctx, socket.socket(self.address_family,
self.socket_type))
self.server_bind()
self.server_activate()
示例8: __init__
# 需要导入模块: from socketserver import BaseServer [as 别名]
# 或者: from socketserver.BaseServer import __init__ [as 别名]
def __init__(self, address, handler):
"""
Initialise the secure handlers for the SSL server if required.s
"""
BaseServer.__init__(self, address, handler)
local_data = AppLocation.get_directory(AppLocation.DataDir)
self.socket = ssl.SSLSocket(
sock=socket.socket(self.address_family, self.socket_type),
certfile=os.path.join(local_data, 'remotes', 'openlp.crt'),
keyfile=os.path.join(local_data, 'remotes', 'openlp.key'),
server_side=True)
self.server_bind()
self.server_activate()
示例9: __init__
# 需要导入模块: from socketserver import BaseServer [as 别名]
# 或者: from socketserver.BaseServer import __init__ [as 别名]
def __init__(self, server_address, HandlerClass):
BaseServer.__init__(self, server_address, HandlerClass)
ctx = SSL.Context(SSL.SSLv23_METHOD)
# server.pem's location (containing the server private key and
# the server certificate).
fpem_priv = 'newreq.pem' # server
fpem_cli = 'newcert.pem' # cli
ctx.use_privatekey_file(fpem_priv)
ctx.use_certificate_file(fpem_cli)
self.socket = SSL.Connection(ctx, socket.socket(self.address_family,
self.socket_type))
self.server_bind()
self.server_activate()
示例10: __init__
# 需要导入模块: from socketserver import BaseServer [as 别名]
# 或者: from socketserver.BaseServer import __init__ [as 别名]
def __init__(self, server_address, HandlerClass):
BaseServer.__init__(self, server_address, HandlerClass)
ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
fpem = '../cacert.crt'
ctx.load_verify_locations(fpem)
ctx.verify_mode = ssl.CERT_NONE
self.socket = ssl.SSLSocket(ctx, socket.socket(self.address_family,
self.socket_type),
certfile = fpem)
self.server_bind()
self.server_activate()
示例11: __init__
# 需要导入模块: from socketserver import BaseServer [as 别名]
# 或者: from socketserver.BaseServer import __init__ [as 别名]
def __init__ (self, address, handler):
import ssl
BaseServer.__init__ (self, address, handler)
# step one up because test suite change directory away from $srcdir (don't do that !!!)
CERTFILE = os.path.abspath(os.path.join('..', os.getenv('srcdir', '.'), 'certs', 'wget-cert.pem'))
fop = open (CERTFILE)
print (fop.readline())
self.socket = ssl.wrap_socket (
sock = socket.socket (self.address_family, self.socket_type),
ssl_version = ssl.PROTOCOL_TLSv1,
certfile = CERTFILE,
server_side = True
)
self.server_bind()
self.server_activate()
示例12: __init__
# 需要导入模块: from socketserver import BaseServer [as 别名]
# 或者: from socketserver.BaseServer import __init__ [as 别名]
def __init__ (self, address, handler):
BaseServer.__init__ (self, address, handler)
print (os.getcwd())
CERTFILE = os.path.abspath (os.path.join ('..', 'certs', 'wget-cert.pem'))
print (CERTFILE)
fop = open (CERTFILE)
print (fop.readline())
self.socket = ssl.wrap_socket (
sock = socket.socket (self.address_family, self.socket_type),
ssl_version = ssl.PROTOCOL_TLSv1,
certfile = CERTFILE,
server_side = True
)
self.server_bind ()
self.server_activate ()
示例13: __init__
# 需要导入模块: from socketserver import BaseServer [as 别名]
# 或者: from socketserver.BaseServer import __init__ [as 别名]
def __init__(self, server_address, HandlerClass):
BaseServer.__init__(self, server_address, HandlerClass)
# SSLv2 and SSLv3 supported
ctx = SSL.Context(SSL.SSLv23_METHOD)
# pem files defined before
fpem_priv = 'newreq.pem'
fpem_cli = 'newcert.pem'
# establish private key
ctx.use_privatekey_file(fpem_priv)
# establish public/client certificate
ctx.use_certificate_file(fpem_cli)
# setup the ssl socket
self.socket = SSL.Connection(ctx, socket.socket(
self.address_family, self.socket_type))
# bind to interface
self.server_bind()
# activate the interface
self.server_activate()
示例14: __init__
# 需要导入模块: from socketserver import BaseServer [as 别名]
# 或者: from socketserver.BaseServer import __init__ [as 别名]
def __init__(self, server_address, HandlerClass, options):
BaseServer.__init__(self, server_address, HandlerClass)
pwd = os.path.dirname(os.path.realpath(__file__))
keys = os.path.join(pwd,options.key)
certs = os.path.join(pwd,options.cert)
self.options = options
self.daemon_threads = True
self.protocol_version = 'HTTP/1.1'
if options.clientverify:
self.socket = ssl.wrap_socket(socket.socket(self.address_family, self.socket_type),
keyfile=keys, certfile=certs, server_side=True, cert_reqs=ssl.CERT_REQUIRED, ca_certs='/etc/ssl/certs/ca-certificates.crt')
else:
self.socket = ssl.wrap_socket(socket.socket(self.address_family, self.socket_type),
keyfile=keys, certfile=certs, server_side=True)
self.server_bind()
self.server_activate()
示例15: __init__
# 需要导入模块: from socketserver import BaseServer [as 别名]
# 或者: from socketserver.BaseServer import __init__ [as 别名]
def __init__(self, address, handler):
global logger
try:
BaseServer.__init__(self, address, handler)
self.socket = ssl.SSLSocket(
sock=socket.socket(self.address_family, self.socket_type),
ssl_version=ssl.PROTOCOL_TLSv1,
certfile=settings.ServerParams["Certificate"],
server_side=True)
self.server_bind()
self.server_activate()
# create http logger
logger = logging.getLogger('HTTP')
logger.setLevel(settings.SystemParams["LogLevel"])
logger.addHandler(log.ch)
logger.info('HTTPS server started. Press ^C to stop')
except Exception as err:
Logger.error('Error during HTTPS server starting')