o
bU @ s d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl m
Z
ddlmZ ddl
mZ dd lmZ dd
lmZ ddlmZ eeu rKdd
Zdd Zndd
Zdd ZG dd dZG dd dZG dd dZeeG dd dZdgZdS )zo
An implementation of
U{Python Web Server Gateway Interface v1.0.1}.
)Sequence)exc_info)warn)implementer)blockingCallFromThread)Logger)Failure)INTERNAL_SERVER_ERROR) IResource)NOT_DONE_YETc C s t | tr| S | dS )z
Convert C{string} to an ISO-8859-1 byte string, if it is not already.
@type string: C{str}/C{bytes} or C{unicode}
@rtype: C{str}/C{bytes}
@raise UnicodeEncodeError: If C{string} contains non-ISO-8859-1 chars.
iso-8859-1)
isinstancestrencodestring r 2/usr/lib/python3/dist-packages/twisted/web/wsgi.py_wsgiString* s
r c C s | S )z
Return C{string} as is; a WSGI string is a byte string in Python 2.
@type string: C{str}/C{bytes}
@rtype: C{str}/C{bytes}
r r r r r _wsgiStringToBytes8 s r c C s$ t | tr
| ddS | dS )as
Convert C{string} to a WSGI "bytes-as-unicode" string.
If it's a byte string, decode as ISO-8859-1. If it's a Unicode string,
round-trip it to bytes and back using ISO-8859-1 as the encoding.
@type string: C{str} or C{bytes}
@rtype: C{str}
@raise UnicodeEncodeError: If C{string} contains non-ISO-8859-1 chars.
r )r
r r decoder r r r r D s
c C s
| dS )z
Convert C{string} from a WSGI "bytes-as-unicode" string to an
ISO-8859-1 byte string.
@type string: C{str}
@rtype: C{bytes}
@raise UnicodeEncodeError: If C{string} contains non-ISO-8859-1 chars.
r )r r r r r r U s
c @ s. e Zd ZdZe Zdd Zdd Zdd ZdS ) _ErrorStreama
File-like object instances of which are used as the value for the
C{'wsgi.errors'} key in the C{environ} dictionary passed to the application
object.
This simply passes writes on to L{logging} system as
error events from the C{'wsgi'} system. In the future, it may be desirable
to expose more information in the events it logs, such as the application
object which generated the message.
c C s^ t |ts"ttu rtd|t|jf td ntd|t|jf | jj |dd|fd dS )aG
Generate an event for the logging system with the given bytes as the
message.
This is called in a WSGI application thread, not the I/O thread.
@type data: str
@raise TypeError: On Python 3, if C{data} is not a native string. On
Python 2 a warning will be issued.
z+write() argument should be str, not %r (%s)categoryz)write() argument must be str, not %r (%s)wsgiT)systemisErrormessageN)
r
r bytesr type__name__UnicodeWarning TypeError_logerror)selfdatar r r writep s
z_ErrorStream.writec C s | d| dS )a
Join the given lines and pass them to C{write} to be handled in the
usual way.
This is called in a WSGI application thread, not the I/O thread.
@param iovec: A C{list} of C{'\n'}-terminated C{str} which will be
logged.
@raise TypeError: On Python 3, if C{iovec} contains any non-native
strings. On Python 2 a warning will be issued.
N)r' join)r% iovecr r r
writelines s
z_ErrorStream.writelinesc C s dS )z
Nothing is buffered, so flushing does nothing. This method is required
to exist by PEP 333, though.
This is called in a WSGI application thread, not the I/O thread.
Nr r% r r r flush s z_ErrorStream.flushN) r
__module____qualname____doc__r r# r' r+ r- r r r r r b s r c @ s> e Zd ZdZdd Zd
ddZd
ddZd
d d
Zdd ZdS )_InputStreama
File-like object instances of which are used as the value for the
C{'wsgi.input'} key in the C{environ} dictionary passed to the application
object.
This only exists to make the handling of C{readline(-1)} consistent across
different possible underlying file-like object implementations. The other
supported methods pass through directly to the wrapped object.
c C s
|| _ dS )zt
Initialize the instance.
This is called in the I/O thread, not a WSGI application thread.
N)_wrapped)r% inputr r r __init__
z_InputStream.__init__Nc C |du r | j S | j |S )z
Pass through to the underlying C{read}.
This is called in a WSGI application thread, not the I/O thread.
N)r2 readr% sizer r r r7
z_InputStream.readc C s&