File: //usr/lib/python3/dist-packages/twisted/web/test/__pycache__/test_cgi.cpython-38.pyc
U
W[�5 � @ s* d Z ddlZddlZddlZddlmZ ddlmZ ddlm Z m
Z
mZmZ ddl
mZmZmZ ddlmZmZ ddlmZmZmZmZmZ dd lmZ dd
lmZ dZdZd
Z dZ!dZ"dZ#dZ$dZ%G dd� dej&�Z'G dd� dej(�Z)G dd� dej(�Z*G dd� dej(�Z+G dd� dej(�Z,dd� Z-dS )z!
Tests for L{twisted.web.twcgi}.
� N)�BytesIO)�unittest)�address�reactor�
interfaces�error)�util�failure�log)� NOT_FOUND�INTERNAL_SERVER_ERROR)�client�twcgi�server�resource�http_headers)�_render)�DummyRequestz2print("Header: OK")
print("")
print("cgi output")
zJprint("Header: spam")
print("Header: eggs")
print("")
print("cgi output")
z+print("XYZ")
print("")
print("cgi output")
zPprint("Server: monkeys")
print("Date: last year")
print("")
print("cgi output")
a& # This is an example of a correctly-written CGI script which reads a body
# from stdin, which only reads env['CONTENT_LENGTH'] bytes.
import os, sys
body_length = int(os.environ.get('CONTENT_LENGTH',0))
indata = sys.stdin.read(body_length)
print("Header: OK")
print("")
print("readinput ok")
a+ # This is an example of the typical (incorrect) CGI script which expects
# the server to close stdin when the body of the request is complete.
# A correct CGI should only read env['CONTENT_LENGTH'] bytes.
import sys
indata = sys.stdin.read()
print("Header: OK")
print("")
print("readallinput ok")
zMprint("content-type: text/cgi-duplicate-test")
print("")
print("cgi output")
z�import json
import os
print("")
print("")
vals = {x:y for x,y in os.environ.items() if x.startswith("HTTP_")}
print(json.dumps(vals))
c @ s e Zd ZejZdS )�PythonScriptN)�__name__�
__module__�__qualname__�sys�
executable�filter� r r �;/usr/lib/python3/dist-packages/twisted/web/test/test_cgi.pyr X s r c @ s� e Zd ZdZej�e�sdZdd� Z dd� Z
dd� Zd d
� Zdd� Z
d
d� Zdd� Zdd� Zdd� Zdd� Zdd� Zde_dd� Zdd� Zde_dd� Zd d!� Zde_d"d#� Zd$d%� Zd&S )'�CGITestsz,
Tests for L{twcgi.FilteredScript}.
z5CGI tests require a functional reactor.spawnProcess()c C sH t �� }t�t|�}|�dt|�� t�|�}t �
d|�| _| j�� j
S )Ns cgir )r ZResourcer Zsibpath�__file__ZputChildr r ZSiter Z listenTCP�pZgetHostZport)�selfZcgi�rootZcgipathZsiter r r �startServerf s
zCGITests.startServerc C s t | dd �r| j�� S d S )Nr )�getattrr Z
stopListening�r r r r �tearDowno s zCGITests.tearDownc C s4 t j�| �� �}t|d��}|�|� W 5 Q R X |S )N�wt)�os�path�abspath�mktemp�open�write)r �source�cgiFilename�cgiFiler r r �writeCGIt s zCGITests.writeCGIc C sV | � t�}| �|�}d|f }|�d�}t�t��d|�}|�tj � |�| j
� |S )N�http://localhost:%d/cgi�ascii� GET)r0 � DUMMY_CGIr"