Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/twisted/web/test/__pycache__/test_cgi.cpython-39.pyc
Ðазад
a k�h; � @ sT d Z ddlZddlZddlZddlmZ ddlmZmZm Z m Z ddlmZ ddl mZmZmZ ddlmZ ddlmZmZmZmZmZmZ dd lmZmZ dd lmZ ddlm Z m!Z! dZ"d Z#dZ$dZ%dZ&dZ'dZ(dZ)dZ*G dd� dej+�Z,G dd� d�Z-G dd� de-ej.�Z/G dd� de-ej.�Z0G dd� dej.�Z1G dd � d ej.�Z2d!d"� Z3dS )#z! Tests for L{twisted.web.twcgi}. � N)�BytesIO)�address�error� interfaces�reactor)�ConnectionLost)�failure�log�util)�unittest)�client�http�http_headers�resource�server�twcgi)�INTERNAL_SERVER_ERROR� NOT_FOUND)�_render)�DummyChannel�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)) zkimport cgi fs = cgi.FieldStorage() param = fs.getvalue("param") print("Header: OK") print("") print(param) c @ s e Zd ZejZdS )�PythonScriptN)�__name__� __module__�__qualname__�sys� executable�filter� r r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/twisted/web/test/test_cgi.pyr c s r c @ s$ e Zd Zdd� Zdd� Zdd� ZdS )�_StartServerAndTearDownMixinc C sH t �� }t�t|�}|�dt|�� t�|�}t � d|�| _| j�� j S )Ns cgir )r �Resourcer Zsibpath�__file__ZputChildr r ZSiter Z listenTCP�pZgetHost�port)�self�cgi�rootZcgipath�siter r r �startServerh s z(_StartServerAndTearDownMixin.startServerc C s t | dd �r| j�� S d S )Nr# )�getattrr# � stopListening�r% r r r �tearDownp s z%_StartServerAndTearDownMixin.tearDownc C sH t j�| �� �}t|d��}|�|� W d � n1 s:0 Y |S )N�wt)�os�path�abspath�mktemp�open�write)r% �source�cgiFilename�cgiFiler r r �writeCGIt s (z%_StartServerAndTearDownMixin.writeCGIN)r r r r) r- r8 r r r r r g s r c @ s� e Zd ZdZej�e�sdZdd� Z dd� Z dd� Zd d � Zdd� Z d d� Zdd� Zdd� Zde_dd� Zdd� Zde_dd� Zdd� Zde_dd� Zdd� Zd S )!�CGITestsz, Tests for L{twcgi.FilteredScript}. z5CGI tests require a functional reactor.spawnProcess()c C sV | � t�}| �|�}d|f }|�d�}t�t��d|�}|�tj � |�| j � |S )N�http://localhost:%d/cgi�ascii� GET)r8 � DUMMY_CGIr) �encoder �Agentr �request�addCallback�readBody� _testCGI_1)r% r6 �portnum�url�dr r r �test_CGI� s zCGITests.test_CGIc C s | � |dtj�d� � d S )Ns cgi outputr; )�assertEqualr/ �linesepr>