HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/cherrypy/__pycache__/_cpmodpy.cpython-310.pyc
o

�N�g�+�@s�dZddlZddlZddlZddlZddlZddlmZddlZddl	m
Z
mZddlm
Z
dd�ZGdd	�d	�Zd
Zd
add�Zdd
d�Zz
ddlZdd�ZWn
ey]dd�ZYnwddd�ZGdd�de�ZdS)aVNative adapter for serving CherryPy via mod_python

Basic usage:

##########################################
# Application in a module called myapp.py
##########################################

import cherrypy

class Root:
    @cherrypy.expose
    def index(self):
        return 'Hi there, Ho there, Hey there'


# We will use this method from the mod_python configuration
# as the entry point to our application
def setup_server():
    cherrypy.tree.mount(Root())
    cherrypy.config.update({'environment': 'production',
                            'log.screen': False,
                            'show_tracebacks': False})

##########################################
# mod_python settings for apache2
# This should reside in your httpd.conf
# or a file that will be loaded at
# apache startup
##########################################

# Start
DocumentRoot "/"
Listen 8080
LoadModule python_module /usr/lib/apache2/modules/mod_python.so

<Location "/">
    PythonPath "sys.path+['/path/to/my/application']"
    SetHandler python-program
    PythonHandler cherrypy._cpmodpy::handler
    PythonOption cherrypy.setup myapp::setup_server
    PythonDebug On
</Location>
# End

The actual path to your mod_python.so is dependent on your
environment. In this case we suppose a global mod_python
installation on a Linux distribution such as Ubuntu.

We do set the PythonPath configuration setting so that
your application can be found by from the user running
the apache2 instance. Of course if your application
resides in the global site-package this won't be needed.

Then restart apache2 and access http://127.0.0.1:8080
�N)�always_iterable)�
format_exc�
bare_error)�httputilc
s@ddlm����}d|vrD|d��D]/}|�dd�}t|�dkr-t|dt�t��}q|\}}t|t�t�|g�}t||�}|�qt	j
�dddgd	��t	j�t
�d
�r\�j��t
�d�rf�j���j��t	j����d���fd
d��}����fdd�}	z��|	�WdSty��j��|	�YdSw)Nr��apachezcherrypy.setupz::�FTZRange)z
log.screenztools.ignore_headers.onztools.ignore_headers.headers�signal_handler�console_control_handler�logcsN�j}tj|kr�j}ntj|kr�j}ntj|kr�j}��||�j	�dS�N)
Z	APLOG_ERR�logging�DEBUGZAPLOG_DEBUG�INFOZ
APLOG_INFO�WARNINGZ
APLOG_WARNINGZ	log_error�server)�msg�level�newlevel)r�req��E/opt/saltstack/salt/lib/python3.10/site-packages/cherrypy/_cpmodpy.py�_loghs


zsetup.<locals>._logcs���dSr)�exit)�data)�enginerr�cherrypy_cleanupxszsetup.<locals>.cherrypy_cleanup)�
mod_pythonr�get_options�split�len�
__import__�globals�locals�getattr�cherrypyZconfig�updater�hasattrr	Zunsubscriber
Z
autoreloadrZ	subscribe�startZregister_cleanup�AttributeError)
r�options�functionZatoms�mod�modname�fname�funcrrr)rrrr�setupJs>
�






