本文整理汇总了Python中http.server.BaseHTTPRequestHandler类的典型用法代码示例。如果您正苦于以下问题:Python BaseHTTPRequestHandler类的具体用法?Python BaseHTTPRequestHandler怎么用?Python BaseHTTPRequestHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BaseHTTPRequestHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_response
def send_response(self, code: Union[int, HTTPStatus], message=None):
"""Fill in HTTP status message if not set."""
if message is None:
if isinstance(code, HTTPStatus):
message = code.phrase
code = code.value
BaseHTTPRequestHandler.send_response(self, code=code, message=message)
示例2: __init__
def __init__(self, *args, **kwargs):
from django.conf import settings
self.admin_media_prefix = settings.ADMIN_MEDIA_PREFIX
# We set self.path to avoid crashes in log_message() on unsupported
# requests (like "OPTIONS").
self.path = ''
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
示例3: finish
def finish(self):
"""make python2 BaseHTTPRequestHandler happy"""
try:
BaseHTTPRequestHandler.finish(self)
except (IOError, OSError) as e:
if e[0] not in (errno.ECONNABORTED, errno.ECONNRESET, errno.EPIPE):
raise
示例4: __init__
def __init__(self, *args, **kwargs):
from google.appengine._internal.django.conf import settings
self.admin_media_prefix = settings.ADMIN_MEDIA_PREFIX
# We set self.path to avoid crashes in log_message() on unsupported
# requests (like "OPTIONS").
self.path = ''
self.style = color_style()
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
示例5: __init__
def __init__(self, request, client_address, origin):
self.origin = origin
#if __name__ != '__main__':
# self.origin.log('postman initializing as plugin..', 2)
#else:
# self.origin.log('postman initializing as standalone application..', 2)
# ^ works
BaseHTTPRequestHandler.__init__(self, request, client_address, origin)
示例6: __init__
def __init__(self, request, client_address, server):
'''
:param request: the request from the client
:param client_address: client address
:param server: HTTP server
'''
BaseHTTPRequestHandler.__init__(
self, request, client_address, server)
self.dataman = None
示例7: __init__
def __init__(self, request, client_address, server):
try:
mimetypes.init()
self.DebugMode = False
BaseHTTPRequestHandler.__init__(self, request, client_address, server)
except:
ReportException()
示例8: test
def test(handler):
sess_id = handler.query.split('=',1)[1]
handler.send_response(200)
handler.send_header("Content-type", "text/html")
msg = "{}={}".format(sess_id, 1000)
handler.send_header("Content-length", str(len(msg)))
handler.send_header("Connection", "close")
handler.end_headers()
BaseHTTPRequestHandler.end_headers(handler)
handler.wfile.write("{}!".format(msg))
示例9: __init__
def __init__(self, *args, **kwargs):
sock = socket_wrapper.Socket(unix_socket=True)
sock.make_nonblocking()
if not sock.connect_unix(os.path.expanduser(PETTYCOIN_SOCKET)):
logging.error('Could not open socket: {}'.format(PETTYCOIN_SOCKET))
sys.exit(1)
self.petty_sock = sock
self.petty_reader = JsonSocketReader(sock)
self.html_parser = HTMLParser()
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
示例10: __init__
def __init__(self, http_svc, *args, **kwargs):
"""
Sets up the request handler (called for each request)
:param http_svc: The associated HTTP service
"""
self._service = http_svc
# This calls the do_* methods
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
示例11: __init__
def __init__(self, request, client, server):
request.settimeout(60.)
try:
BaseHTTPRequestHandler.__init__(self, request, client, server)
except OSError as e:
if server.debug:
logger.exception("OSError in http request")
else:
logger.error("%s", e)
except Exception:
logger.exception("Unhandle Error")
示例12: __init__
def __init__(self, http_svc, *args, **kwargs):
"""
Constructor
:param http_svc: The associated HTTP service instance
"""
# Store the reference to the service
self.service = http_svc
# Call the parent constructor
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
示例13: log_message
def log_message(self, *args, **kwargs):
if self.command == 'POST':
sys.stderr.write('{addr} - - [{datetime}] "POST {path} {req_ver}" {statuscode} {data}\n'.format(
addr=self.address_string(),
datetime=self.log_date_time_string(),
path=self.path,
req_ver=self.request_version,
statuscode=args[2],
data=self.POST_data.decode(),
))
else:
BaseHTTPRequestHandler.log_message(self, *args, **kwargs)
示例14: send_response
def send_response(self, mesg, code=200, headers=None):
'Wraps sending a response down'
if not headers:
headers = {}
if 'Content-Type' not in headers:
headers['Content-Type'] = 'text/html'
BaseHTTPRequestHandler.send_response(self, code)
self.send_header('Content-Length', len(mesg))
if headers:
for k, v in headers.items():
self.send_header(k, v)
self.end_headers()
self.wfile.write(mesg)
示例15: handle_one_request
def handle_one_request(self):
"""Extended request handler
This is where WebSocketRequestHandler redirects requests to the
new methods. Any sub-classes must call this method in order for
the calls to function.
"""
self._real_do_GET = self.do_GET
self.do_GET = self._websocket_do_GET
try:
BaseHTTPRequestHandler.handle_one_request(self)
finally:
self.do_GET = self._real_do_GET