@@ -23,6 +23,7 @@ an existing framework.
23
23
be used to add WSGI support to a web server or framework. It provides utilities
24
24
for manipulating WSGI environment variables and response headers, base classes
25
25
for implementing WSGI servers, a demo HTTP server that serves WSGI applications,
26
+ types for static type checking,
26
27
and a validation tool that checks WSGI servers and applications for conformance
27
28
to the WSGI specification (:pep: `3333 `).
28
29
@@ -43,7 +44,9 @@ This module provides a variety of utility functions for working with WSGI
43
44
environments. A WSGI environment is a dictionary containing HTTP request
44
45
variables as described in :pep: `3333 `. All of the functions taking an *environ *
45
46
parameter expect a WSGI-compliant dictionary to be supplied; please see
46
- :pep: `3333 ` for a detailed specification.
47
+ :pep: `3333 ` for a detailed specification and
48
+ :data: `~wsgiref.types.WSGIEnvironment ` for a type alias that can be used
49
+ in type annotations.
47
50
48
51
49
52
.. function :: guess_scheme(environ)
@@ -150,7 +153,9 @@ also provides these miscellaneous utilities:
150
153
151
154
.. class :: FileWrapper(filelike, blksize=8192)
152
155
153
- A wrapper to convert a file-like object to an :term: `iterator `. The resulting objects
156
+ A concrete implementation of the :class: `wsgiref.types.FileWrapper `
157
+ protocol used to convert a file-like object to an :term: `iterator `.
158
+ The resulting objects
154
159
are :term: `iterable `\ s. As the object is iterated over, the
155
160
optional *blksize * parameter will be repeatedly passed to the *filelike *
156
161
object's :meth: `read ` method to obtain bytestrings to yield. When :meth: `read `
@@ -349,7 +354,8 @@ request. (E.g., using the :func:`shift_path_info` function from
349
354
350
355
.. method :: WSGIRequestHandler.get_environ()
351
356
352
- Returns a dictionary containing the WSGI environment for a request. The default
357
+ Return a :data: `~wsgiref.types.WSGIEnvironment ` dictionary for a
358
+ request. The default
353
359
implementation copies the contents of the :class: `WSGIServer ` object's
354
360
:attr: `base_environ ` dictionary attribute and then adds various headers derived
355
361
from the HTTP request. Each call to this method should return a new dictionary
@@ -558,13 +564,15 @@ input, output, and error streams.
558
564
559
565
.. method :: BaseHandler.get_stdin()
560
566
561
- Return an input stream object suitable for use as the ``wsgi.input `` of the
567
+ Return an object compatible with :class: `~wsgiref.types.InputStream `
568
+ suitable for use as the ``wsgi.input `` of the
562
569
request currently being processed.
563
570
564
571
565
572
.. method :: BaseHandler.get_stderr()
566
573
567
- Return an output stream object suitable for use as the ``wsgi.errors `` of the
574
+ Return an object compatible with :class: `~wsgiref.types.ErrorStream `
575
+ suitable for use as the ``wsgi.errors `` of the
568
576
request currently being processed.
569
577
570
578
@@ -703,8 +711,9 @@ input, output, and error streams.
703
711
704
712
.. attribute :: BaseHandler.wsgi_file_wrapper
705
713
706
- A ``wsgi.file_wrapper `` factory, or ``None ``. The default value of this
707
- attribute is the :class: `wsgiref.util.FileWrapper ` class.
714
+ A ``wsgi.file_wrapper `` factory, compatible with
715
+ :class: `wsgiref.types.FileWrapper `, or ``None ``. The default value
716
+ of this attribute is the :class: `wsgiref.util.FileWrapper ` class.
708
717
709
718
710
719
.. method :: BaseHandler.sendfile()
@@ -754,6 +763,51 @@ input, output, and error streams.
754
763
.. versionadded :: 3.2
755
764
756
765
766
+ :mod: `wsgiref.types ` -- WSGI types for static type checking
767
+ -----------------------------------------------------------
768
+
769
+ .. module :: wsgiref.types
770
+ :synopsis: WSGI types for static type checking
771
+
772
+
773
+ This module provides various types for static type checking as described
774
+ in :pep: `3333 `.
775
+
776
+ .. versionadded :: 3.11
777
+
778
+
779
+ .. class :: StartResponse()
780
+
781
+ A :class: `typing.Protocol ` describing `start_response()
782
+ <https://peps.python.org/pep-3333/#the-start-response-callable> `_
783
+ callables (:pep: `3333 `).
784
+
785
+ .. data :: WSGIEnvironment
786
+
787
+ A type alias describing a WSGI environment dictionary.
788
+
789
+ .. data :: WSGIApplication
790
+
791
+ A type alias describing a WSGI application callable.
792
+
793
+ .. class :: InputStream()
794
+
795
+ A :class: `typing.Protocol ` describing a `WSGI Input Stream
796
+ <https://peps.python.org/pep-3333/#input-and-error-streams> `_.
797
+
798
+ .. class :: ErrorStream()
799
+
800
+ A :class: `typing.Protocol ` describing a `WSGI Error Stream
801
+ <https://peps.python.org/pep-3333/#input-and-error-streams> `_.
802
+
803
+ .. class :: FileWrapper()
804
+
805
+ A :class: `typing.Protocol ` describing a `file wrapper
806
+ <https://peps.python.org/pep-3333/#optional-platform-specific-file-handling> `_.
807
+ See :class: `wsgiref.util.FileWrapper ` for a concrete implementation of this
808
+ protocol.
809
+
810
+
757
811
Examples
758
812
--------
759
813
0 commit comments