�r0c@seZdZdZdd�ZdS)�_ReadOnlyRequest)�read�readline�	readlinescCs |jD]
}t||�|j|<qdSr)�exposer$�__dict__)�selfr�methodrrr�__init__�s
�z_ReadOnlyRequest.__init__N)�__name__�
__module__�__qualname__r5r9rrrrr1�sr1FcCs
ddlm}�zXtst|�da|jj}t�|d|d|jjp!d�}|jj	}t�|d|d|jj
p4d�}|jdp<d}|��z|j
}||j�}||j�}WnGty�d}|��}	|	�dd���}|d	krld}n
|d
krsd}nt|d��|	�dd���}|d	kr�d}n
|d
kr�d}nt|d��Ynwtj�|jp�d
�}
|
dur�t|dgd�W|jAStjj|
}|j}|j}
|jp�d}|j}t|j� ��!��}t"|�}d}z�g}	|�#|||d�\}}|j$|_%t&|�|_'t&|�|_(||_)||_*z|�+||
||||�WnDtj,�yDt-�.�d}|�/�|}t0�s6|j1|v�r&t2d|j1��|�r-d|}|�3|
|
|�d}|j1}
|j4}t5�6�}Ynwq�t||j7|j8|j9|j:�W|�/�W|jAS|�/�wt;�y�t<�}tj=|dt>j?d�t@�\}}}t||||�Y|jASw)NrrTr��httpzfYou must provide a PythonOption '%s', either 'on' or 'off', when running a version of mod_python < 3.1�multithread�onZoffF�multiprocess�/z
404 Not FoundzHTTP/1.1z1InternalRedirector visited the same URL twice: %r�?ZGETZ
MOD_PYTHON)Zseverity)Brr�_isSetUpr0�
connectionZ
local_addrr�HostZ
local_hostZremote_addrZremote_hostZ
parsed_uriZget_basic_auth_pwZ	mpm_queryZAP_MPMQ_IS_THREADEDZAP_MPMQ_IS_FORKEDr)r�get�lower�
ValueErrorr%Ztree�script_nameZuri�
send_responseZappsr8�args�protocol�listZ
headers_in�copy�itemsr1Zget_serving�userZlogin�boolr?rA�app�prev�runZInternalRedirect�sys�exc_infoZrelease_serving�	recursive�path�RuntimeError�appendZquery_string�io�BytesIOZ
output_statusZheader_list�body�stream�	Exceptionrrr
�ERRORr�OK)rr�localZremote�scheme�qZthreadedZforkedZ	bad_valuer*ZsnrSr8rY�qsZreqproto�headersZrfilerTZredirections�request�responseZir�tb�s�h�brrr�handler�s���
��;�

�

����$
�

��rncCspt|dd��|_d|_|D]\}}|��dkr||_q|j�||�q|r*|��t|�D]}|�|�q.dS)N�z
text/plainzcontent-type)	�int�status�content_typerHZheaders_out�add�flushr�write)rrqrgr^r_�header�value�segrrrrK�s�rKcCstj|dtjtjdd�}|jS)NT)�shell�stdout�stderr�	close_fds)�
subprocess�Popen�PIPE�STDOUTrz)�fullcmd�prrr�popens
�r�cCst�|�\}}|Sr)�osZpopen4)r�Zpipein�pipeoutrrrr�sr=cCsbd||f}t|�}z!|��}t�d|tj�}|rtd|��||��}W|��|S|��w)Nz%s %ss'(not recognized|No such file|not found)z%s must be on your system path.)r�r3�re�search�
IGNORECASE�IOErrorr2�close)�cmdrLr�r��	firstlineZ
cmd_not_found�outputrrr�read_process!s�
�r�c@s.eZdZdZ		d
dd�Zd	d
�Zdd�ZdS)�ModPythonServera
# Apache2 server configuration file for running CherryPy with mod_python.

DocumentRoot "/"
Listen %(port)s
LoadModule python_module modules/mod_python.so

<Location %(loc)s>
    SetHandler python-program
    PythonHandler %(handler)s
    PythonDebug On
%(opts)s
</Location>
rB�PNr�cherrypy._cpmodpy::handlercCs"||_||_||_||_||_dSr)�loc�port�opts�apache_pathrn)r7r�r�r�r�rnrrrr9Ds

zModPythonServer.__init__cCs�d�dd�|jD��}|j|j|j||jd�}tj�tj�t	�d�}t
|d�}z|�|�W|��n|��wt
|jd|�}d|_|S)	Nr=cSsg|]
\}}d||f�qS)z    PythonOption %s %s
r)�.0�k�vrrr�
<listcomp>Ms�z)ModPythonServer.start.<locals>.<listcomp>)r�r�r�rnzcpmodpy.conf�wbz-k start -f %sT)�joinr��templater�r�rnr�rY�dirname�__file__�openrur�r�r��ready)r7r�Z	conf_dataZmpconf�frirrrr(Ls 
��
zModPythonServer.startcCst�d�d|_dS)Nzapache -k stopF)r�r�r�)r7rrr�stop`s

zModPythonServer.stop)rBr�Nrr�)r:r;r<r�r9r(r�rrrrr�3s
�r�)F)r=)�__doc__r\r
r�r�rVZmore_itertoolsrr%Zcherrypy._cperrorrrZcherrypy.librr0r1rXrDrnrKr}r��ImportErrorr��objectr�rrrr�<module>s097
o