本文整理汇总了Python中socketserver.BaseServer类的典型用法代码示例。如果您正苦于以下问题:Python BaseServer类的具体用法?Python BaseServer怎么用?Python BaseServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BaseServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_error
def handle_error( self, request, client_address ):
# Override default behaviour of error handler in ThreadingMixIn
# the default handler prints and error message to stdout and stderr.
# Instead, this re-raises the exception so that it can be caught and
# dealt with sensibly!
print("handle_error!");
exc_type, exc_value, exc_traceback = sys.exc_info();
#if exc_type == SSL.Error and exc_value[0][0][2]=='http request':
print(exc_type);
print(exc_value);
print(exc_traceback);
print("OpenSLL error detected!");
# We would like to send back a BadRequest to the web-client indicating
# that they made an http request to this https server (like apache does).
# But this response message must be sent via http (not https), but this
# server's __init__ function sets up an SSL server, so this seems
# difficult to to.
# It might be possible to make a mixed server than can serve both types
# of requests, but this is left for later.
# Fall back to original error handler.
# Print: exc_type, exc_value, exc_traceback.
BaseServer.handle_error( self, request, client_address );
示例2: __init__
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
示例3: __init__
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()
示例4: __init__
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()
示例5: __init__
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()
示例6: __init__
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__
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()
示例8: __init__
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()
示例9: __init__
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()
示例10: __init__
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()
示例11: __init__
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()
示例12: __init__
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__
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()
示例14: __init__
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()
示例15: __init__
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()