Anonymous avatar Anonymous committed 9bd0481

Deprecated "initOnly" and "serverClass". New names are "init_only" and "server_class"

Comments (0)

Files changed (6)

cherrypy/_cpserver.py

         self.onStartServerList = []
         self.onStopThreadList = []
     
-    def start(self, initOnly=False, serverClass=_missing):
+    def start(self, init_only = False, server_class = _missing,
+                initOnly = None, serverClass = None):
         """Main function. MUST be called from the main thread.
         
         Set initOnly to True to keep this function from blocking.
         Set serverClass to None to skip starting any HTTP server.
         """
+        
+        # Read old variable names for backward compatibility
+        if initOnly is not None:
+            init_only = initOnly
+        if serverClass is not None:
+            server_class = serverClass
+
         self.state = STARTING
         self.interrupt = None
         
         conf = cherrypy.config.get
         
-        if serverClass is _missing:
-            serverClass = conf("server.class", _missing)
-        if serverClass is _missing:
+        if server_class is _missing:
+            server_class = conf("server.class", _missing)
+        if server_class is _missing:
             import _cpwsgi
-            serverClass = _cpwsgi.WSGIServer
-        elif serverClass and isinstance(serverClass, basestring):
+            server_class = _cpwsgi.WSGIServer
+        elif server_class and isinstance(server_class, basestring):
             # Dynamically load the class from the given string
-            serverClass = cptools.attributes(serverClass)
+            server_class = cptools.attributes(server_class)
         
-        self.blocking = not initOnly
-        self.httpserverclass = serverClass
+        self.blocking = not init_only
+        self.httpserverclass = server_class
         
         # Hmmm...we *could* check config in _start instead, but I think
         # most people would like CP to fail before autoreload kicks in.
         check_config()
         
-        # Autoreload, but check serverClass. If None, we're not starting
+        # Autoreload, but check server_class. If None, we're not starting
         # our own webserver, and therefore could do Very Bad Things when
         # autoreload calls sys.exit.
-        if serverClass is not None:
+        if server_class is not None:
             if conf('autoreload.on', False):
                 try:
                     freq = conf('autoreload.frequency', 1)
                                     " receive requests, False otherwise.")
     
     def start_with_callback(self, func, args=None, kwargs=None,
-                            serverClass=_missing):
+                            server_class = _missing, serverClass = None):
         """Start, then callback the given func in a new thread."""
+
+        # Read old name for backward compatibility
+        if serverClass is not None:
+            server_class = None
+
         if args is None:
             args = ()
         if kwargs is None:
             func(*args, **kwargs)
         threading.Thread(target=_callback, args=args, kwargs=kwargs).start()
         
-        self.start(serverClass=serverClass)
+        self.start(server_class = server_class)
 
 
 def check_config():

