当前位置: 首页>>代码示例>>Python>>正文


Python BaseHTTPServer.BaseHTTPRequestHandler方法代码示例

本文整理汇总了Python中BaseHTTPServer.BaseHTTPRequestHandler方法的典型用法代码示例。如果您正苦于以下问题:Python BaseHTTPServer.BaseHTTPRequestHandler方法的具体用法?Python BaseHTTPServer.BaseHTTPRequestHandler怎么用?Python BaseHTTPServer.BaseHTTPRequestHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BaseHTTPServer的用法示例。


在下文中一共展示了BaseHTTPServer.BaseHTTPRequestHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import BaseHTTPServer [as 别名]
# 或者: from BaseHTTPServer import BaseHTTPRequestHandler [as 别名]
def __init__(self,
               request,
               client_address,
               connection_handler=httplib.HTTPConnection):
    """Constructor extending BaseHTTPRequestHandler.

    Args:
      request: The incoming request.
      client_address: A (ip, port) tuple with the address of the client.
      backend: The HTTPServer that received the request.
      connection_handler: http library to use when balancer the connection to
        the next available backend instance. Used for dependency injection.
    """
    self.connection_handler = connection_handler
    BaseHTTPServer.BaseHTTPRequestHandler.__init__(self,
                                                   request,
                                                   client_address,
                                                   HttpServer()) 
开发者ID:elsigh,项目名称:browserscope,代码行数:20,代码来源:dev_appserver_multiprocess.py

示例2: handle_get

# 需要导入模块: import BaseHTTPServer [as 别名]
# 或者: from BaseHTTPServer import BaseHTTPRequestHandler [as 别名]
def handle_get(self):
        """Handle a single HTTP GET request.

        Default implementation indicates an error because
        XML-RPC uses the POST method.
        """

        code = 400
        message, explain = \
                 BaseHTTPServer.BaseHTTPRequestHandler.responses[code]

        response = BaseHTTPServer.DEFAULT_ERROR_MESSAGE % \
            {
             'code' : code,
             'message' : message,
             'explain' : explain
            }
        print 'Status: %d %s' % (code, message)
        print 'Content-Type: %s' % BaseHTTPServer.DEFAULT_ERROR_CONTENT_TYPE
        print 'Content-Length: %d' % len(response)
        print
        sys.stdout.write(response) 
开发者ID:glmcdona,项目名称:meddle,代码行数:24,代码来源:SimpleXMLRPCServer.py

示例3: __init__

# 需要导入模块: import BaseHTTPServer [as 别名]
# 或者: from BaseHTTPServer import BaseHTTPRequestHandler [as 别名]
def __init__(self):
        super(HttpServerThread, self).__init__()
        self.done = False
        self.hostname = 'localhost'

        class MockStardog(BaseHTTPRequestHandler):
            def do_GET(self):
                if self.path != '/admin/status':
                    self.send_response(404)
                    return
                self.send_response(200)
                self.send_header('Content-type', 'application/json')
                self.end_headers()
                # json.dumps always outputs a str, wfile.write requires bytes
                self.wfile.write(ensure_bytes(json.dumps(DATA)))

        self.http = HTTPServer((self.hostname, 0), MockStardog)
        self.port = self.http.server_port 
开发者ID:DataDog,项目名称:integrations-extras,代码行数:20,代码来源:test_stardog.py

示例4: handle_get

# 需要导入模块: import BaseHTTPServer [as 别名]
# 或者: from BaseHTTPServer import BaseHTTPRequestHandler [as 别名]
def handle_get(self):
        """Handle a single HTTP GET request.

        Default implementation indicates an error because
        XML-RPC uses the POST method.
        """

        code = 400
        message, explain = \
                 BaseHTTPServer.BaseHTTPRequestHandler.responses[code]

        response = BaseHTTPServer.DEFAULT_ERROR_MESSAGE % \
            {
             'code' : code,
             'message' : message,
             'explain' : explain
            }
        print 'Status: %d %s' % (code, message)
        print 'Content-Type: text/html'
        print 'Content-Length: %d' % len(response)
        print
        sys.stdout.write(response) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:24,代码来源:SimpleXMLRPCServer.py

示例5: start_server

# 需要导入模块: import BaseHTTPServer [as 别名]
# 或者: from BaseHTTPServer import BaseHTTPRequestHandler [as 别名]
def start_server():
    server_address = ('127.0.0.1', 0)

    class DaemonThreadingMixIn(ThreadingMixIn):
        daemon_threads = True

    class ThreadedHTTPServer(DaemonThreadingMixIn, HTTPServer):
        """Handle requests in a separate thread."""

    # not actually going to do anything with this server, so a
    # do-nothing handler is reasonable
    httpd = ThreadedHTTPServer(server_address, BaseHTTPRequestHandler)
    server_thread = threading.Thread(target=httpd.serve_forever)
    server_thread.daemon = True
    server_thread.start()
    return httpd, server_thread 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:18,代码来源:test_socket_jy.py

