gooderp18绿色标准版
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

1194 lines
122KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="wsgiref — WSGI Utilities and Reference Implementation" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/wsgiref.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/wsgiref The Web Server Gateway Interface (WSGI) is a standard interface between web server software and web applications written in Python. Having a standard interface makes it eas..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Source code: Lib/wsgiref The Web Server Gateway Interface (WSGI) is a standard interface between web server software and web applications written in Python. Having a standard interface makes it eas..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>wsgiref — WSGI Utilities and Reference Implementation &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="urllib — URL handling modules" href="urllib.html" />
  33. <link rel="prev" title="webbrowser — Convenient web-browser controller" href="webbrowser.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/wsgiref.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref</span></code> — WSGI Utilities and Reference Implementation</a><ul>
  86. <li><a class="reference internal" href="#module-wsgiref.util"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.util</span></code> – WSGI environment utilities</a></li>
  87. <li><a class="reference internal" href="#module-wsgiref.headers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.headers</span></code> – WSGI response header tools</a></li>
  88. <li><a class="reference internal" href="#module-wsgiref.simple_server"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.simple_server</span></code> – a simple WSGI HTTP server</a></li>
  89. <li><a class="reference internal" href="#module-wsgiref.validate"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.validate</span></code> — WSGI conformance checker</a></li>
  90. <li><a class="reference internal" href="#module-wsgiref.handlers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.handlers</span></code> – server/gateway base classes</a></li>
  91. <li><a class="reference internal" href="#module-wsgiref.types"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.types</span></code> – WSGI types for static type checking</a></li>
  92. <li><a class="reference internal" href="#examples">Examples</a></li>
  93. </ul>
  94. </li>
  95. </ul>
  96. </div>
  97. <div>
  98. <h4>Previous topic</h4>
  99. <p class="topless"><a href="webbrowser.html"
  100. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">webbrowser</span></code> — Convenient web-browser controller</a></p>
  101. </div>
  102. <div>
  103. <h4>Next topic</h4>
  104. <p class="topless"><a href="urllib.html"
  105. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib</span></code> — URL handling modules</a></p>
  106. </div>
  107. <div role="note" aria-label="source link">
  108. <h3>This Page</h3>
  109. <ul class="this-page-menu">
  110. <li><a href="../bugs.html">Report a Bug</a></li>
  111. <li>
  112. <a href="https://github.com/python/cpython/blob/main/Doc/library/wsgiref.rst"
  113. rel="nofollow">Show Source
  114. </a>
  115. </li>
  116. </ul>
  117. </div>
  118. </nav>
  119. </div>
  120. </div>
  121. <div class="related" role="navigation" aria-label="related navigation">
  122. <h3>Navigation</h3>
  123. <ul>
  124. <li class="right" style="margin-right: 10px">
  125. <a href="../genindex.html" title="General Index"
  126. accesskey="I">index</a></li>
  127. <li class="right" >
  128. <a href="../py-modindex.html" title="Python Module Index"
  129. >modules</a> |</li>
  130. <li class="right" >
  131. <a href="urllib.html" title="urllib — URL handling modules"
  132. accesskey="N">next</a> |</li>
  133. <li class="right" >
  134. <a href="webbrowser.html" title="webbrowser — Convenient web-browser controller"
  135. accesskey="P">previous</a> |</li>
  136. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  137. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  138. <li class="switchers">
  139. <div class="language_switcher_placeholder"></div>
  140. <div class="version_switcher_placeholder"></div>
  141. </li>
  142. <li>
  143. </li>
  144. <li id="cpython-language-and-version">
  145. <a href="../index.html">3.12.3 Documentation</a> &#187;
  146. </li>
  147. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  148. <li class="nav-item nav-item-2"><a href="internet.html" accesskey="U">Internet Protocols and Support</a> &#187;</li>
  149. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref</span></code> — WSGI Utilities and Reference Implementation</a></li>
  150. <li class="right">
  151. <div class="inline-search" role="search">
  152. <form class="inline-search" action="../search.html" method="get">
  153. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  154. <input type="submit" value="Go" />
  155. </form>
  156. </div>
  157. |
  158. </li>
  159. <li class="right">
  160. <label class="theme-selector-label">
  161. Theme
  162. <select class="theme-selector" oninput="activateTheme(this.value)">
  163. <option value="auto" selected>Auto</option>
  164. <option value="light">Light</option>
  165. <option value="dark">Dark</option>
  166. </select>
  167. </label> |</li>
  168. </ul>
  169. </div>
  170. <div class="document">
  171. <div class="documentwrapper">
  172. <div class="bodywrapper">
  173. <div class="body" role="main">
  174. <section id="module-wsgiref">
  175. <span id="wsgiref-wsgi-utilities-and-reference-implementation"></span><h1><a class="reference internal" href="#module-wsgiref" title="wsgiref: WSGI Utilities and Reference Implementation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref</span></code></a> — WSGI Utilities and Reference Implementation<a class="headerlink" href="#module-wsgiref" title="Link to this heading">¶</a></h1>
  176. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/wsgiref">Lib/wsgiref</a></p>
  177. <hr class="docutils" />
  178. <p>The Web Server Gateway Interface (WSGI) is a standard interface between web
  179. server software and web applications written in Python. Having a standard
  180. interface makes it easy to use an application that supports WSGI with a number
  181. of different web servers.</p>
  182. <p>Only authors of web servers and programming frameworks need to know every detail
  183. and corner case of the WSGI design. You don’t need to understand every detail
  184. of WSGI just to install a WSGI application or to write a web application using
  185. an existing framework.</p>
  186. <p><a class="reference internal" href="#module-wsgiref" title="wsgiref: WSGI Utilities and Reference Implementation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref</span></code></a> is a reference implementation of the WSGI specification that can
  187. be used to add WSGI support to a web server or framework. It provides utilities
  188. for manipulating WSGI environment variables and response headers, base classes
  189. for implementing WSGI servers, a demo HTTP server that serves WSGI applications,
  190. types for static type checking,
  191. and a validation tool that checks WSGI servers and applications for conformance
  192. to the WSGI specification (<span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>PEP 3333</strong></a>).</p>
  193. <p>See <a class="reference external" href="https://wsgi.readthedocs.io/">wsgi.readthedocs.io</a> for more information about WSGI, and links
  194. to tutorials and other resources.</p>
  195. <section id="module-wsgiref.util">
  196. <span id="wsgiref-util-wsgi-environment-utilities"></span><h2><a class="reference internal" href="#module-wsgiref.util" title="wsgiref.util: WSGI environment utilities."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.util</span></code></a> – WSGI environment utilities<a class="headerlink" href="#module-wsgiref.util" title="Link to this heading">¶</a></h2>
  197. <p>This module provides a variety of utility functions for working with WSGI
  198. environments. A WSGI environment is a dictionary containing HTTP request
  199. variables as described in <span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>PEP 3333</strong></a>. All of the functions taking an <em>environ</em>
  200. parameter expect a WSGI-compliant dictionary to be supplied; please see
  201. <span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>PEP 3333</strong></a> for a detailed specification and
  202. <a class="reference internal" href="#wsgiref.types.WSGIEnvironment" title="wsgiref.types.WSGIEnvironment"><code class="xref py py-data docutils literal notranslate"><span class="pre">WSGIEnvironment</span></code></a> for a type alias that can be used
  203. in type annotations.</p>
  204. <dl class="py function">
  205. <dt class="sig sig-object py" id="wsgiref.util.guess_scheme">
  206. <span class="sig-prename descclassname"><span class="pre">wsgiref.util.</span></span><span class="sig-name descname"><span class="pre">guess_scheme</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">environ</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.util.guess_scheme" title="Link to this definition">¶</a></dt>
  207. <dd><p>Return a guess for whether <code class="docutils literal notranslate"><span class="pre">wsgi.url_scheme</span></code> should be “http” or “https”, by
  208. checking for a <code class="docutils literal notranslate"><span class="pre">HTTPS</span></code> environment variable in the <em>environ</em> dictionary. The
  209. return value is a string.</p>
  210. <p>This function is useful when creating a gateway that wraps CGI or a CGI-like
  211. protocol such as FastCGI. Typically, servers providing such protocols will
  212. include a <code class="docutils literal notranslate"><span class="pre">HTTPS</span></code> variable with a value of “1”, “yes”, or “on” when a request
  213. is received via SSL. So, this function returns “https” if such a value is
  214. found, and “http” otherwise.</p>
  215. </dd></dl>
  216. <dl class="py function">
  217. <dt class="sig sig-object py" id="wsgiref.util.request_uri">
  218. <span class="sig-prename descclassname"><span class="pre">wsgiref.util.</span></span><span class="sig-name descname"><span class="pre">request_uri</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">environ</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">include_query</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.util.request_uri" title="Link to this definition">¶</a></dt>
  219. <dd><p>Return the full request URI, optionally including the query string, using the
  220. algorithm found in the “URL Reconstruction” section of <span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>PEP 3333</strong></a>. If
  221. <em>include_query</em> is false, the query string is not included in the resulting URI.</p>
  222. </dd></dl>
  223. <dl class="py function">
  224. <dt class="sig sig-object py" id="wsgiref.util.application_uri">
  225. <span class="sig-prename descclassname"><span class="pre">wsgiref.util.</span></span><span class="sig-name descname"><span class="pre">application_uri</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">environ</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.util.application_uri" title="Link to this definition">¶</a></dt>
  226. <dd><p>Similar to <a class="reference internal" href="#wsgiref.util.request_uri" title="wsgiref.util.request_uri"><code class="xref py py-func docutils literal notranslate"><span class="pre">request_uri()</span></code></a>, except that the <code class="docutils literal notranslate"><span class="pre">PATH_INFO</span></code> and
  227. <code class="docutils literal notranslate"><span class="pre">QUERY_STRING</span></code> variables are ignored. The result is the base URI of the
  228. application object addressed by the request.</p>
  229. </dd></dl>
  230. <dl class="py function">
  231. <dt class="sig sig-object py" id="wsgiref.util.shift_path_info">
  232. <span class="sig-prename descclassname"><span class="pre">wsgiref.util.</span></span><span class="sig-name descname"><span class="pre">shift_path_info</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">environ</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.util.shift_path_info" title="Link to this definition">¶</a></dt>
  233. <dd><p>Shift a single name from <code class="docutils literal notranslate"><span class="pre">PATH_INFO</span></code> to <code class="docutils literal notranslate"><span class="pre">SCRIPT_NAME</span></code> and return the name.
  234. The <em>environ</em> dictionary is <em>modified</em> in-place; use a copy if you need to keep
  235. the original <code class="docutils literal notranslate"><span class="pre">PATH_INFO</span></code> or <code class="docutils literal notranslate"><span class="pre">SCRIPT_NAME</span></code> intact.</p>
  236. <p>If there are no remaining path segments in <code class="docutils literal notranslate"><span class="pre">PATH_INFO</span></code>, <code class="docutils literal notranslate"><span class="pre">None</span></code> is returned.</p>
  237. <p>Typically, this routine is used to process each portion of a request URI path,
  238. for example to treat the path as a series of dictionary keys. This routine
  239. modifies the passed-in environment to make it suitable for invoking another WSGI
  240. application that is located at the target URI. For example, if there is a WSGI
  241. application at <code class="docutils literal notranslate"><span class="pre">/foo</span></code>, and the request URI path is <code class="docutils literal notranslate"><span class="pre">/foo/bar/baz</span></code>, and the
  242. WSGI application at <code class="docutils literal notranslate"><span class="pre">/foo</span></code> calls <a class="reference internal" href="#wsgiref.util.shift_path_info" title="wsgiref.util.shift_path_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">shift_path_info()</span></code></a>, it will receive the
  243. string “bar”, and the environment will be updated to be suitable for passing to
  244. a WSGI application at <code class="docutils literal notranslate"><span class="pre">/foo/bar</span></code>. That is, <code class="docutils literal notranslate"><span class="pre">SCRIPT_NAME</span></code> will change from
  245. <code class="docutils literal notranslate"><span class="pre">/foo</span></code> to <code class="docutils literal notranslate"><span class="pre">/foo/bar</span></code>, and <code class="docutils literal notranslate"><span class="pre">PATH_INFO</span></code> will change from <code class="docutils literal notranslate"><span class="pre">/bar/baz</span></code> to
  246. <code class="docutils literal notranslate"><span class="pre">/baz</span></code>.</p>
  247. <p>When <code class="docutils literal notranslate"><span class="pre">PATH_INFO</span></code> is just a “/”, this routine returns an empty string and
  248. appends a trailing slash to <code class="docutils literal notranslate"><span class="pre">SCRIPT_NAME</span></code>, even though empty path segments are
  249. normally ignored, and <code class="docutils literal notranslate"><span class="pre">SCRIPT_NAME</span></code> doesn’t normally end in a slash. This is
  250. intentional behavior, to ensure that an application can tell the difference
  251. between URIs ending in <code class="docutils literal notranslate"><span class="pre">/x</span></code> from ones ending in <code class="docutils literal notranslate"><span class="pre">/x/</span></code> when using this
  252. routine to do object traversal.</p>
  253. </dd></dl>
  254. <dl class="py function">
  255. <dt class="sig sig-object py" id="wsgiref.util.setup_testing_defaults">
  256. <span class="sig-prename descclassname"><span class="pre">wsgiref.util.</span></span><span class="sig-name descname"><span class="pre">setup_testing_defaults</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">environ</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.util.setup_testing_defaults" title="Link to this definition">¶</a></dt>
  257. <dd><p>Update <em>environ</em> with trivial defaults for testing purposes.</p>
  258. <p>This routine adds various parameters required for WSGI, including <code class="docutils literal notranslate"><span class="pre">HTTP_HOST</span></code>,
  259. <code class="docutils literal notranslate"><span class="pre">SERVER_NAME</span></code>, <code class="docutils literal notranslate"><span class="pre">SERVER_PORT</span></code>, <code class="docutils literal notranslate"><span class="pre">REQUEST_METHOD</span></code>, <code class="docutils literal notranslate"><span class="pre">SCRIPT_NAME</span></code>,
  260. <code class="docutils literal notranslate"><span class="pre">PATH_INFO</span></code>, and all of the <span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>PEP 3333</strong></a>-defined <code class="docutils literal notranslate"><span class="pre">wsgi.*</span></code> variables. It
  261. only supplies default values, and does not replace any existing settings for
  262. these variables.</p>
  263. <p>This routine is intended to make it easier for unit tests of WSGI servers and
  264. applications to set up dummy environments. It should NOT be used by actual WSGI
  265. servers or applications, since the data is fake!</p>
  266. <p>Example usage:</p>
  267. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">wsgiref.util</span> <span class="kn">import</span> <span class="n">setup_testing_defaults</span>
  268. <span class="kn">from</span> <span class="nn">wsgiref.simple_server</span> <span class="kn">import</span> <span class="n">make_server</span>
  269. <span class="c1"># A relatively simple WSGI application. It&#39;s going to print out the</span>
  270. <span class="c1"># environment dictionary after being updated by setup_testing_defaults</span>
  271. <span class="k">def</span> <span class="nf">simple_app</span><span class="p">(</span><span class="n">environ</span><span class="p">,</span> <span class="n">start_response</span><span class="p">):</span>
  272. <span class="n">setup_testing_defaults</span><span class="p">(</span><span class="n">environ</span><span class="p">)</span>
  273. <span class="n">status</span> <span class="o">=</span> <span class="s1">&#39;200 OK&#39;</span>
  274. <span class="n">headers</span> <span class="o">=</span> <span class="p">[(</span><span class="s1">&#39;Content-type&#39;</span><span class="p">,</span> <span class="s1">&#39;text/plain; charset=utf-8&#39;</span><span class="p">)]</span>
  275. <span class="n">start_response</span><span class="p">(</span><span class="n">status</span><span class="p">,</span> <span class="n">headers</span><span class="p">)</span>
  276. <span class="n">ret</span> <span class="o">=</span> <span class="p">[(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">))</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">)</span>
  277. <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">environ</span><span class="o">.</span><span class="n">items</span><span class="p">()]</span>
  278. <span class="k">return</span> <span class="n">ret</span>
  279. <span class="k">with</span> <span class="n">make_server</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="mi">8000</span><span class="p">,</span> <span class="n">simple_app</span><span class="p">)</span> <span class="k">as</span> <span class="n">httpd</span><span class="p">:</span>
  280. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Serving on port 8000...&quot;</span><span class="p">)</span>
  281. <span class="n">httpd</span><span class="o">.</span><span class="n">serve_forever</span><span class="p">()</span>
  282. </pre></div>
  283. </div>
  284. </dd></dl>
  285. <p>In addition to the environment functions above, the <a class="reference internal" href="#module-wsgiref.util" title="wsgiref.util: WSGI environment utilities."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.util</span></code></a> module
  286. also provides these miscellaneous utilities:</p>
  287. <dl class="py function">
  288. <dt class="sig sig-object py" id="wsgiref.util.is_hop_by_hop">
  289. <span class="sig-prename descclassname"><span class="pre">wsgiref.util.</span></span><span class="sig-name descname"><span class="pre">is_hop_by_hop</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">header_name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.util.is_hop_by_hop" title="Link to this definition">¶</a></dt>
  290. <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if ‘header_name’ is an HTTP/1.1 “Hop-by-Hop” header, as defined by
  291. <span class="target" id="index-5"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc2616.html"><strong>RFC 2616</strong></a>.</p>
  292. </dd></dl>
  293. <dl class="py class">
  294. <dt class="sig sig-object py" id="wsgiref.util.FileWrapper">
  295. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">wsgiref.util.</span></span><span class="sig-name descname"><span class="pre">FileWrapper</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filelike</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">blksize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">8192</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.util.FileWrapper" title="Link to this definition">¶</a></dt>
  296. <dd><p>A concrete implementation of the <a class="reference internal" href="#wsgiref.types.FileWrapper" title="wsgiref.types.FileWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">wsgiref.types.FileWrapper</span></code></a>
  297. protocol used to convert a file-like object to an <a class="reference internal" href="../glossary.html#term-iterator"><span class="xref std std-term">iterator</span></a>.
  298. The resulting objects
  299. are <a class="reference internal" href="../glossary.html#term-iterable"><span class="xref std std-term">iterable</span></a>s. As the object is iterated over, the
  300. optional <em>blksize</em> parameter will be repeatedly passed to the <em>filelike</em>
  301. object’s <code class="xref py py-meth docutils literal notranslate"><span class="pre">read()</span></code> method to obtain bytestrings to yield. When <code class="xref py py-meth docutils literal notranslate"><span class="pre">read()</span></code>
  302. returns an empty bytestring, iteration is ended and is not resumable.</p>
  303. <p>If <em>filelike</em> has a <code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code> method, the returned object will also have a
  304. <code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code> method, and it will invoke the <em>filelike</em> object’s <code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code>
  305. method when called.</p>
  306. <p>Example usage:</p>
  307. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">io</span> <span class="kn">import</span> <span class="n">StringIO</span>
  308. <span class="kn">from</span> <span class="nn">wsgiref.util</span> <span class="kn">import</span> <span class="n">FileWrapper</span>
  309. <span class="c1"># We&#39;re using a StringIO-buffer for as the file-like object</span>
  310. <span class="n">filelike</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">(</span><span class="s2">&quot;This is an example file-like object&quot;</span><span class="o">*</span><span class="mi">10</span><span class="p">)</span>
  311. <span class="n">wrapper</span> <span class="o">=</span> <span class="n">FileWrapper</span><span class="p">(</span><span class="n">filelike</span><span class="p">,</span> <span class="n">blksize</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
  312. <span class="k">for</span> <span class="n">chunk</span> <span class="ow">in</span> <span class="n">wrapper</span><span class="p">:</span>
  313. <span class="nb">print</span><span class="p">(</span><span class="n">chunk</span><span class="p">)</span>
  314. </pre></div>
  315. </div>
  316. <div class="versionchanged">
  317. <p><span class="versionmodified changed">Changed in version 3.11: </span>Support for <a class="reference internal" href="../reference/datamodel.html#object.__getitem__" title="object.__getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getitem__()</span></code></a> method has been removed.</p>
  318. </div>
  319. </dd></dl>
  320. </section>
  321. <section id="module-wsgiref.headers">
  322. <span id="wsgiref-headers-wsgi-response-header-tools"></span><h2><a class="reference internal" href="#module-wsgiref.headers" title="wsgiref.headers: WSGI response header tools."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.headers</span></code></a> – WSGI response header tools<a class="headerlink" href="#module-wsgiref.headers" title="Link to this heading">¶</a></h2>
  323. <p>This module provides a single class, <a class="reference internal" href="#wsgiref.headers.Headers" title="wsgiref.headers.Headers"><code class="xref py py-class docutils literal notranslate"><span class="pre">Headers</span></code></a>, for convenient
  324. manipulation of WSGI response headers using a mapping-like interface.</p>
  325. <dl class="py class">
  326. <dt class="sig sig-object py" id="wsgiref.headers.Headers">
  327. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">wsgiref.headers.</span></span><span class="sig-name descname"><span class="pre">Headers</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">headers</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.headers.Headers" title="Link to this definition">¶</a></dt>
  328. <dd><p>Create a mapping-like object wrapping <em>headers</em>, which must be a list of header
  329. name/value tuples as described in <span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>PEP 3333</strong></a>. The default value of <em>headers</em> is
  330. an empty list.</p>
  331. <p><a class="reference internal" href="#wsgiref.headers.Headers" title="wsgiref.headers.Headers"><code class="xref py py-class docutils literal notranslate"><span class="pre">Headers</span></code></a> objects support typical mapping operations including
  332. <a class="reference internal" href="../reference/datamodel.html#object.__getitem__" title="object.__getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getitem__()</span></code></a>, <a class="reference internal" href="stdtypes.html#dict.get" title="dict.get"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get()</span></code></a>, <a class="reference internal" href="../reference/datamodel.html#object.__setitem__" title="object.__setitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__setitem__()</span></code></a>,
  333. <a class="reference internal" href="stdtypes.html#dict.setdefault" title="dict.setdefault"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setdefault()</span></code></a>,
  334. <a class="reference internal" href="../reference/datamodel.html#object.__delitem__" title="object.__delitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__delitem__()</span></code></a> and <a class="reference internal" href="../reference/datamodel.html#object.__contains__" title="object.__contains__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__contains__()</span></code></a>. For each of
  335. these methods, the key is the header name (treated case-insensitively), and the
  336. value is the first value associated with that header name. Setting a header
  337. deletes any existing values for that header, then adds a new value at the end of
  338. the wrapped header list. Headers’ existing order is generally maintained, with
  339. new headers added to the end of the wrapped list.</p>
  340. <p>Unlike a dictionary, <a class="reference internal" href="#wsgiref.headers.Headers" title="wsgiref.headers.Headers"><code class="xref py py-class docutils literal notranslate"><span class="pre">Headers</span></code></a> objects do not raise an error when you try
  341. to get or delete a key that isn’t in the wrapped header list. Getting a
  342. nonexistent header just returns <code class="docutils literal notranslate"><span class="pre">None</span></code>, and deleting a nonexistent header does
  343. nothing.</p>
  344. <p><a class="reference internal" href="#wsgiref.headers.Headers" title="wsgiref.headers.Headers"><code class="xref py py-class docutils literal notranslate"><span class="pre">Headers</span></code></a> objects also support <code class="xref py py-meth docutils literal notranslate"><span class="pre">keys()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">values()</span></code>, and
  345. <code class="xref py py-meth docutils literal notranslate"><span class="pre">items()</span></code> methods. The lists returned by <code class="xref py py-meth docutils literal notranslate"><span class="pre">keys()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">items()</span></code> can
  346. include the same key more than once if there is a multi-valued header. The
  347. <code class="docutils literal notranslate"><span class="pre">len()</span></code> of a <a class="reference internal" href="#wsgiref.headers.Headers" title="wsgiref.headers.Headers"><code class="xref py py-class docutils literal notranslate"><span class="pre">Headers</span></code></a> object is the same as the length of its
  348. <code class="xref py py-meth docutils literal notranslate"><span class="pre">items()</span></code>, which is the same as the length of the wrapped header list. In
  349. fact, the <code class="xref py py-meth docutils literal notranslate"><span class="pre">items()</span></code> method just returns a copy of the wrapped header list.</p>
  350. <p>Calling <code class="docutils literal notranslate"><span class="pre">bytes()</span></code> on a <a class="reference internal" href="#wsgiref.headers.Headers" title="wsgiref.headers.Headers"><code class="xref py py-class docutils literal notranslate"><span class="pre">Headers</span></code></a> object returns a formatted bytestring
  351. suitable for transmission as HTTP response headers. Each header is placed on a
  352. line with its value, separated by a colon and a space. Each line is terminated
  353. by a carriage return and line feed, and the bytestring is terminated with a
  354. blank line.</p>
  355. <p>In addition to their mapping interface and formatting features, <a class="reference internal" href="#wsgiref.headers.Headers" title="wsgiref.headers.Headers"><code class="xref py py-class docutils literal notranslate"><span class="pre">Headers</span></code></a>
  356. objects also have the following methods for querying and adding multi-valued
  357. headers, and for adding headers with MIME parameters:</p>
  358. <dl class="py method">
  359. <dt class="sig sig-object py" id="wsgiref.headers.Headers.get_all">
  360. <span class="sig-name descname"><span class="pre">get_all</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.headers.Headers.get_all" title="Link to this definition">¶</a></dt>
  361. <dd><p>Return a list of all the values for the named header.</p>
  362. <p>The returned list will be sorted in the order they appeared in the original
  363. header list or were added to this instance, and may contain duplicates. Any
  364. fields deleted and re-inserted are always appended to the header list. If no
  365. fields exist with the given name, returns an empty list.</p>
  366. </dd></dl>
  367. <dl class="py method">
  368. <dt class="sig sig-object py" id="wsgiref.headers.Headers.add_header">
  369. <span class="sig-name descname"><span class="pre">add_header</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">value</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">_params</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.headers.Headers.add_header" title="Link to this definition">¶</a></dt>
  370. <dd><p>Add a (possibly multi-valued) header, with optional MIME parameters specified
  371. via keyword arguments.</p>
  372. <p><em>name</em> is the header field to add. Keyword arguments can be used to set MIME
  373. parameters for the header field. Each parameter must be a string or <code class="docutils literal notranslate"><span class="pre">None</span></code>.
  374. Underscores in parameter names are converted to dashes, since dashes are illegal
  375. in Python identifiers, but many MIME parameter names include dashes. If the
  376. parameter value is a string, it is added to the header value parameters in the
  377. form <code class="docutils literal notranslate"><span class="pre">name=&quot;value&quot;</span></code>. If it is <code class="docutils literal notranslate"><span class="pre">None</span></code>, only the parameter name is added.
  378. (This is used for MIME parameters without a value.) Example usage:</p>
  379. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">h</span><span class="o">.</span><span class="n">add_header</span><span class="p">(</span><span class="s1">&#39;content-disposition&#39;</span><span class="p">,</span> <span class="s1">&#39;attachment&#39;</span><span class="p">,</span> <span class="n">filename</span><span class="o">=</span><span class="s1">&#39;bud.gif&#39;</span><span class="p">)</span>
  380. </pre></div>
  381. </div>
  382. <p>The above will add a header that looks like this:</p>
  383. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">Content</span><span class="o">-</span><span class="n">Disposition</span><span class="p">:</span> <span class="n">attachment</span><span class="p">;</span> <span class="n">filename</span><span class="o">=</span><span class="s2">&quot;bud.gif&quot;</span>
  384. </pre></div>
  385. </div>
  386. </dd></dl>
  387. <div class="versionchanged">
  388. <p><span class="versionmodified changed">Changed in version 3.5: </span><em>headers</em> parameter is optional.</p>
  389. </div>
  390. </dd></dl>
  391. </section>
  392. <section id="module-wsgiref.simple_server">
  393. <span id="wsgiref-simple-server-a-simple-wsgi-http-server"></span><h2><a class="reference internal" href="#module-wsgiref.simple_server" title="wsgiref.simple_server: A simple WSGI HTTP server."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.simple_server</span></code></a> – a simple WSGI HTTP server<a class="headerlink" href="#module-wsgiref.simple_server" title="Link to this heading">¶</a></h2>
  394. <p>This module implements a simple HTTP server (based on <a class="reference internal" href="http.server.html#module-http.server" title="http.server: HTTP server and request handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.server</span></code></a>)
  395. that serves WSGI applications. Each server instance serves a single WSGI
  396. application on a given host and port. If you want to serve multiple
  397. applications on a single host and port, you should create a WSGI application
  398. that parses <code class="docutils literal notranslate"><span class="pre">PATH_INFO</span></code> to select which application to invoke for each
  399. request. (E.g., using the <code class="xref py py-func docutils literal notranslate"><span class="pre">shift_path_info()</span></code> function from
  400. <a class="reference internal" href="#module-wsgiref.util" title="wsgiref.util: WSGI environment utilities."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.util</span></code></a>.)</p>
  401. <dl class="py function">
  402. <dt class="sig sig-object py" id="wsgiref.simple_server.make_server">
  403. <span class="sig-prename descclassname"><span class="pre">wsgiref.simple_server.</span></span><span class="sig-name descname"><span class="pre">make_server</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">host</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">port</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">app</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">server_class</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">WSGIServer</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">handler_class</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">WSGIRequestHandler</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.simple_server.make_server" title="Link to this definition">¶</a></dt>
  404. <dd><p>Create a new WSGI server listening on <em>host</em> and <em>port</em>, accepting connections
  405. for <em>app</em>. The return value is an instance of the supplied <em>server_class</em>, and
  406. will process requests using the specified <em>handler_class</em>. <em>app</em> must be a WSGI
  407. application object, as defined by <span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>PEP 3333</strong></a>.</p>
  408. <p>Example usage:</p>
  409. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">wsgiref.simple_server</span> <span class="kn">import</span> <span class="n">make_server</span><span class="p">,</span> <span class="n">demo_app</span>
  410. <span class="k">with</span> <span class="n">make_server</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="mi">8000</span><span class="p">,</span> <span class="n">demo_app</span><span class="p">)</span> <span class="k">as</span> <span class="n">httpd</span><span class="p">:</span>
  411. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Serving HTTP on port 8000...&quot;</span><span class="p">)</span>
  412. <span class="c1"># Respond to requests until process is killed</span>
  413. <span class="n">httpd</span><span class="o">.</span><span class="n">serve_forever</span><span class="p">()</span>
  414. <span class="c1"># Alternative: serve one request, then exit</span>
  415. <span class="n">httpd</span><span class="o">.</span><span class="n">handle_request</span><span class="p">()</span>
  416. </pre></div>
  417. </div>
  418. </dd></dl>
  419. <dl class="py function">
  420. <dt class="sig sig-object py" id="wsgiref.simple_server.demo_app">
  421. <span class="sig-prename descclassname"><span class="pre">wsgiref.simple_server.</span></span><span class="sig-name descname"><span class="pre">demo_app</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">environ</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">start_response</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.simple_server.demo_app" title="Link to this definition">¶</a></dt>
  422. <dd><p>This function is a small but complete WSGI application that returns a text page
  423. containing the message “Hello world!” and a list of the key/value pairs provided
  424. in the <em>environ</em> parameter. It’s useful for verifying that a WSGI server (such
  425. as <a class="reference internal" href="#module-wsgiref.simple_server" title="wsgiref.simple_server: A simple WSGI HTTP server."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.simple_server</span></code></a>) is able to run a simple WSGI application
  426. correctly.</p>
  427. </dd></dl>
  428. <dl class="py class">
  429. <dt class="sig sig-object py" id="wsgiref.simple_server.WSGIServer">
  430. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">wsgiref.simple_server.</span></span><span class="sig-name descname"><span class="pre">WSGIServer</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">server_address</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">RequestHandlerClass</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.simple_server.WSGIServer" title="Link to this definition">¶</a></dt>
  431. <dd><p>Create a <a class="reference internal" href="#wsgiref.simple_server.WSGIServer" title="wsgiref.simple_server.WSGIServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">WSGIServer</span></code></a> instance. <em>server_address</em> should be a
  432. <code class="docutils literal notranslate"><span class="pre">(host,port)</span></code> tuple, and <em>RequestHandlerClass</em> should be the subclass of
  433. <a class="reference internal" href="http.server.html#http.server.BaseHTTPRequestHandler" title="http.server.BaseHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">http.server.BaseHTTPRequestHandler</span></code></a> that will be used to process
  434. requests.</p>
  435. <p>You do not normally need to call this constructor, as the <a class="reference internal" href="#wsgiref.simple_server.make_server" title="wsgiref.simple_server.make_server"><code class="xref py py-func docutils literal notranslate"><span class="pre">make_server()</span></code></a>
  436. function can handle all the details for you.</p>
  437. <p><a class="reference internal" href="#wsgiref.simple_server.WSGIServer" title="wsgiref.simple_server.WSGIServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">WSGIServer</span></code></a> is a subclass of <a class="reference internal" href="http.server.html#http.server.HTTPServer" title="http.server.HTTPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">http.server.HTTPServer</span></code></a>, so all
  438. of its methods (such as <code class="xref py py-meth docutils literal notranslate"><span class="pre">serve_forever()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">handle_request()</span></code>) are
  439. available. <a class="reference internal" href="#wsgiref.simple_server.WSGIServer" title="wsgiref.simple_server.WSGIServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">WSGIServer</span></code></a> also provides these WSGI-specific methods:</p>
  440. <dl class="py method">
  441. <dt class="sig sig-object py" id="wsgiref.simple_server.WSGIServer.set_app">
  442. <span class="sig-name descname"><span class="pre">set_app</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">application</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.simple_server.WSGIServer.set_app" title="Link to this definition">¶</a></dt>
  443. <dd><p>Sets the callable <em>application</em> as the WSGI application that will receive
  444. requests.</p>
  445. </dd></dl>
  446. <dl class="py method">
  447. <dt class="sig sig-object py" id="wsgiref.simple_server.WSGIServer.get_app">
  448. <span class="sig-name descname"><span class="pre">get_app</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.simple_server.WSGIServer.get_app" title="Link to this definition">¶</a></dt>
  449. <dd><p>Returns the currently set application callable.</p>
  450. </dd></dl>
  451. <p>Normally, however, you do not need to use these additional methods, as
  452. <a class="reference internal" href="#wsgiref.simple_server.WSGIServer.set_app" title="wsgiref.simple_server.WSGIServer.set_app"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_app()</span></code></a> is normally called by <a class="reference internal" href="#wsgiref.simple_server.make_server" title="wsgiref.simple_server.make_server"><code class="xref py py-func docutils literal notranslate"><span class="pre">make_server()</span></code></a>, and the
  453. <a class="reference internal" href="#wsgiref.simple_server.WSGIServer.get_app" title="wsgiref.simple_server.WSGIServer.get_app"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_app()</span></code></a> exists mainly for the benefit of request handler instances.</p>
  454. </dd></dl>
  455. <dl class="py class">
  456. <dt class="sig sig-object py" id="wsgiref.simple_server.WSGIRequestHandler">
  457. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">wsgiref.simple_server.</span></span><span class="sig-name descname"><span class="pre">WSGIRequestHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">request</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">client_address</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">server</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.simple_server.WSGIRequestHandler" title="Link to this definition">¶</a></dt>
  458. <dd><p>Create an HTTP handler for the given <em>request</em> (i.e. a socket), <em>client_address</em>
  459. (a <code class="docutils literal notranslate"><span class="pre">(host,port)</span></code> tuple), and <em>server</em> (<a class="reference internal" href="#wsgiref.simple_server.WSGIServer" title="wsgiref.simple_server.WSGIServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">WSGIServer</span></code></a> instance).</p>
  460. <p>You do not need to create instances of this class directly; they are
  461. automatically created as needed by <a class="reference internal" href="#wsgiref.simple_server.WSGIServer" title="wsgiref.simple_server.WSGIServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">WSGIServer</span></code></a> objects. You can,
  462. however, subclass this class and supply it as a <em>handler_class</em> to the
  463. <a class="reference internal" href="#wsgiref.simple_server.make_server" title="wsgiref.simple_server.make_server"><code class="xref py py-func docutils literal notranslate"><span class="pre">make_server()</span></code></a> function. Some possibly relevant methods for overriding in
  464. subclasses:</p>
  465. <dl class="py method">
  466. <dt class="sig sig-object py" id="wsgiref.simple_server.WSGIRequestHandler.get_environ">
  467. <span class="sig-name descname"><span class="pre">get_environ</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.simple_server.WSGIRequestHandler.get_environ" title="Link to this definition">¶</a></dt>
  468. <dd><p>Return a <a class="reference internal" href="#wsgiref.types.WSGIEnvironment" title="wsgiref.types.WSGIEnvironment"><code class="xref py py-data docutils literal notranslate"><span class="pre">WSGIEnvironment</span></code></a> dictionary for a
  469. request. The default
  470. implementation copies the contents of the <a class="reference internal" href="#wsgiref.simple_server.WSGIServer" title="wsgiref.simple_server.WSGIServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">WSGIServer</span></code></a> object’s
  471. <code class="xref py py-attr docutils literal notranslate"><span class="pre">base_environ</span></code> dictionary attribute and then adds various headers derived
  472. from the HTTP request. Each call to this method should return a new dictionary
  473. containing all of the relevant CGI environment variables as specified in
  474. <span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>PEP 3333</strong></a>.</p>
  475. </dd></dl>
  476. <dl class="py method">
  477. <dt class="sig sig-object py" id="wsgiref.simple_server.WSGIRequestHandler.get_stderr">
  478. <span class="sig-name descname"><span class="pre">get_stderr</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.simple_server.WSGIRequestHandler.get_stderr" title="Link to this definition">¶</a></dt>
  479. <dd><p>Return the object that should be used as the <code class="docutils literal notranslate"><span class="pre">wsgi.errors</span></code> stream. The default
  480. implementation just returns <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code>.</p>
  481. </dd></dl>
  482. <dl class="py method">
  483. <dt class="sig sig-object py" id="wsgiref.simple_server.WSGIRequestHandler.handle">
  484. <span class="sig-name descname"><span class="pre">handle</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.simple_server.WSGIRequestHandler.handle" title="Link to this definition">¶</a></dt>
  485. <dd><p>Process the HTTP request. The default implementation creates a handler instance
  486. using a <a class="reference internal" href="#module-wsgiref.handlers" title="wsgiref.handlers: WSGI server/gateway base classes."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.handlers</span></code></a> class to implement the actual WSGI application
  487. interface.</p>
  488. </dd></dl>
  489. </dd></dl>
  490. </section>
  491. <section id="module-wsgiref.validate">
  492. <span id="wsgiref-validate-wsgi-conformance-checker"></span><h2><a class="reference internal" href="#module-wsgiref.validate" title="wsgiref.validate: WSGI conformance checker."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.validate</span></code></a> — WSGI conformance checker<a class="headerlink" href="#module-wsgiref.validate" title="Link to this heading">¶</a></h2>
  493. <p>When creating new WSGI application objects, frameworks, servers, or middleware,
  494. it can be useful to validate the new code’s conformance using
  495. <a class="reference internal" href="#module-wsgiref.validate" title="wsgiref.validate: WSGI conformance checker."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.validate</span></code></a>. This module provides a function that creates WSGI
  496. application objects that validate communications between a WSGI server or
  497. gateway and a WSGI application object, to check both sides for protocol
  498. conformance.</p>
  499. <p>Note that this utility does not guarantee complete <span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>PEP 3333</strong></a> compliance; an
  500. absence of errors from this module does not necessarily mean that errors do not
  501. exist. However, if this module does produce an error, then it is virtually
  502. certain that either the server or application is not 100% compliant.</p>
  503. <p>This module is based on the <code class="xref py py-mod docutils literal notranslate"><span class="pre">paste.lint</span></code> module from Ian Bicking’s “Python
  504. Paste” library.</p>
  505. <dl class="py function">
  506. <dt class="sig sig-object py" id="wsgiref.validate.validator">
  507. <span class="sig-prename descclassname"><span class="pre">wsgiref.validate.</span></span><span class="sig-name descname"><span class="pre">validator</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">application</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.validate.validator" title="Link to this definition">¶</a></dt>
  508. <dd><p>Wrap <em>application</em> and return a new WSGI application object. The returned
  509. application will forward all requests to the original <em>application</em>, and will
  510. check that both the <em>application</em> and the server invoking it are conforming to
  511. the WSGI specification and to <span class="target" id="index-10"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc2616.html"><strong>RFC 2616</strong></a>.</p>
  512. <p>Any detected nonconformance results in an <a class="reference internal" href="exceptions.html#AssertionError" title="AssertionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AssertionError</span></code></a> being raised;
  513. note, however, that how these errors are handled is server-dependent. For
  514. example, <a class="reference internal" href="#module-wsgiref.simple_server" title="wsgiref.simple_server: A simple WSGI HTTP server."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.simple_server</span></code></a> and other servers based on
  515. <a class="reference internal" href="#module-wsgiref.handlers" title="wsgiref.handlers: WSGI server/gateway base classes."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.handlers</span></code></a> (that don’t override the error handling methods to do
  516. something else) will simply output a message that an error has occurred, and
  517. dump the traceback to <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code> or some other error stream.</p>
  518. <p>This wrapper may also generate output using the <a class="reference internal" href="warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><code class="xref py py-mod docutils literal notranslate"><span class="pre">warnings</span></code></a> module to
  519. indicate behaviors that are questionable but which may not actually be
  520. prohibited by <span class="target" id="index-11"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>PEP 3333</strong></a>. Unless they are suppressed using Python command-line
  521. options or the <a class="reference internal" href="warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><code class="xref py py-mod docutils literal notranslate"><span class="pre">warnings</span></code></a> API, any such warnings will be written to
  522. <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code> (<em>not</em> <code class="docutils literal notranslate"><span class="pre">wsgi.errors</span></code>, unless they happen to be the same
  523. object).</p>
  524. <p>Example usage:</p>
  525. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">wsgiref.validate</span> <span class="kn">import</span> <span class="n">validator</span>
  526. <span class="kn">from</span> <span class="nn">wsgiref.simple_server</span> <span class="kn">import</span> <span class="n">make_server</span>
  527. <span class="c1"># Our callable object which is intentionally not compliant to the</span>
  528. <span class="c1"># standard, so the validator is going to break</span>
  529. <span class="k">def</span> <span class="nf">simple_app</span><span class="p">(</span><span class="n">environ</span><span class="p">,</span> <span class="n">start_response</span><span class="p">):</span>
  530. <span class="n">status</span> <span class="o">=</span> <span class="s1">&#39;200 OK&#39;</span> <span class="c1"># HTTP Status</span>
  531. <span class="n">headers</span> <span class="o">=</span> <span class="p">[(</span><span class="s1">&#39;Content-type&#39;</span><span class="p">,</span> <span class="s1">&#39;text/plain&#39;</span><span class="p">)]</span> <span class="c1"># HTTP Headers</span>
  532. <span class="n">start_response</span><span class="p">(</span><span class="n">status</span><span class="p">,</span> <span class="n">headers</span><span class="p">)</span>
  533. <span class="c1"># This is going to break because we need to return a list, and</span>
  534. <span class="c1"># the validator is going to inform us</span>
  535. <span class="k">return</span> <span class="sa">b</span><span class="s2">&quot;Hello World&quot;</span>
  536. <span class="c1"># This is the application wrapped in a validator</span>
  537. <span class="n">validator_app</span> <span class="o">=</span> <span class="n">validator</span><span class="p">(</span><span class="n">simple_app</span><span class="p">)</span>
  538. <span class="k">with</span> <span class="n">make_server</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="mi">8000</span><span class="p">,</span> <span class="n">validator_app</span><span class="p">)</span> <span class="k">as</span> <span class="n">httpd</span><span class="p">:</span>
  539. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Listening on port 8000....&quot;</span><span class="p">)</span>
  540. <span class="n">httpd</span><span class="o">.</span><span class="n">serve_forever</span><span class="p">()</span>
  541. </pre></div>
  542. </div>
  543. </dd></dl>
  544. </section>
  545. <section id="module-wsgiref.handlers">
  546. <span id="wsgiref-handlers-server-gateway-base-classes"></span><h2><a class="reference internal" href="#module-wsgiref.handlers" title="wsgiref.handlers: WSGI server/gateway base classes."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.handlers</span></code></a> – server/gateway base classes<a class="headerlink" href="#module-wsgiref.handlers" title="Link to this heading">¶</a></h2>
  547. <p>This module provides base handler classes for implementing WSGI servers and
  548. gateways. These base classes handle most of the work of communicating with a
  549. WSGI application, as long as they are given a CGI-like environment, along with
  550. input, output, and error streams.</p>
  551. <dl class="py class">
  552. <dt class="sig sig-object py" id="wsgiref.handlers.CGIHandler">
  553. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">wsgiref.handlers.</span></span><span class="sig-name descname"><span class="pre">CGIHandler</span></span><a class="headerlink" href="#wsgiref.handlers.CGIHandler" title="Link to this definition">¶</a></dt>
  554. <dd><p>CGI-based invocation via <code class="docutils literal notranslate"><span class="pre">sys.stdin</span></code>, <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code>, <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code> and
  555. <code class="docutils literal notranslate"><span class="pre">os.environ</span></code>. This is useful when you have a WSGI application and want to run
  556. it as a CGI script. Simply invoke <code class="docutils literal notranslate"><span class="pre">CGIHandler().run(app)</span></code>, where <code class="docutils literal notranslate"><span class="pre">app</span></code> is
  557. the WSGI application object you wish to invoke.</p>
  558. <p>This class is a subclass of <a class="reference internal" href="#wsgiref.handlers.BaseCGIHandler" title="wsgiref.handlers.BaseCGIHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseCGIHandler</span></code></a> that sets <code class="docutils literal notranslate"><span class="pre">wsgi.run_once</span></code>
  559. to true, <code class="docutils literal notranslate"><span class="pre">wsgi.multithread</span></code> to false, and <code class="docutils literal notranslate"><span class="pre">wsgi.multiprocess</span></code> to true, and
  560. always uses <a class="reference internal" href="sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> and <a class="reference internal" href="os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> to obtain the necessary CGI streams and
  561. environment.</p>
  562. </dd></dl>
  563. <dl class="py class">
  564. <dt class="sig sig-object py" id="wsgiref.handlers.IISCGIHandler">
  565. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">wsgiref.handlers.</span></span><span class="sig-name descname"><span class="pre">IISCGIHandler</span></span><a class="headerlink" href="#wsgiref.handlers.IISCGIHandler" title="Link to this definition">¶</a></dt>
  566. <dd><p>A specialized alternative to <a class="reference internal" href="#wsgiref.handlers.CGIHandler" title="wsgiref.handlers.CGIHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CGIHandler</span></code></a>, for use when deploying on
  567. Microsoft’s IIS web server, without having set the config allowPathInfo
  568. option (IIS&gt;=7) or metabase allowPathInfoForScriptMappings (IIS&lt;7).</p>
  569. <p>By default, IIS gives a <code class="docutils literal notranslate"><span class="pre">PATH_INFO</span></code> that duplicates the <code class="docutils literal notranslate"><span class="pre">SCRIPT_NAME</span></code> at
  570. the front, causing problems for WSGI applications that wish to implement
  571. routing. This handler strips any such duplicated path.</p>
  572. <p>IIS can be configured to pass the correct <code class="docutils literal notranslate"><span class="pre">PATH_INFO</span></code>, but this causes
  573. another bug where <code class="docutils literal notranslate"><span class="pre">PATH_TRANSLATED</span></code> is wrong. Luckily this variable is
  574. rarely used and is not guaranteed by WSGI. On IIS&lt;7, though, the
  575. setting can only be made on a vhost level, affecting all other script
  576. mappings, many of which break when exposed to the <code class="docutils literal notranslate"><span class="pre">PATH_TRANSLATED</span></code> bug.
  577. For this reason IIS&lt;7 is almost never deployed with the fix (Even IIS7
  578. rarely uses it because there is still no UI for it.).</p>
  579. <p>There is no way for CGI code to tell whether the option was set, so a
  580. separate handler class is provided. It is used in the same way as
  581. <a class="reference internal" href="#wsgiref.handlers.CGIHandler" title="wsgiref.handlers.CGIHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CGIHandler</span></code></a>, i.e., by calling <code class="docutils literal notranslate"><span class="pre">IISCGIHandler().run(app)</span></code>, where
  582. <code class="docutils literal notranslate"><span class="pre">app</span></code> is the WSGI application object you wish to invoke.</p>
  583. <div class="versionadded">
  584. <p><span class="versionmodified added">New in version 3.2.</span></p>
  585. </div>
  586. </dd></dl>
  587. <dl class="py class">
  588. <dt class="sig sig-object py" id="wsgiref.handlers.BaseCGIHandler">
  589. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">wsgiref.handlers.</span></span><span class="sig-name descname"><span class="pre">BaseCGIHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">stdin</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stdout</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stderr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">environ</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">multithread</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">multiprocess</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.handlers.BaseCGIHandler" title="Link to this definition">¶</a></dt>
  590. <dd><p>Similar to <a class="reference internal" href="#wsgiref.handlers.CGIHandler" title="wsgiref.handlers.CGIHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CGIHandler</span></code></a>, but instead of using the <a class="reference internal" href="sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> and
  591. <a class="reference internal" href="os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> modules, the CGI environment and I/O streams are specified explicitly.
  592. The <em>multithread</em> and <em>multiprocess</em> values are used to set the
  593. <code class="docutils literal notranslate"><span class="pre">wsgi.multithread</span></code> and <code class="docutils literal notranslate"><span class="pre">wsgi.multiprocess</span></code> flags for any applications run by
  594. the handler instance.</p>
  595. <p>This class is a subclass of <a class="reference internal" href="#wsgiref.handlers.SimpleHandler" title="wsgiref.handlers.SimpleHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleHandler</span></code></a> intended for use with
  596. software other than HTTP “origin servers”. If you are writing a gateway
  597. protocol implementation (such as CGI, FastCGI, SCGI, etc.) that uses a
  598. <code class="docutils literal notranslate"><span class="pre">Status:</span></code> header to send an HTTP status, you probably want to subclass this
  599. instead of <a class="reference internal" href="#wsgiref.handlers.SimpleHandler" title="wsgiref.handlers.SimpleHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleHandler</span></code></a>.</p>
  600. </dd></dl>
  601. <dl class="py class">
  602. <dt class="sig sig-object py" id="wsgiref.handlers.SimpleHandler">
  603. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">wsgiref.handlers.</span></span><span class="sig-name descname"><span class="pre">SimpleHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">stdin</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stdout</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stderr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">environ</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">multithread</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">multiprocess</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.handlers.SimpleHandler" title="Link to this definition">¶</a></dt>
  604. <dd><p>Similar to <a class="reference internal" href="#wsgiref.handlers.BaseCGIHandler" title="wsgiref.handlers.BaseCGIHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseCGIHandler</span></code></a>, but designed for use with HTTP origin
  605. servers. If you are writing an HTTP server implementation, you will probably
  606. want to subclass this instead of <a class="reference internal" href="#wsgiref.handlers.BaseCGIHandler" title="wsgiref.handlers.BaseCGIHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseCGIHandler</span></code></a>.</p>
  607. <p>This class is a subclass of <a class="reference internal" href="#wsgiref.handlers.BaseHandler" title="wsgiref.handlers.BaseHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseHandler</span></code></a>. It overrides the
  608. <code class="xref py py-meth docutils literal notranslate"><span class="pre">__init__()</span></code>, <a class="reference internal" href="#wsgiref.handlers.BaseHandler.get_stdin" title="wsgiref.handlers.BaseHandler.get_stdin"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_stdin()</span></code></a>,
  609. <a class="reference internal" href="#wsgiref.handlers.BaseHandler.get_stderr" title="wsgiref.handlers.BaseHandler.get_stderr"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_stderr()</span></code></a>, <a class="reference internal" href="#wsgiref.handlers.BaseHandler.add_cgi_vars" title="wsgiref.handlers.BaseHandler.add_cgi_vars"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_cgi_vars()</span></code></a>,
  610. <a class="reference internal" href="#wsgiref.handlers.BaseHandler._write" title="wsgiref.handlers.BaseHandler._write"><code class="xref py py-meth docutils literal notranslate"><span class="pre">_write()</span></code></a>, and <a class="reference internal" href="#wsgiref.handlers.BaseHandler._flush" title="wsgiref.handlers.BaseHandler._flush"><code class="xref py py-meth docutils literal notranslate"><span class="pre">_flush()</span></code></a> methods to
  611. support explicitly setting the
  612. environment and streams via the constructor. The supplied environment and
  613. streams are stored in the <code class="xref py py-attr docutils literal notranslate"><span class="pre">stdin</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">stdout</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">stderr</span></code>, and
  614. <code class="xref py py-attr docutils literal notranslate"><span class="pre">environ</span></code> attributes.</p>
  615. <p>The <a class="reference internal" href="io.html#io.BufferedIOBase.write" title="io.BufferedIOBase.write"><code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code></a> method of <em>stdout</em> should write
  616. each chunk in full, like <a class="reference internal" href="io.html#io.BufferedIOBase" title="io.BufferedIOBase"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.BufferedIOBase</span></code></a>.</p>
  617. </dd></dl>
  618. <dl class="py class">
  619. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler">
  620. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">wsgiref.handlers.</span></span><span class="sig-name descname"><span class="pre">BaseHandler</span></span><a class="headerlink" href="#wsgiref.handlers.BaseHandler" title="Link to this definition">¶</a></dt>
  621. <dd><p>This is an abstract base class for running WSGI applications. Each instance
  622. will handle a single HTTP request, although in principle you could create a
  623. subclass that was reusable for multiple requests.</p>
  624. <p><a class="reference internal" href="#wsgiref.handlers.BaseHandler" title="wsgiref.handlers.BaseHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseHandler</span></code></a> instances have only one method intended for external use:</p>
  625. <dl class="py method">
  626. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.run">
  627. <span class="sig-name descname"><span class="pre">run</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.run" title="Link to this definition">¶</a></dt>
  628. <dd><p>Run the specified WSGI application, <em>app</em>.</p>
  629. </dd></dl>
  630. <p>All of the other <a class="reference internal" href="#wsgiref.handlers.BaseHandler" title="wsgiref.handlers.BaseHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseHandler</span></code></a> methods are invoked by this method in the
  631. process of running the application, and thus exist primarily to allow
  632. customizing the process.</p>
  633. <p>The following methods MUST be overridden in a subclass:</p>
  634. <dl class="py method">
  635. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler._write">
  636. <span class="sig-name descname"><span class="pre">_write</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.handlers.BaseHandler._write" title="Link to this definition">¶</a></dt>
  637. <dd><p>Buffer the bytes <em>data</em> for transmission to the client. It’s okay if this
  638. method actually transmits the data; <a class="reference internal" href="#wsgiref.handlers.BaseHandler" title="wsgiref.handlers.BaseHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseHandler</span></code></a> just separates write
  639. and flush operations for greater efficiency when the underlying system actually
  640. has such a distinction.</p>
  641. </dd></dl>
  642. <dl class="py method">
  643. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler._flush">
  644. <span class="sig-name descname"><span class="pre">_flush</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.handlers.BaseHandler._flush" title="Link to this definition">¶</a></dt>
  645. <dd><p>Force buffered data to be transmitted to the client. It’s okay if this method
  646. is a no-op (i.e., if <a class="reference internal" href="#wsgiref.handlers.BaseHandler._write" title="wsgiref.handlers.BaseHandler._write"><code class="xref py py-meth docutils literal notranslate"><span class="pre">_write()</span></code></a> actually sends the data).</p>
  647. </dd></dl>
  648. <dl class="py method">
  649. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.get_stdin">
  650. <span class="sig-name descname"><span class="pre">get_stdin</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.get_stdin" title="Link to this definition">¶</a></dt>
  651. <dd><p>Return an object compatible with <a class="reference internal" href="#wsgiref.types.InputStream" title="wsgiref.types.InputStream"><code class="xref py py-class docutils literal notranslate"><span class="pre">InputStream</span></code></a>
  652. suitable for use as the <code class="docutils literal notranslate"><span class="pre">wsgi.input</span></code> of the
  653. request currently being processed.</p>
  654. </dd></dl>
  655. <dl class="py method">
  656. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.get_stderr">
  657. <span class="sig-name descname"><span class="pre">get_stderr</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.get_stderr" title="Link to this definition">¶</a></dt>
  658. <dd><p>Return an object compatible with <a class="reference internal" href="#wsgiref.types.ErrorStream" title="wsgiref.types.ErrorStream"><code class="xref py py-class docutils literal notranslate"><span class="pre">ErrorStream</span></code></a>
  659. suitable for use as the <code class="docutils literal notranslate"><span class="pre">wsgi.errors</span></code> of the
  660. request currently being processed.</p>
  661. </dd></dl>
  662. <dl class="py method">
  663. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.add_cgi_vars">
  664. <span class="sig-name descname"><span class="pre">add_cgi_vars</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.add_cgi_vars" title="Link to this definition">¶</a></dt>
  665. <dd><p>Insert CGI variables for the current request into the <code class="xref py py-attr docutils literal notranslate"><span class="pre">environ</span></code> attribute.</p>
  666. </dd></dl>
  667. <p>Here are some other methods and attributes you may wish to override. This list
  668. is only a summary, however, and does not include every method that can be
  669. overridden. You should consult the docstrings and source code for additional
  670. information before attempting to create a customized <a class="reference internal" href="#wsgiref.handlers.BaseHandler" title="wsgiref.handlers.BaseHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseHandler</span></code></a>
  671. subclass.</p>
  672. <p>Attributes and methods for customizing the WSGI environment:</p>
  673. <dl class="py attribute">
  674. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.wsgi_multithread">
  675. <span class="sig-name descname"><span class="pre">wsgi_multithread</span></span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.wsgi_multithread" title="Link to this definition">¶</a></dt>
  676. <dd><p>The value to be used for the <code class="docutils literal notranslate"><span class="pre">wsgi.multithread</span></code> environment variable. It
  677. defaults to true in <a class="reference internal" href="#wsgiref.handlers.BaseHandler" title="wsgiref.handlers.BaseHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseHandler</span></code></a>, but may have a different default (or
  678. be set by the constructor) in the other subclasses.</p>
  679. </dd></dl>
  680. <dl class="py attribute">
  681. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.wsgi_multiprocess">
  682. <span class="sig-name descname"><span class="pre">wsgi_multiprocess</span></span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.wsgi_multiprocess" title="Link to this definition">¶</a></dt>
  683. <dd><p>The value to be used for the <code class="docutils literal notranslate"><span class="pre">wsgi.multiprocess</span></code> environment variable. It
  684. defaults to true in <a class="reference internal" href="#wsgiref.handlers.BaseHandler" title="wsgiref.handlers.BaseHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseHandler</span></code></a>, but may have a different default (or
  685. be set by the constructor) in the other subclasses.</p>
  686. </dd></dl>
  687. <dl class="py attribute">
  688. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.wsgi_run_once">
  689. <span class="sig-name descname"><span class="pre">wsgi_run_once</span></span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.wsgi_run_once" title="Link to this definition">¶</a></dt>
  690. <dd><p>The value to be used for the <code class="docutils literal notranslate"><span class="pre">wsgi.run_once</span></code> environment variable. It
  691. defaults to false in <a class="reference internal" href="#wsgiref.handlers.BaseHandler" title="wsgiref.handlers.BaseHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseHandler</span></code></a>, but <a class="reference internal" href="#wsgiref.handlers.CGIHandler" title="wsgiref.handlers.CGIHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CGIHandler</span></code></a> sets it to
  692. true by default.</p>
  693. </dd></dl>
  694. <dl class="py attribute">
  695. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.os_environ">
  696. <span class="sig-name descname"><span class="pre">os_environ</span></span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.os_environ" title="Link to this definition">¶</a></dt>
  697. <dd><p>The default environment variables to be included in every request’s WSGI
  698. environment. By default, this is a copy of <code class="docutils literal notranslate"><span class="pre">os.environ</span></code> at the time that
  699. <a class="reference internal" href="#module-wsgiref.handlers" title="wsgiref.handlers: WSGI server/gateway base classes."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.handlers</span></code></a> was imported, but subclasses can either create their own
  700. at the class or instance level. Note that the dictionary should be considered
  701. read-only, since the default value is shared between multiple classes and
  702. instances.</p>
  703. </dd></dl>
  704. <dl class="py attribute">
  705. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.server_software">
  706. <span class="sig-name descname"><span class="pre">server_software</span></span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.server_software" title="Link to this definition">¶</a></dt>
  707. <dd><p>If the <a class="reference internal" href="#wsgiref.handlers.BaseHandler.origin_server" title="wsgiref.handlers.BaseHandler.origin_server"><code class="xref py py-attr docutils literal notranslate"><span class="pre">origin_server</span></code></a> attribute is set, this attribute’s value is used to
  708. set the default <code class="docutils literal notranslate"><span class="pre">SERVER_SOFTWARE</span></code> WSGI environment variable, and also to set a
  709. default <code class="docutils literal notranslate"><span class="pre">Server:</span></code> header in HTTP responses. It is ignored for handlers (such
  710. as <a class="reference internal" href="#wsgiref.handlers.BaseCGIHandler" title="wsgiref.handlers.BaseCGIHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseCGIHandler</span></code></a> and <a class="reference internal" href="#wsgiref.handlers.CGIHandler" title="wsgiref.handlers.CGIHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CGIHandler</span></code></a>) that are not HTTP origin
  711. servers.</p>
  712. <div class="versionchanged">
  713. <p><span class="versionmodified changed">Changed in version 3.3: </span>The term “Python” is replaced with implementation specific term like
  714. “CPython”, “Jython” etc.</p>
  715. </div>
  716. </dd></dl>
  717. <dl class="py method">
  718. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.get_scheme">
  719. <span class="sig-name descname"><span class="pre">get_scheme</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.get_scheme" title="Link to this definition">¶</a></dt>
  720. <dd><p>Return the URL scheme being used for the current request. The default
  721. implementation uses the <code class="xref py py-func docutils literal notranslate"><span class="pre">guess_scheme()</span></code> function from <a class="reference internal" href="#module-wsgiref.util" title="wsgiref.util: WSGI environment utilities."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.util</span></code></a>
  722. to guess whether the scheme should be “http” or “https”, based on the current
  723. request’s <code class="xref py py-attr docutils literal notranslate"><span class="pre">environ</span></code> variables.</p>
  724. </dd></dl>
  725. <dl class="py method">
  726. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.setup_environ">
  727. <span class="sig-name descname"><span class="pre">setup_environ</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.setup_environ" title="Link to this definition">¶</a></dt>
  728. <dd><p>Set the <code class="xref py py-attr docutils literal notranslate"><span class="pre">environ</span></code> attribute to a fully populated WSGI environment. The
  729. default implementation uses all of the above methods and attributes, plus the
  730. <a class="reference internal" href="#wsgiref.handlers.BaseHandler.get_stdin" title="wsgiref.handlers.BaseHandler.get_stdin"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_stdin()</span></code></a>, <a class="reference internal" href="#wsgiref.handlers.BaseHandler.get_stderr" title="wsgiref.handlers.BaseHandler.get_stderr"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_stderr()</span></code></a>, and <a class="reference internal" href="#wsgiref.handlers.BaseHandler.add_cgi_vars" title="wsgiref.handlers.BaseHandler.add_cgi_vars"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_cgi_vars()</span></code></a> methods and the
  731. <a class="reference internal" href="#wsgiref.handlers.BaseHandler.wsgi_file_wrapper" title="wsgiref.handlers.BaseHandler.wsgi_file_wrapper"><code class="xref py py-attr docutils literal notranslate"><span class="pre">wsgi_file_wrapper</span></code></a> attribute. It also inserts a <code class="docutils literal notranslate"><span class="pre">SERVER_SOFTWARE</span></code> key
  732. if not present, as long as the <a class="reference internal" href="#wsgiref.handlers.BaseHandler.origin_server" title="wsgiref.handlers.BaseHandler.origin_server"><code class="xref py py-attr docutils literal notranslate"><span class="pre">origin_server</span></code></a> attribute is a true value
  733. and the <a class="reference internal" href="#wsgiref.handlers.BaseHandler.server_software" title="wsgiref.handlers.BaseHandler.server_software"><code class="xref py py-attr docutils literal notranslate"><span class="pre">server_software</span></code></a> attribute is set.</p>
  734. </dd></dl>
  735. <p>Methods and attributes for customizing exception handling:</p>
  736. <dl class="py method">
  737. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.log_exception">
  738. <span class="sig-name descname"><span class="pre">log_exception</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">exc_info</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.log_exception" title="Link to this definition">¶</a></dt>
  739. <dd><p>Log the <em>exc_info</em> tuple in the server log. <em>exc_info</em> is a <code class="docutils literal notranslate"><span class="pre">(type,</span> <span class="pre">value,</span>
  740. <span class="pre">traceback)</span></code> tuple. The default implementation simply writes the traceback to
  741. the request’s <code class="docutils literal notranslate"><span class="pre">wsgi.errors</span></code> stream and flushes it. Subclasses can override
  742. this method to change the format or retarget the output, mail the traceback to
  743. an administrator, or whatever other action may be deemed suitable.</p>
  744. </dd></dl>
  745. <dl class="py attribute">
  746. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.traceback_limit">
  747. <span class="sig-name descname"><span class="pre">traceback_limit</span></span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.traceback_limit" title="Link to this definition">¶</a></dt>
  748. <dd><p>The maximum number of frames to include in tracebacks output by the default
  749. <a class="reference internal" href="#wsgiref.handlers.BaseHandler.log_exception" title="wsgiref.handlers.BaseHandler.log_exception"><code class="xref py py-meth docutils literal notranslate"><span class="pre">log_exception()</span></code></a> method. If <code class="docutils literal notranslate"><span class="pre">None</span></code>, all frames are included.</p>
  750. </dd></dl>
  751. <dl class="py method">
  752. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.error_output">
  753. <span class="sig-name descname"><span class="pre">error_output</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">environ</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">start_response</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.error_output" title="Link to this definition">¶</a></dt>
  754. <dd><p>This method is a WSGI application to generate an error page for the user. It is
  755. only invoked if an error occurs before headers are sent to the client.</p>
  756. <p>This method can access the current error using <code class="docutils literal notranslate"><span class="pre">sys.exception()</span></code>,
  757. and should pass that information to <em>start_response</em> when calling it (as
  758. described in the “Error Handling” section of <span class="target" id="index-12"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>PEP 3333</strong></a>).</p>
  759. <p>The default implementation just uses the <a class="reference internal" href="#wsgiref.handlers.BaseHandler.error_status" title="wsgiref.handlers.BaseHandler.error_status"><code class="xref py py-attr docutils literal notranslate"><span class="pre">error_status</span></code></a>,
  760. <a class="reference internal" href="#wsgiref.handlers.BaseHandler.error_headers" title="wsgiref.handlers.BaseHandler.error_headers"><code class="xref py py-attr docutils literal notranslate"><span class="pre">error_headers</span></code></a>, and <a class="reference internal" href="#wsgiref.handlers.BaseHandler.error_body" title="wsgiref.handlers.BaseHandler.error_body"><code class="xref py py-attr docutils literal notranslate"><span class="pre">error_body</span></code></a> attributes to generate an output
  761. page. Subclasses can override this to produce more dynamic error output.</p>
  762. <p>Note, however, that it’s not recommended from a security perspective to spit out
  763. diagnostics to any old user; ideally, you should have to do something special to
  764. enable diagnostic output, which is why the default implementation doesn’t
  765. include any.</p>
  766. </dd></dl>
  767. <dl class="py attribute">
  768. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.error_status">
  769. <span class="sig-name descname"><span class="pre">error_status</span></span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.error_status" title="Link to this definition">¶</a></dt>
  770. <dd><p>The HTTP status used for error responses. This should be a status string as
  771. defined in <span class="target" id="index-13"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>PEP 3333</strong></a>; it defaults to a 500 code and message.</p>
  772. </dd></dl>
  773. <dl class="py attribute">
  774. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.error_headers">
  775. <span class="sig-name descname"><span class="pre">error_headers</span></span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.error_headers" title="Link to this definition">¶</a></dt>
  776. <dd><p>The HTTP headers used for error responses. This should be a list of WSGI
  777. response headers (<code class="docutils literal notranslate"><span class="pre">(name,</span> <span class="pre">value)</span></code> tuples), as described in <span class="target" id="index-14"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>PEP 3333</strong></a>. The
  778. default list just sets the content type to <code class="docutils literal notranslate"><span class="pre">text/plain</span></code>.</p>
  779. </dd></dl>
  780. <dl class="py attribute">
  781. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.error_body">
  782. <span class="sig-name descname"><span class="pre">error_body</span></span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.error_body" title="Link to this definition">¶</a></dt>
  783. <dd><p>The error response body. This should be an HTTP response body bytestring. It
  784. defaults to the plain text, “A server error occurred. Please contact the
  785. administrator.”</p>
  786. </dd></dl>
  787. <p>Methods and attributes for <span class="target" id="index-15"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>PEP 3333</strong></a>’s “Optional Platform-Specific File
  788. Handling” feature:</p>
  789. <dl class="py attribute">
  790. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.wsgi_file_wrapper">
  791. <span class="sig-name descname"><span class="pre">wsgi_file_wrapper</span></span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.wsgi_file_wrapper" title="Link to this definition">¶</a></dt>
  792. <dd><p>A <code class="docutils literal notranslate"><span class="pre">wsgi.file_wrapper</span></code> factory, compatible with
  793. <a class="reference internal" href="#wsgiref.types.FileWrapper" title="wsgiref.types.FileWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">wsgiref.types.FileWrapper</span></code></a>, or <code class="docutils literal notranslate"><span class="pre">None</span></code>. The default value
  794. of this attribute is the <a class="reference internal" href="#wsgiref.util.FileWrapper" title="wsgiref.util.FileWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">wsgiref.util.FileWrapper</span></code></a> class.</p>
  795. </dd></dl>
  796. <dl class="py method">
  797. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.sendfile">
  798. <span class="sig-name descname"><span class="pre">sendfile</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.sendfile" title="Link to this definition">¶</a></dt>
  799. <dd><p>Override to implement platform-specific file transmission. This method is
  800. called only if the application’s return value is an instance of the class
  801. specified by the <a class="reference internal" href="#wsgiref.handlers.BaseHandler.wsgi_file_wrapper" title="wsgiref.handlers.BaseHandler.wsgi_file_wrapper"><code class="xref py py-attr docutils literal notranslate"><span class="pre">wsgi_file_wrapper</span></code></a> attribute. It should return a true
  802. value if it was able to successfully transmit the file, so that the default
  803. transmission code will not be executed. The default implementation of this
  804. method just returns a false value.</p>
  805. </dd></dl>
  806. <p>Miscellaneous methods and attributes:</p>
  807. <dl class="py attribute">
  808. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.origin_server">
  809. <span class="sig-name descname"><span class="pre">origin_server</span></span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.origin_server" title="Link to this definition">¶</a></dt>
  810. <dd><p>This attribute should be set to a true value if the handler’s <a class="reference internal" href="#wsgiref.handlers.BaseHandler._write" title="wsgiref.handlers.BaseHandler._write"><code class="xref py py-meth docutils literal notranslate"><span class="pre">_write()</span></code></a> and
  811. <a class="reference internal" href="#wsgiref.handlers.BaseHandler._flush" title="wsgiref.handlers.BaseHandler._flush"><code class="xref py py-meth docutils literal notranslate"><span class="pre">_flush()</span></code></a> are being used to communicate directly to the client, rather than
  812. via a CGI-like gateway protocol that wants the HTTP status in a special
  813. <code class="docutils literal notranslate"><span class="pre">Status:</span></code> header.</p>
  814. <p>This attribute’s default value is true in <a class="reference internal" href="#wsgiref.handlers.BaseHandler" title="wsgiref.handlers.BaseHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseHandler</span></code></a>, but false in
  815. <a class="reference internal" href="#wsgiref.handlers.BaseCGIHandler" title="wsgiref.handlers.BaseCGIHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseCGIHandler</span></code></a> and <a class="reference internal" href="#wsgiref.handlers.CGIHandler" title="wsgiref.handlers.CGIHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CGIHandler</span></code></a>.</p>
  816. </dd></dl>
  817. <dl class="py attribute">
  818. <dt class="sig sig-object py" id="wsgiref.handlers.BaseHandler.http_version">
  819. <span class="sig-name descname"><span class="pre">http_version</span></span><a class="headerlink" href="#wsgiref.handlers.BaseHandler.http_version" title="Link to this definition">¶</a></dt>
  820. <dd><p>If <a class="reference internal" href="#wsgiref.handlers.BaseHandler.origin_server" title="wsgiref.handlers.BaseHandler.origin_server"><code class="xref py py-attr docutils literal notranslate"><span class="pre">origin_server</span></code></a> is true, this string attribute is used to set the HTTP
  821. version of the response set to the client. It defaults to <code class="docutils literal notranslate"><span class="pre">&quot;1.0&quot;</span></code>.</p>
  822. </dd></dl>
  823. </dd></dl>
  824. <dl class="py function">
  825. <dt class="sig sig-object py" id="wsgiref.handlers.read_environ">
  826. <span class="sig-prename descclassname"><span class="pre">wsgiref.handlers.</span></span><span class="sig-name descname"><span class="pre">read_environ</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#wsgiref.handlers.read_environ" title="Link to this definition">¶</a></dt>
  827. <dd><p>Transcode CGI variables from <code class="docutils literal notranslate"><span class="pre">os.environ</span></code> to <span class="target" id="index-16"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>PEP 3333</strong></a> “bytes in unicode”
  828. strings, returning a new dictionary. This function is used by
  829. <a class="reference internal" href="#wsgiref.handlers.CGIHandler" title="wsgiref.handlers.CGIHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CGIHandler</span></code></a> and <a class="reference internal" href="#wsgiref.handlers.IISCGIHandler" title="wsgiref.handlers.IISCGIHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">IISCGIHandler</span></code></a> in place of directly using
  830. <code class="docutils literal notranslate"><span class="pre">os.environ</span></code>, which is not necessarily WSGI-compliant on all platforms
  831. and web servers using Python 3 – specifically, ones where the OS’s
  832. actual environment is Unicode (i.e. Windows), or ones where the environment
  833. is bytes, but the system encoding used by Python to decode it is anything
  834. other than ISO-8859-1 (e.g. Unix systems using UTF-8).</p>
  835. <p>If you are implementing a CGI-based handler of your own, you probably want
  836. to use this routine instead of just copying values out of <code class="docutils literal notranslate"><span class="pre">os.environ</span></code>
  837. directly.</p>
  838. <div class="versionadded">
  839. <p><span class="versionmodified added">New in version 3.2.</span></p>
  840. </div>
  841. </dd></dl>
  842. </section>
  843. <section id="module-wsgiref.types">
  844. <span id="wsgiref-types-wsgi-types-for-static-type-checking"></span><h2><a class="reference internal" href="#module-wsgiref.types" title="wsgiref.types: WSGI types for static type checking"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.types</span></code></a> – WSGI types for static type checking<a class="headerlink" href="#module-wsgiref.types" title="Link to this heading">¶</a></h2>
  845. <p>This module provides various types for static type checking as described
  846. in <span class="target" id="index-17"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>PEP 3333</strong></a>.</p>
  847. <div class="versionadded">
  848. <p><span class="versionmodified added">New in version 3.11.</span></p>
  849. </div>
  850. <dl class="py class">
  851. <dt class="sig sig-object py" id="wsgiref.types.StartResponse">
  852. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">wsgiref.types.</span></span><span class="sig-name descname"><span class="pre">StartResponse</span></span><a class="headerlink" href="#wsgiref.types.StartResponse" title="Link to this definition">¶</a></dt>
  853. <dd><p>A <a class="reference internal" href="typing.html#typing.Protocol" title="typing.Protocol"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Protocol</span></code></a> describing <a class="reference external" href="https://peps.python.org/pep-3333/#the-start-response-callable">start_response()</a>
  854. callables (<span class="target" id="index-18"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>PEP 3333</strong></a>).</p>
  855. </dd></dl>
  856. <dl class="py data">
  857. <dt class="sig sig-object py" id="wsgiref.types.WSGIEnvironment">
  858. <span class="sig-prename descclassname"><span class="pre">wsgiref.types.</span></span><span class="sig-name descname"><span class="pre">WSGIEnvironment</span></span><a class="headerlink" href="#wsgiref.types.WSGIEnvironment" title="Link to this definition">¶</a></dt>
  859. <dd><p>A type alias describing a WSGI environment dictionary.</p>
  860. </dd></dl>
  861. <dl class="py data">
  862. <dt class="sig sig-object py" id="wsgiref.types.WSGIApplication">
  863. <span class="sig-prename descclassname"><span class="pre">wsgiref.types.</span></span><span class="sig-name descname"><span class="pre">WSGIApplication</span></span><a class="headerlink" href="#wsgiref.types.WSGIApplication" title="Link to this definition">¶</a></dt>
  864. <dd><p>A type alias describing a WSGI application callable.</p>
  865. </dd></dl>
  866. <dl class="py class">
  867. <dt class="sig sig-object py" id="wsgiref.types.InputStream">
  868. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">wsgiref.types.</span></span><span class="sig-name descname"><span class="pre">InputStream</span></span><a class="headerlink" href="#wsgiref.types.InputStream" title="Link to this definition">¶</a></dt>
  869. <dd><p>A <a class="reference internal" href="typing.html#typing.Protocol" title="typing.Protocol"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Protocol</span></code></a> describing a <a class="reference external" href="https://peps.python.org/pep-3333/#input-and-error-streams">WSGI Input Stream</a>.</p>
  870. </dd></dl>
  871. <dl class="py class">
  872. <dt class="sig sig-object py" id="wsgiref.types.ErrorStream">
  873. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">wsgiref.types.</span></span><span class="sig-name descname"><span class="pre">ErrorStream</span></span><a class="headerlink" href="#wsgiref.types.ErrorStream" title="Link to this definition">¶</a></dt>
  874. <dd><p>A <a class="reference internal" href="typing.html#typing.Protocol" title="typing.Protocol"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Protocol</span></code></a> describing a <a class="reference external" href="https://peps.python.org/pep-3333/#input-and-error-streams">WSGI Error Stream</a>.</p>
  875. </dd></dl>
  876. <dl class="py class">
  877. <dt class="sig sig-object py" id="wsgiref.types.FileWrapper">
  878. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">wsgiref.types.</span></span><span class="sig-name descname"><span class="pre">FileWrapper</span></span><a class="headerlink" href="#wsgiref.types.FileWrapper" title="Link to this definition">¶</a></dt>
  879. <dd><p>A <a class="reference internal" href="typing.html#typing.Protocol" title="typing.Protocol"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Protocol</span></code></a> describing a <a class="reference external" href="https://peps.python.org/pep-3333/#optional-platform-specific-file-handling">file wrapper</a>.
  880. See <a class="reference internal" href="#wsgiref.util.FileWrapper" title="wsgiref.util.FileWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">wsgiref.util.FileWrapper</span></code></a> for a concrete implementation of this
  881. protocol.</p>
  882. </dd></dl>
  883. </section>
  884. <section id="examples">
  885. <h2>Examples<a class="headerlink" href="#examples" title="Link to this heading">¶</a></h2>
  886. <p>This is a working “Hello World” WSGI application:</p>
  887. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="sd">&quot;&quot;&quot;</span>
  888. <span class="sd">Every WSGI application must have an application object - a callable</span>
  889. <span class="sd">object that accepts two arguments. For that purpose, we&#39;re going to</span>
  890. <span class="sd">use a function (note that you&#39;re not limited to a function, you can</span>
  891. <span class="sd">use a class for example). The first argument passed to the function</span>
  892. <span class="sd">is a dictionary containing CGI-style environment variables and the</span>
  893. <span class="sd">second variable is the callable object.</span>
  894. <span class="sd">&quot;&quot;&quot;</span>
  895. <span class="kn">from</span> <span class="nn">wsgiref.simple_server</span> <span class="kn">import</span> <span class="n">make_server</span>
  896. <span class="k">def</span> <span class="nf">hello_world_app</span><span class="p">(</span><span class="n">environ</span><span class="p">,</span> <span class="n">start_response</span><span class="p">):</span>
  897. <span class="n">status</span> <span class="o">=</span> <span class="s2">&quot;200 OK&quot;</span> <span class="c1"># HTTP Status</span>
  898. <span class="n">headers</span> <span class="o">=</span> <span class="p">[(</span><span class="s2">&quot;Content-type&quot;</span><span class="p">,</span> <span class="s2">&quot;text/plain; charset=utf-8&quot;</span><span class="p">)]</span> <span class="c1"># HTTP Headers</span>
  899. <span class="n">start_response</span><span class="p">(</span><span class="n">status</span><span class="p">,</span> <span class="n">headers</span><span class="p">)</span>
  900. <span class="c1"># The returned object is going to be printed</span>
  901. <span class="k">return</span> <span class="p">[</span><span class="sa">b</span><span class="s2">&quot;Hello World&quot;</span><span class="p">]</span>
  902. <span class="k">with</span> <span class="n">make_server</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="mi">8000</span><span class="p">,</span> <span class="n">hello_world_app</span><span class="p">)</span> <span class="k">as</span> <span class="n">httpd</span><span class="p">:</span>
  903. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Serving on port 8000...&quot;</span><span class="p">)</span>
  904. <span class="c1"># Serve until process is killed</span>
  905. <span class="n">httpd</span><span class="o">.</span><span class="n">serve_forever</span><span class="p">()</span>
  906. </pre></div>
  907. </div>
  908. <p>Example of a WSGI application serving the current directory, accept optional
  909. directory and port number (default: 8000) on the command line:</p>
  910. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="sd">&quot;&quot;&quot;</span>
  911. <span class="sd">Small wsgiref based web server. Takes a path to serve from and an</span>
  912. <span class="sd">optional port number (defaults to 8000), then tries to serve files.</span>
  913. <span class="sd">MIME types are guessed from the file names, 404 errors are raised</span>
  914. <span class="sd">if the file is not found.</span>
  915. <span class="sd">&quot;&quot;&quot;</span>
  916. <span class="kn">import</span> <span class="nn">mimetypes</span>
  917. <span class="kn">import</span> <span class="nn">os</span>
  918. <span class="kn">import</span> <span class="nn">sys</span>
  919. <span class="kn">from</span> <span class="nn">wsgiref</span> <span class="kn">import</span> <span class="n">simple_server</span><span class="p">,</span> <span class="n">util</span>
  920. <span class="k">def</span> <span class="nf">app</span><span class="p">(</span><span class="n">environ</span><span class="p">,</span> <span class="n">respond</span><span class="p">):</span>
  921. <span class="c1"># Get the file name and MIME type</span>
  922. <span class="n">fn</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">environ</span><span class="p">[</span><span class="s2">&quot;PATH_INFO&quot;</span><span class="p">][</span><span class="mi">1</span><span class="p">:])</span>
  923. <span class="k">if</span> <span class="s2">&quot;.&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">fn</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">sep</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]:</span>
  924. <span class="n">fn</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">fn</span><span class="p">,</span> <span class="s2">&quot;index.html&quot;</span><span class="p">)</span>
  925. <span class="n">mime_type</span> <span class="o">=</span> <span class="n">mimetypes</span><span class="o">.</span><span class="n">guess_type</span><span class="p">(</span><span class="n">fn</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
  926. <span class="c1"># Return 200 OK if file exists, otherwise 404 Not Found</span>
  927. <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">fn</span><span class="p">):</span>
  928. <span class="n">respond</span><span class="p">(</span><span class="s2">&quot;200 OK&quot;</span><span class="p">,</span> <span class="p">[(</span><span class="s2">&quot;Content-Type&quot;</span><span class="p">,</span> <span class="n">mime_type</span><span class="p">)])</span>
  929. <span class="k">return</span> <span class="n">util</span><span class="o">.</span><span class="n">FileWrapper</span><span class="p">(</span><span class="nb">open</span><span class="p">(</span><span class="n">fn</span><span class="p">,</span> <span class="s2">&quot;rb&quot;</span><span class="p">))</span>
  930. <span class="k">else</span><span class="p">:</span>
  931. <span class="n">respond</span><span class="p">(</span><span class="s2">&quot;404 Not Found&quot;</span><span class="p">,</span> <span class="p">[(</span><span class="s2">&quot;Content-Type&quot;</span><span class="p">,</span> <span class="s2">&quot;text/plain&quot;</span><span class="p">)])</span>
  932. <span class="k">return</span> <span class="p">[</span><span class="sa">b</span><span class="s2">&quot;not found&quot;</span><span class="p">]</span>
  933. <span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
  934. <span class="c1"># Get the path and port from command-line arguments</span>
  935. <span class="n">path</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="k">else</span> <span class="n">os</span><span class="o">.</span><span class="n">getcwd</span><span class="p">()</span>
  936. <span class="n">port</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">2</span> <span class="k">else</span> <span class="mi">8000</span>
  937. <span class="c1"># Make and start the server until control-c</span>
  938. <span class="n">httpd</span> <span class="o">=</span> <span class="n">simple_server</span><span class="o">.</span><span class="n">make_server</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">port</span><span class="p">,</span> <span class="n">app</span><span class="p">)</span>
  939. <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Serving </span><span class="si">{</span><span class="n">path</span><span class="si">}</span><span class="s2"> on port </span><span class="si">{</span><span class="n">port</span><span class="si">}</span><span class="s2">, control-C to stop&quot;</span><span class="p">)</span>
  940. <span class="k">try</span><span class="p">:</span>
  941. <span class="n">httpd</span><span class="o">.</span><span class="n">serve_forever</span><span class="p">()</span>
  942. <span class="k">except</span> <span class="ne">KeyboardInterrupt</span><span class="p">:</span>
  943. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Shutting down.&quot;</span><span class="p">)</span>
  944. <span class="n">httpd</span><span class="o">.</span><span class="n">server_close</span><span class="p">()</span>
  945. </pre></div>
  946. </div>
  947. </section>
  948. </section>
  949. <div class="clearer"></div>
  950. </div>
  951. </div>
  952. </div>
  953. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  954. <div class="sphinxsidebarwrapper">
  955. <div>
  956. <h3><a href="../contents.html">Table of Contents</a></h3>
  957. <ul>
  958. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref</span></code> — WSGI Utilities and Reference Implementation</a><ul>
  959. <li><a class="reference internal" href="#module-wsgiref.util"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.util</span></code> – WSGI environment utilities</a></li>
  960. <li><a class="reference internal" href="#module-wsgiref.headers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.headers</span></code> – WSGI response header tools</a></li>
  961. <li><a class="reference internal" href="#module-wsgiref.simple_server"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.simple_server</span></code> – a simple WSGI HTTP server</a></li>
  962. <li><a class="reference internal" href="#module-wsgiref.validate"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.validate</span></code> — WSGI conformance checker</a></li>
  963. <li><a class="reference internal" href="#module-wsgiref.handlers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.handlers</span></code> – server/gateway base classes</a></li>
  964. <li><a class="reference internal" href="#module-wsgiref.types"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.types</span></code> – WSGI types for static type checking</a></li>
  965. <li><a class="reference internal" href="#examples">Examples</a></li>
  966. </ul>
  967. </li>
  968. </ul>
  969. </div>
  970. <div>
  971. <h4>Previous topic</h4>
  972. <p class="topless"><a href="webbrowser.html"
  973. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">webbrowser</span></code> — Convenient web-browser controller</a></p>
  974. </div>
  975. <div>
  976. <h4>Next topic</h4>
  977. <p class="topless"><a href="urllib.html"
  978. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib</span></code> — URL handling modules</a></p>
  979. </div>
  980. <div role="note" aria-label="source link">
  981. <h3>This Page</h3>
  982. <ul class="this-page-menu">
  983. <li><a href="../bugs.html">Report a Bug</a></li>
  984. <li>
  985. <a href="https://github.com/python/cpython/blob/main/Doc/library/wsgiref.rst"
  986. rel="nofollow">Show Source
  987. </a>
  988. </li>
  989. </ul>
  990. </div>
  991. </div>
  992. <div id="sidebarbutton" title="Collapse sidebar">
  993. <span>«</span>
  994. </div>
  995. </div>
  996. <div class="clearer"></div>
  997. </div>
  998. <div class="related" role="navigation" aria-label="related navigation">
  999. <h3>Navigation</h3>
  1000. <ul>
  1001. <li class="right" style="margin-right: 10px">
  1002. <a href="../genindex.html" title="General Index"
  1003. >index</a></li>
  1004. <li class="right" >
  1005. <a href="../py-modindex.html" title="Python Module Index"
  1006. >modules</a> |</li>
  1007. <li class="right" >
  1008. <a href="urllib.html" title="urllib — URL handling modules"
  1009. >next</a> |</li>
  1010. <li class="right" >
  1011. <a href="webbrowser.html" title="webbrowser — Convenient web-browser controller"
  1012. >previous</a> |</li>
  1013. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  1014. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  1015. <li class="switchers">
  1016. <div class="language_switcher_placeholder"></div>
  1017. <div class="version_switcher_placeholder"></div>
  1018. </li>
  1019. <li>
  1020. </li>
  1021. <li id="cpython-language-and-version">
  1022. <a href="../index.html">3.12.3 Documentation</a> &#187;
  1023. </li>
  1024. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  1025. <li class="nav-item nav-item-2"><a href="internet.html" >Internet Protocols and Support</a> &#187;</li>
  1026. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref</span></code> — WSGI Utilities and Reference Implementation</a></li>
  1027. <li class="right">
  1028. <div class="inline-search" role="search">
  1029. <form class="inline-search" action="../search.html" method="get">
  1030. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  1031. <input type="submit" value="Go" />
  1032. </form>
  1033. </div>
  1034. |
  1035. </li>
  1036. <li class="right">
  1037. <label class="theme-selector-label">
  1038. Theme
  1039. <select class="theme-selector" oninput="activateTheme(this.value)">
  1040. <option value="auto" selected>Auto</option>
  1041. <option value="light">Light</option>
  1042. <option value="dark">Dark</option>
  1043. </select>
  1044. </label> |</li>
  1045. </ul>
  1046. </div>
  1047. <div class="footer">
  1048. &copy;
  1049. <a href="../copyright.html">
  1050. Copyright
  1051. </a>
  1052. 2001-2024, Python Software Foundation.
  1053. <br />
  1054. This page is licensed under the Python Software Foundation License Version 2.
  1055. <br />
  1056. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  1057. <br />
  1058. See <a href="/license.html">History and License</a> for more information.<br />
  1059. <br />
  1060. The Python Software Foundation is a non-profit corporation.
  1061. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  1062. <br />
  1063. <br />
  1064. Last updated on Apr 09, 2024 (13:47 UTC).
  1065. <a href="/bugs.html">Found a bug</a>?
  1066. <br />
  1067. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  1068. </div>
  1069. </body>
  1070. </html>
上海开阖软件有限公司 沪ICP备12045867号-1