File: //lib/python3/dist-packages/twisted/web/__pycache__/wsgi.cpython-38.pyc
U
��W[wU � @ s� d Z eZddlmZ ddlmZ ddlmZ ddl m
Z
ddlmZm
Z
ddlmZ ddlmZ dd lmZ dd
lmZ ddlmZ eekr�dd
� Zdd� Zndd
� Zdd� ZG dd� d�ZG dd� d�ZG dd� d�Zee�G dd� d��ZdgZ dS )zo
An implementation of
U{Python Web Server Gateway Interface v1.0.1<http://www.python.org/dev/peps/pep-3333/>}.
� )�exc_info)�warn)�implementer)�blockingCallFromThread)�reraise�Sequence)�Failure)� IResource)�NOT_DONE_YET)�INTERNAL_SERVER_ERROR)�Loggerc C s t | t�r| S | �d�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-1N)�
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 �_wsgiStringToBytes; s r c C s( t | t�r| �d��d�S | �d�S 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
N)r r r �decoder r r r r E 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 V 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�sDttkr.td|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)ZwsgiT)�systemZisError�messageN)
r r �bytesr �type�__name__�UnicodeWarning� TypeError�_log�error)�self�datar r r �writeq s&