示例6: setup

# 需要导入模块: import BaseHTTPServer [as 别名]
# 或者: from BaseHTTPServer import BaseHTTPRequestHandler [as 别名]
def setup(self):
        if isinstance(self.__class__.first_run, collections.Callable):
            try:
                with self.__class__.first_run_lock:
                    if isinstance(self.__class__.first_run, collections.Callable):
                        self.first_run()
                        self.__class__.first_run = None
            except StandardError as e:
                logging.exception('%s.first_run() return %r', self.__class__, e)
        self.__class__.setup = BaseHTTPServer.BaseHTTPRequestHandler.setup
        self.__class__.do_CONNECT = self.__class__.do_METHOD
        self.__class__.do_GET = self.__class__.do_METHOD
        self.__class__.do_PUT = self.__class__.do_METHOD
        self.__class__.do_POST = self.__class__.do_METHOD
        self.__class__.do_HEAD = self.__class__.do_METHOD
        self.__class__.do_DELETE = self.__class__.do_METHOD
        self.__class__.do_OPTIONS = self.__class__.do_METHOD
        self.__class__.do_PATCH = self.__class__.do_METHOD
        self.setup() 
开发者ID:projectarkc,项目名称:arkc-client,代码行数:21,代码来源:proxylib.py

示例7: handle_one_request

# 需要导入模块: import BaseHTTPServer [as 别名]
# 或者: from BaseHTTPServer import BaseHTTPRequestHandler [as 别名]
def handle_one_request(self):
        if not self.disable_transport_ssl and self.scheme == 'http':
            leadbyte = self.connection.recv(1, socket.MSG_PEEK)
            if leadbyte in ('\x80', '\x16'):
                server_name = ''
                if leadbyte == '\x16':
                    for _ in xrange(2):
                        leaddata = self.connection.recv(1024, socket.MSG_PEEK)
                        if is_clienthello(leaddata):
                            try:
                                server_name = extract_sni_name(leaddata)
                            finally:
                                break
                try:
                    certfile = CertUtil.get_cert(server_name or 'www.google.com')
                    ssl_sock = ssl.wrap_socket(self.connection, ssl_version=self.ssl_version, keyfile=certfile, certfile=certfile, server_side=True)
                except StandardError as e:
                    if e.args[0] not in (errno.ECONNABORTED, errno.ECONNRESET):
                        logging.exception('ssl.wrap_socket(self.connection=%r) failed: %s', self.connection, e)
                    return
                self.connection = ssl_sock
                self.rfile = self.connection.makefile('rb', self.bufsize)
                self.wfile = self.connection.makefile('wb', 0)
                self.scheme = 'https'
        return BaseHTTPServer.BaseHTTPRequestHandler.handle_one_request(self) 
开发者ID:projectarkc,项目名称:arkc-client,代码行数:27,代码来源:proxylib.py

示例8: handle

# 需要导入模块: import BaseHTTPServer [as 别名]
# 或者: from BaseHTTPServer import BaseHTTPRequestHandler [as 别名]
def handle(self):

        ''' To quiet socket errors with 404.
        '''
        try:
            BaseHTTPServer.BaseHTTPRequestHandler.handle(self)
        except Exception as error:
            pass 
开发者ID:MediaBrowser,项目名称:plugin.video.emby,代码行数:10,代码来源:webservice.py

示例9: __init__

# 需要导入模块: import BaseHTTPServer [as 别名]
# 或者: from BaseHTTPServer import BaseHTTPRequestHandler [as 别名]
def __init__(self, *args):
        try:
            BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args)
        except IOError:
            pass 
开发者ID:masmu,项目名称:pulseaudio-dlna,代码行数:7,代码来源:streamserver.py

示例10: log_request

# 需要导入模块: import BaseHTTPServer [as 别名]
# 或者: from BaseHTTPServer import BaseHTTPRequestHandler [as 别名]
def log_request(self, code='-', size='-'):
      """Indicate that this request has completed."""
      BaseHTTPServer.BaseHTTPRequestHandler.log_request(self, code, size)
      if code == '-':
        code = 0
      if size == '-':
        size = 0


      logservice.logs_buffer().flush()
      self._log_record_writer.end_request(None, code, size) 
开发者ID:elsigh,项目名称:browserscope,代码行数:13,代码来源:dev_appserver.py

示例11: handle_one_request

