]>
jfr.im git - dlqueue.git/blob - venv/lib/python3.11/site-packages/werkzeug/testapp.py
1 """A small application that can be used to test a WSGI server and check
2 it for WSGI compliance.
4 from __future__
import annotations
9 from textwrap
import wrap
11 from markupsafe
import escape
13 from . import __version__
as _werkzeug_version
14 from .wrappers
.request
import Request
15 from .wrappers
.response
import Response
20 <title>WSGI Information</title>
21 <style type="text/css">
22 @import url(https://fonts.googleapis.com/css?family=Ubuntu);
24 body { font-family: 'Lucida Grande', 'Lucida Sans Unicode', 'Geneva',
25 'Verdana', sans-serif; background-color: white; color: #000;
26 font-size: 15px; text-align: center; }
27 div.box { text-align: left; width: 45em; margin: auto; padding: 50px 0;
28 background-color: white; }
29 h1, h2 { font-family: 'Ubuntu', 'Lucida Grande', 'Lucida Sans Unicode',
30 'Geneva', 'Verdana', sans-serif; font-weight: normal; }
31 h1 { margin: 0 0 30px 0; }
32 h2 { font-size: 1.4em; margin: 1em 0 0.5em 0; }
33 table { width: 100%%; border-collapse: collapse; border: 1px solid #AFC5C9 }
34 table th { background-color: #AFC1C4; color: white; font-size: 0.72em;
35 font-weight: normal; width: 18em; vertical-align: top;
36 padding: 0.5em 0 0.1em 0.5em; }
37 table td { border: 1px solid #AFC5C9; padding: 0.1em 0 0.1em 0.5em; }
38 code { font-family: 'Consolas', 'Monaco', 'Bitstream Vera Sans Mono',
39 monospace; font-size: 0.7em; }
40 ul li { line-height: 1.5em; }
41 ul.path { font-size: 0.7em; margin: 0 -30px; padding: 8px 30px;
42 list-style: none; background: #E8EFF0; }
43 ul.path li { line-height: 1.6em; }
44 li.virtual { color: #999; text-decoration: underline; }
45 li.exp { background: white; }
48 <h1>WSGI Information</h1>
50 This page displays all available information about the WSGI server and
51 the underlying Python interpreter.
52 <h2 id="python-interpreter">Python Interpreter</h2>
56 <td>%(python_version)s
59 <td>%(platform)s [%(os)s]
68 <td>%(werkzeug_version)s
70 <h2 id="wsgi-environment">WSGI Environment</h2>
71 <table>%(wsgi_env)s</table>
72 <h2 id="installed-eggs">Installed Eggs</h2>
74 The following python packages were installed on the system as
76 <ul>%(python_eggs)s</ul>
77 <h2 id="sys-path">System Path</h2>
79 The following paths are the current contents of the load path. The
80 following entries are looked up for Python packages. Note that not
81 all items in this path are folders. Gray and underlined items are
82 entries pointing to invalid resources or used by custom import hooks
83 such as the zip importer.
85 Items with a bright background were expanded for display from a relative
86 path. If you encounter such paths in the output you might want to check
87 your setup as relative paths are usually problematic in multithreaded
89 <ul class="path">%(sys_path)s</ul>
94 def iter_sys_path() -> t
.Iterator
[tuple[str, bool, bool]]:
95 if os
.name
== "posix":
97 def strip(x
: str) -> str:
98 prefix
= os
.path
.expanduser("~")
99 if x
.startswith(prefix
):
100 x
= f
"~{x[len(prefix) :]}"
105 def strip(x
: str) -> str:
108 cwd
= os
.path
.abspath(os
.getcwd())
109 for item
in sys
.path
:
110 path
= os
.path
.join(cwd
, item
or os
.path
.curdir
)
111 yield strip(os
.path
.normpath(path
)), not os
.path
.isdir(path
), path
!= item
115 def test_app(req
: Request
) -> Response
:
116 """Simple test application that dumps the environment. You can use
117 it to check if Werkzeug is working properly:
119 .. sourcecode:: pycon
121 >>> from werkzeug.serving import run_simple
122 >>> from werkzeug.testapp import test_app
123 >>> run_simple('localhost', 3000, test_app)
124 * Running on http://localhost:3000/
126 The application displays important information from the WSGI environment,
127 the Python interpreter and the installed libraries.
132 eggs
: t
.Iterable
[t
.Any
] = ()
135 pkg_resources
.working_set
,
136 key
=lambda x
: x
.project_name
.lower(),
141 version
= egg
.version
142 except (ValueError, AttributeError):
145 f
"<li>{escape(egg.project_name)} <small>[{escape(version)}]</small>"
149 sorted_environ
= sorted(req
.environ
.items(), key
=lambda x
: repr(x
[0]).lower())
150 for key
, value
in sorted_environ
:
151 value
= "".join(wrap(str(escape(repr(value
)))))
152 wsgi_env
.append(f
"<tr><th>{escape(key)}<td><code>{value}</code>")
155 for item
, virtual
, expanded
in iter_sys_path():
158 class_
.append("virtual")
161 class_
= f
' class="{" ".join(class_)}"' if class_
else ""
162 sys_path
.append(f
"<li{class_}>{escape(item)}")
165 "python_version": "<br>".join(escape(sys
.version
).splitlines()),
166 "platform": escape(sys
.platform
),
167 "os": escape(os
.name
),
168 "api_version": sys
.api_version
,
169 "byteorder": sys
.byteorder
,
170 "werkzeug_version": _werkzeug_version
,
171 "python_eggs": "\n".join(python_eggs
),
172 "wsgi_env": "\n".join(wsgi_env
),
173 "sys_path": "\n".join(sys_path
),
175 return Response(TEMPLATE
% context
, mimetype
="text/html")
178 if __name__
== "__main__":
179 from .serving
import run_simple
181 run_simple("localhost", 5000, test_app
, use_reloader
=True)