PEP8'd rocket.py.footer (to be removed from rocket.py).
This commit is contained in:
+10
-7
@@ -1,17 +1,18 @@
|
|||||||
|
# The following code is not part of Rocket but was added to
|
||||||
|
# web2py for testing purposes.
|
||||||
|
|
||||||
#
|
|
||||||
# the following code is not part of Rocket but was added in web2py for testing purposes
|
|
||||||
#
|
|
||||||
|
|
||||||
def demo_app(environ, start_response):
|
def demo_app(environ, start_response):
|
||||||
global static_folder
|
global static_folder
|
||||||
import os
|
import os
|
||||||
types = {'htm': 'text/html','html': 'text/html','gif': 'image/gif',
|
types = {'htm': 'text/html', 'html': 'text/html',
|
||||||
'jpg': 'image/jpeg','png': 'image/png','pdf': 'applications/pdf'}
|
'gif': 'image/gif', 'jpg': 'image/jpeg',
|
||||||
|
'png': 'image/png', 'pdf': 'applications/pdf'}
|
||||||
if static_folder:
|
if static_folder:
|
||||||
if not static_folder.startswith('/'):
|
if not static_folder.startswith('/'):
|
||||||
static_folder = os.path.join(os.getcwd(), static_folder)
|
static_folder = os.path.join(os.getcwd(), static_folder)
|
||||||
path = os.path.join(static_folder, environ['PATH_INFO'][1:] or 'index.html')
|
path = os.path.join(
|
||||||
|
static_folder, environ['PATH_INFO'][1:] or 'index.html')
|
||||||
type = types.get(path.split('.')[-1], 'text')
|
type = types.get(path.split('.')[-1], 'text')
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
try:
|
try:
|
||||||
@@ -25,9 +26,10 @@ def demo_app(environ, start_response):
|
|||||||
data = '500 INTERNAL SERVER ERROR'
|
data = '500 INTERNAL SERVER ERROR'
|
||||||
else:
|
else:
|
||||||
start_response('200 OK', [('Content-Type', 'text/html')])
|
start_response('200 OK', [('Content-Type', 'text/html')])
|
||||||
data = '<html><body><h1>Hello from Rocket Web Server</h1></body></html>'
|
data = '<html><body><h1>Hello from Rocket</h1></body></html>'
|
||||||
return [data]
|
return [data]
|
||||||
|
|
||||||
|
|
||||||
def demo():
|
def demo():
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
parser = OptionParser()
|
parser = OptionParser()
|
||||||
@@ -44,5 +46,6 @@ def demo():
|
|||||||
r = Rocket((options.ip, int(options.port)), 'wsgi', {'wsgi_app': demo_app})
|
r = Rocket((options.ip, int(options.port)), 'wsgi', {'wsgi_app': demo_app})
|
||||||
r.start()
|
r.start()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
demo()
|
demo()
|
||||||
|
|||||||
Reference in New Issue
Block a user