# 需要导入模块: import BaseHTTPServer [as 别名]
# 或者: from BaseHTTPServer import BaseHTTPRequestHandler [as 别名]
def handle_one_request(self):
    """Override. Invoked from BaseHTTPRequestHandler constructor."""
    self.raw_requestline = self.rfile.readline()
    if not self.raw_requestline:
      self.close_connection = 1
      return
    if not self.parse_request():
      return

    process = GlobalProcess()
    balance_set = process.GetBalanceSet()
    request_size = int(self.headers.get('content-length', 0))
    payload = self.rfile.read(request_size)




    for port in balance_set:
      logging.debug('balancer to port %d',  port)
      connection = self.connection_handler(process.host, port=port)


      connection.response_class = ForwardResponse
      connection.request(self.command, self.path, payload, dict(self.headers))
      try:
        response = connection.getresponse()
      except httplib.HTTPException, e:


        self.send_error(httplib.INTERNAL_SERVER_ERROR, str(e))
        return

      if response.status != httplib.SERVICE_UNAVAILABLE:
        self.wfile.write(response.data)
        return 
开发者ID:elsigh,项目名称:browserscope,代码行数:37,代码来源:dev_appserver_multiprocess.py

示例12: log_request

# 需要导入模块: import BaseHTTPServer [as 别名]
# 或者: from BaseHTTPServer import BaseHTTPRequestHandler [as 别名]
def log_request(self, code='-', size='-'):
        """Selectively log an accepted request."""

        if self.server.logRequests:
            BaseHTTPServer.BaseHTTPRequestHandler.log_request(self, code, size) 
开发者ID:glmcdona,项目名称:meddle,代码行数:7,代码来源:SimpleXMLRPCServer.py

示例13: serve

# 需要导入模块: import BaseHTTPServer [as 别名]
# 或者: from BaseHTTPServer import BaseHTTPRequestHandler [as 别名]
def serve(port, callback=None, completer=None):
    import BaseHTTPServer, mimetools, select

    # Patch up mimetools.Message so it doesn't break if rfc822 is reloaded.
    class Message(mimetools.Message):
        def __init__(self, fp, seekable=1):
            Message = self.__class__
            Message.__bases__[0].__bases__[0].__init__(self, fp, seekable)
            self.encodingheader = self.getheader('content-transfer-encoding')
            self.typeheader = self.getheader('content-type')
            self.parsetype()
            self.parseplist()

    class DocHandler(BaseHTTPServer.BaseHTTPRequestHandler):
        def send_document(self, title, contents):
            try:
                self.send_response(200)
                self.send_header('Content-Type', 'text/html')
                self.end_headers()
                self.wfile.write(html.page(title, contents))
            except IOError: pass

        def do_GET(self):
            path = self.path
            if path[-5:] == '.html': path = path[:-5]
            if path[:1] == '/': path = path[1:]
            if path and path != '.':
                try:
                    obj = locate(path, forceload=1)
                except ErrorDuringImport, value:
                    self.send_document(path, html.escape(str(value)))
                    return
                if obj:
                    self.send_document(describe(obj), html.document(obj, path))
                else:
                    self.send_document(path,
'no Python documentation found for %s' % repr(path))
            else: 
开发者ID:glmcdona,项目名称:meddle,代码行数:40,代码来源:pydoc.py

示例14: request_handler

# 需要导入模块: import BaseHTTPServer [as 别名]
# 或者: from BaseHTTPServer import BaseHTTPRequestHandler [as 别名]
def request_handler(addr):
    class RequestHandler(BaseHTTPRequestHandler):
        def do_GET(self):
            if self.path == '/provider.json':
                body = provider_json % {
                    'api_uri': addr.api_uri,
                    'host': addr.host,
                    'port': addr.port,
                    'fingerprint': addr.fingerprint
                }

            elif self.path == '/ca.crt':
                cacert = os.path.join(os.path.dirname(__file__),
                                      "leaptestscert.pem")
                with open(cacert, 'r') as f:
                    castr = f.read()
                body = castr

            elif self.path == '/1/configs.json':
                body = configs_json

            else:
                body = '{"error": "not implemented"}'

            self.send_response(200)
            self.send_header('Content-type', 'applicatino/json')
            self.send_header('Content-Length', str(len(body)))
            self.end_headers()
            self.wfile.write(body)

    return RequestHandler 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:33,代码来源:test_config.py

示例15: __init__

# 需要导入模块: import BaseHTTPServer [as 别名]
# 或者: from BaseHTTPServer import BaseHTTPRequestHandler [as 别名]
def __init__(self, *args, **kwargs):
        BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args, **kwargs) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_urllib2_localnet.py


注:本文中的BaseHTTPServer.BaseHTTPRequestHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。