File: //usr/lib/python3/dist-packages/twisted/web/__pycache__/wsgi.cpython-310.pyc
o
�b�U � @ 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� d�ZG dd� d�ZG dd� d�Zee�G dd� d��ZdgZdS )zo
An implementation of
U{Python Web Server Gateway Interface v1.0.1<http://www.python.org/dev/peps/pep-3333/>}.
� )�Sequence)�exc_info)�warn)�implementer)�blockingCallFromThread)�Logger)�Failure)�INTERNAL_SERVER_ERROR)� IResource)�NOT_DONE_YETc C s t | t�r| S | �d�S )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)�
isinstance�str�encode��string� 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 | t�r
| �d��d�S | �d�S )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
| � d�S )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<twisted.logger>} 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 |t�s"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)�system�isError�messageN)
r
r �bytesr �type�__name__�UnicodeWarning� TypeError�_log�error)�self�datar 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'