cherrypy/test/helper.py

     """
     setConfig(conf)
     cherrypy.server.start_with_callback(_run_test_suite_thread,
-                                        args=(moduleNames, conf),
-                                        serverClass=server)
+            args = (moduleNames, conf), server_class = server)
 
 def _run_test_suite_thread(moduleNames, conf):
     for testmod in moduleNames:
     if conf is None:
         conf = {}
     setConfig(conf)
-    cherrypy.server.start_with_callback(_test_main_thread, serverClass=server)
+    cherrypy.server.start_with_callback(_test_main_thread,
+            server_class = server)
 
 def _test_main_thread():
     try:

cherrypy/test/test_noserver.py

 cherrypy.root.test = HelloWorld()
 
 cherrypy.config.update({"server.environment": "production"})
-cherrypy.server.start(serverClass=None)
+cherrypy.server.start(server_class = None)
 

cherrypy/test/test_states.py

         self.assertEqual(len(db_connection.threads), 0)
         
         # Test server start
-        cherrypy.server.start(True, self.serverClass)
+        cherrypy.server.start(True, self.server_class)
         self.assertEqual(cherrypy.server.state, 1)
         
-        if self.serverClass:
+        if self.server_class:
             host = cherrypy.config.get('server.socket_host')
             port = cherrypy.config.get('server.socket_port')
             self.assertRaises(IOError, cherrypy._cpserver.check_port, host, port)
         self.assertEqual(len(db_connection.threads), 0)
     
     def test_1_Restart(self):
-        cherrypy.server.start(True, self.serverClass)
+        cherrypy.server.start(True, self.server_class)
         
         # The db_connection should be running now
         self.assertEqual(db_connection.running, True)
         self.assertEqual(len(db_connection.threads), 0)
     
     def test_2_KeyboardInterrupt(self):
-        if self.serverClass:
+        if self.server_class:
             
             # Raise a keyboard interrupt in the HTTP server's main thread.
             def interrupt():
             threading.Thread(target=interrupt).start()
             
             # We must start the server in this, the main thread
-            cherrypy.server.start(False, self.serverClass)
+            cherrypy.server.start(False, self.server_class)
             # Time passes...
             self.assertEqual(cherrypy.server.httpserver, None)
             self.assertEqual(cherrypy.server.state, 0)
                 self.assertRaises(BadStatusLine, self.getPage, "/ctrlc")
             threading.Thread(target=interrupt).start()
             
-            cherrypy.server.start(False, self.serverClass)
+            cherrypy.server.start(False, self.server_class)
             # Time passes...
             self.assertEqual(cherrypy.server.httpserver, None)
             self.assertEqual(cherrypy.server.state, 0)
     
     def test_3_ConfigErrors(self):
         cherrypy.config.update({'server.environment': 'destruction'})
+        
         try:
             self.assertRaises(cherrypy.WrongConfigValue,
-                              cherrypy.server.start, True, self.serverClass)
+                    cherrypy.server.start, True, self.server_class)
         finally:
             cherrypy.server.stop()
 
 
 def run(server, conf):
     helper.setConfig(conf)
-    ServerStateTests.serverClass = server
+    ServerStateTests.server_class = server
     suite = helper.CPTestLoader.loadTestsFromTestCase(ServerStateTests)
     try:
         global db_connection

cherrypy/test/test_xmlrpc_filter.py

 
 if __name__ == '__main__':
     from cherrypy import _cpwsgi
-    serverClass = _cpwsgi.WSGIServer
-    helper.testmain(serverClass)
+    server_class = _cpwsgi.WSGIServer
+    helper.testmain(server_class)
 

docs/book/xml/apireference.xml

     <section id="cherrypyserver">
         <title>cherrypy.server</title>
         <section>
-            <title>cherrypy.server.start(initOnly=False, serverClass=_missing)</title>
+            <title>cherrypy.server.start(init_only = False, server_class = _missing)</title>
             <para>Start the CherryPy Server. Simple websites may call this without any arguments, to
-            run the default server. If initOnly is False (the default), this function will block
+            run the default server. If init_only is False (the default), this function will block
             until KeyboardInterrupt or SystemExit is raised, so that the process will persist. When
             using one of the built-in HTTP servers, you should leave this set to False. You should
             only set it to True if you're running CherryPy as an extension to another HTTP server
             (for example, when using Apache and mod_python with CherryPy), in which case the foreign
             HTTP server should do its own process-management.</para>
-            <para>Use the serverClass argument to specify that you wish to use an HTTP server other
+            <para>Use the server_class argument to specify that you wish to use an HTTP server other
             than the default, built-in WSGIServer. If missing, config.get("server.class") will be
             checked for an alternate value; otherwise, the default is used. Possible alternate values
             (you may pass the class names as a string if you wish):</para>
                 </listitem>
                 <listitem>
                     <para><code>None</code>: this will not load any HTTP server. Note that this is
-                    not the default; the default (if serverClass is not given) is to load the
+                    not the default; the default (if server_class is not given) is to load the
                     WSGIServer.</para>
                 </listitem>
                 <listitem>
                 </listitem>
             </itemizedlist>
             <para>You <emphasis>must</emphasis> call this function from Python's main thread, and set
-            initOnly to False, if you want CherryPy to shut down when KeyboardInterrupt or SystemExit
+            init_only to False, if you want CherryPy to shut down when KeyboardInterrupt or SystemExit
             are raised (including Ctrl-C). The only time you might want to do otherwise is if you run
             CherryPy as a Windows service, or as an extension to, say, mod_python, and even then, you
             might want to anyway.</para>
         </section>
         <section>
             <title>cherrypy.server.blocking</title>
-            <para>If the "initOnly" argument to server.start is True, this will be False, and
+            <para>If the "init_only" argument to server.start is True, this will be False, and
             vice-versa.</para>
         </section>
         <section>
         </section>
         <section>
             <title>cherrypy.server.start_with_callback(func, args=(), kwargs={},
-            serverClass=_missing)</title>
+            server_class = _missing)</title>
             <para>Since server.start usually blocks, use this to easily run another function in a new
             thread. It starts the new thread and then runs server.start. The new thread automatically
             waits for the server to finish its startup procedure.</para>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.