1+ #!/usr/bin/env python3
2+ """
3+ CherryPy Test Application for Framework Detection
4+ """
5+
6+ import cherrypy
7+ import os
8+
9+ class CherryPyTestApp :
10+ @cherrypy .expose
11+ def index (self ):
12+ return """
13+ <!DOCTYPE html>
14+ <html>
15+ <head>
16+ <title>CherryPy Test App</title>
17+ </head>
18+ <body>
19+ <h1>Hello from CherryPy!</h1>
20+ <p>CherryPy Framework Detection Test</p>
21+ <p>CherryPy is a pythonic, object-oriented HTTP framework.</p>
22+ <ul>
23+ <li><a href="/about">About</a></li>
24+ <li><a href="/api/status">API Status</a></li>
25+ <li><a href="/error">Test Error</a></li>
26+ <li><a href="/admin">Admin Interface</a></li>
27+ </ul>
28+ </body>
29+ </html>
30+ """ .encode ('utf-8' )
31+
32+ @cherrypy .expose
33+ def about (self ):
34+ return """
35+ <!DOCTYPE html>
36+ <html>
37+ <head>
38+ <title>About - CherryPy Test App</title>
39+ </head>
40+ <body>
41+ <h1>About CherryPy</h1>
42+ <p>CherryPy is a pythonic, object-oriented HTTP framework.</p>
43+ <p>It allows developers to build web applications in much the same way they would build any other object-oriented Python program.</p>
44+ <a href="/">Back to Home</a>
45+ </body>
46+ </html>
47+ """ .encode ('utf-8' )
48+
49+ @cherrypy .expose
50+ def api (self , status = None ):
51+ if status == "status" :
52+ cherrypy .response .headers ['Content-Type' ] = 'application/json'
53+ return '{"framework": "cherrypy", "status": "running", "version": "18.8.0"}' .encode ('utf-8' )
54+ return "API endpoint" .encode ('utf-8' )
55+
56+ @cherrypy .expose
57+ def error (self ):
58+ # Trigger an error for testing
59+ raise cherrypy .HTTPError (500 , "Test error for framework detection" )
60+
61+ @cherrypy .expose
62+ def admin (self ):
63+ return """
64+ <!DOCTYPE html>
65+ <html>
66+ <head>
67+ <title>CherryPy Admin</title>
68+ </head>
69+ <body>
70+ <h1>CherryPy Admin Interface</h1>
71+ <p>This is the CherryPy admin interface for testing.</p>
72+ <p>CherryPy admin features:</p>
73+ <ul>
74+ <li>Session management</li>
75+ <li>Configuration</li>
76+ <li>Logging</li>
77+ </ul>
78+ <a href="/">Back to Home</a>
79+ </body>
80+ </html>
81+ """ .encode ('utf-8' )
82+
83+ if __name__ == '__main__' :
84+ # Configure CherryPy
85+ cherrypy .config .update ({
86+ 'server.socket_host' : '0.0.0.0' ,
87+ 'server.socket_port' : 8080 ,
88+ 'server.thread_pool' : 10 ,
89+ 'tools.sessions.on' : True ,
90+ 'tools.sessions.storage_type' : 'file' ,
91+ 'tools.sessions.storage_path' : '/tmp/cherrypy_sessions' ,
92+ 'log.screen' : True ,
93+ 'log.access_file' : '/tmp/cherrypy_access.log' ,
94+ 'log.error_file' : '/tmp/cherrypy_error.log'
95+ })
96+
97+ # Mount the application
98+ cherrypy .quickstart (CherryPyTestApp (), '/' )
0 commit comments