コード例 #1
0
ファイル: _cpserver.py プロジェクト: bieschke/nuffle
def configure():
    """Perform one-time actions to prepare the CherryPy core."""
    if cherrypy.codecoverage:
        from cherrypy.lib import covercp
        covercp.start()
    
    conf = cherrypy.config.get
    # TODO: config.checkConfigOptions()
    
    # If sessions are stored in files and we
    # use threading, we need a lock on the file
    if (conf('server.threadPool') > 1
        and conf('session.storageType') == 'file'):
        cherrypy._sessionFileLock = threading.RLock()
    
    # set cgi.maxlen which will limit the size of POST request bodies
    cgi.maxlen = conf('server.maxRequestSize')
    
    # Set up the profiler if requested.
    if conf("profiling.on", False):
        ppath = conf("profiling.path", "")
        cherrypy.profiler = profiler.Profiler(ppath)
    else:
        cherrypy.profiler = None
    
    # Initialize the built in filters
    cherrypy._cputil._cpInitDefaultFilters()
    cherrypy._cputil._cpInitUserDefinedFilters()
コード例 #2
0
ファイル: _cpengine.py プロジェクト: thraxil/gtreed
    def request(self, clientAddress, remoteHost, scheme="http"):
        """Obtain an HTTP Request object.
        
        clientAddress: the (IP address, port) of the client
        remoteHost: the IP address of the client
        scheme: either "http" or "https"; defaults to "http"
        """
        if self.state == STOPPED:
            raise cherrypy.NotReady("The CherryPy server has stopped.")
        elif self.state == STARTING:
            raise cherrypy.NotReady("The CherryPy server could not start.")

        threadID = threading._get_ident()
        if threadID not in self.seen_threads:

            if cherrypy.codecoverage:
                from cherrypy.lib import covercp

                covercp.start()

            i = len(self.seen_threads) + 1
            self.seen_threads[threadID] = i

            for func in self.on_start_thread_list:
                func(i)

        r = self.request_class(clientAddress[0], clientAddress[1], remoteHost, scheme)
        cherrypy.serving.request = r
        cherrypy.serving.response = self.response_class()
        return r
コード例 #3
0
ファイル: _cpengine.py プロジェクト: thraxil/gtreed
    def setup(self):
        # The only reason this method isn't in __init__ is so that
        # "import cherrypy" can create an Engine() without a circular ref.
        conf = cherrypy.config.get

        # Output config options to log
        if conf("server.log_config_options", True):
            cherrypy.config.outputConfigMap()

        # Hmmm...we *could* check config in _start instead, but I think
        # most people would like CP to fail before autoreload kicks in.
        err = cherrypy.WrongConfigValue
        for name, section in cherrypy.config.configs.iteritems():
            for k, v in section.iteritems():
                if k == "server.environment":
                    if v and v not in cherrypy.config.environments:
                        raise err("'%s' is not a registered environment." % v)

        if cherrypy.codecoverage:
            from cherrypy.lib import covercp

            covercp.start()

        # If sessions are stored in files and we
        # use threading, we need a lock on the file
        if conf("server.thread_pool") > 1 and conf("session.storage_type") == "file":
            cherrypy._sessionFileLock = threading.RLock()

        # set cgi.maxlen which will limit the size of POST request bodies
        cgi.maxlen = conf("server.max_request_size")

        # Set up the profiler if requested.
        if conf("profiling.on", False):
            ppath = conf("profiling.path", "")
            cherrypy.profiler = profiler.Profiler(ppath)
        else:
            cherrypy.profiler = None

        # Initialize the built in filters
        filters.init()
コード例 #4
0
ファイル: _cpserver.py プロジェクト: bieschke/nuffle
 def request(self, clientAddress, remoteHost, requestLine,
             headers, rfile, scheme="http"):
     """request(clientAddress, remoteHost, requestLine, headers, rfile, scheme="http")
     
     clientAddress: the (IP address, port) of the client
     remoteHost: the IP address of the client
     requestLine: "<HTTP method> <url?qs> HTTP/<version>",
             e.g. "GET /main?abc=123 HTTP/1.1"
     headers: a list of (key, value) tuples
     rfile: a file-like object from which to read the HTTP request body
     scheme: either "http" or "https"; defaults to "http"
     """
     if self.state == STOPPED:
         raise cherrypy.NotReady("The CherryPy server has stopped.")
     elif self.state == STARTING:
         raise cherrypy.NotReady("The CherryPy server could not start.")
     
     threadID = threading._get_ident()
     if threadID not in seen_threads:
         
         if cherrypy.codecoverage:
             from cherrypy.lib import covercp
             covercp.start()
         
         i = len(seen_threads) + 1
         seen_threads[threadID] = i
         
         for func in self.onStartThreadList:
             func(i)
     
     if cherrypy.profiler:
         cherrypy.profiler.run(_cphttptools.Request, clientAddress, remoteHost,
                               requestLine, headers, rfile, scheme)
     else:
         _cphttptools.Request(clientAddress, remoteHost,
                              requestLine, headers, rfile, scheme)