§
    ÎÑßj+  ã                   ó~   — d Z ddlZddlZddlmZmZmZmZmZ ddlm	Z	m
Z
  G d„ de¦  «        Z G d„ de¦  «        ZdS )	z&CherryPy Application and Tree objects.é    N)Ú	_cpconfigÚ
_cploggingÚ
_cprequestÚ_cpwsgiÚtools)ÚhttputilÚreprconfc                   óâ   — e Zd ZdZdZ	 i Z	  ej        ¦   «         Zde	j
        iZdZ	 dZ	 ej        Zej        ZdZdd„Zd„ ZdZed	„ ¦   «         Zej        d
„ ¦   «         Zd„ Zdd„Zd„ Zd„ Zd„ ZdS )ÚApplicationa!  A CherryPy Application.

    Servers and gateways should not instantiate Request objects
    directly. Instead, they should ask an Application object for a
    request object.

    An instance of this class may also be used as a WSGI callable (WSGI
    application object) for itself.
    Nr   FÚ c                 ó¸  ‡ — t          j        t          ‰ ¦  «        t          j        j        ¦  «        ‰ _        |‰ _        |‰ _        t          j	        ‰ ¦  «        ‰ _
        ‰ j                             ¦   «         ‰ _        ˆ fd„‰ j        d<   ‰ j
        j        ‰ j        d<   ‰ j        j                             ¦   «         ‰ _        |r‰                      |¦  «         dS dS )z'Initialize Application with given root.c                 ó0   •— t          ‰j        | |¦  «        S ©N)ÚsetattrÚlog)ÚkÚvÚselfs     €úD/opt/saltstack/salt/lib/python3.11/site-packages/cherrypy/_cptree.pyú<lambda>z&Application.__init__.<locals>.<lambda>>   s   ø€ ­g°d´hÀÀ1Ñ.EÔ.E€ ó    r   ÚwsgiN)r   Ú
LogManagerÚidÚcherrypyr   Úlogger_rootÚrootÚscript_namer   Ú	CPWSGIAppÚwsgiappÚ
namespacesÚcopyÚnamespace_handlerÚ	__class__ÚconfigÚmerge)r   r   r   r%   s   `   r   Ú__init__zApplication.__init__6   sÀ   ø€ åÔ(­¨D©¬µ8´<Ô3KÑLÔLˆŒØˆŒ	Ø&ˆÔÝÔ(¨Ñ.Ô.ˆŒàœ/×.Ò.Ñ0Ô0ˆŒØ!EÐ!EÐ!EÐ!EˆŒ˜ÑØ"&¤,Ô"@ˆŒ˜Ñà”nÔ+×0Ò0Ñ2Ô2ˆŒØð 	Ø�JŠJ�vÑÔÐÐÐð	ð 	r   c                 óP   — | j         ›d| j        j        ›d| j        ›d| j        ›d�S )z6Generate a representation of the Application instance.ú.ú(z, ú))Ú
__module__r$   Ú__name__r   r   ©r   s    r   Ú__repr__zApplication.__repr__E   s6   € à"&¤/ / /°4´>Ô3JÐ3JÐ3JØ"&¤) ) )¨TÔ-=Ð-=Ð-=ð?ð 	?r   aÅ  The URI "mount point" for this app. A mount point
    is that portion of the URI which is constant for all URIs that are
    serviced by this application; it does not include scheme, host, or proxy
    ("virtual host") portions of the URI.

    For example, if script_name is "/my/cool/app", then the URL
    "http://www.example.com/my/cool/app/page1" might be handled by a
    "page1" method on the root object.

    The value of script_name MUST NOT end in a slash. If the script_name
    refers to the root of the URI, it MUST be an empty string (not "/").

    If script_name is explicitly set to None, then the script_name will be
    provided for each call from request.wsgi_environ['SCRIPT_NAME'].
    c                 ó|   — | j         �| j         S t          j        j        j        d                              d¦  «        S )a  The URI "mount point" for this app.

        A mount point is that portion of the URI which is constant for
        all URIs that are serviced by this application; it does not
        include scheme, host, or proxy ("virtual host") portions of the
        URI.

        For example, if script_name is "/my/cool/app", then the URL "

        http://www.example.com/my/cool/app/page1"
        might be handled by a
        "page1" method on the root object.

        The value of script_name MUST NOT end in a slash. If the script_name
        refers to the root of the URI, it MUST be an empty string (not "/").

        If script_name is explicitly set to None, then the script_name will be
        provided for each call from request.wsgi_environ['SCRIPT_NAME'].
        NÚSCRIPT_NAMEú/)Ú_script_namer   ÚservingÚrequestÚwsgi_environÚrstripr.   s    r   r   zApplication.script_nameZ   s:   € ð* ÔÐ(ØÔ$Ð$õ ÔÔ'Ô4°]ÔC×JÒJÈ3ÑOÔOÐOr   c                 óB   — |r|                      d¦  «        }|| _        d S )Nr2   )r7   r3   )r   Úvalues     r   r   zApplication.script_namev   s)   € àð 	&Ø—L’L Ñ%Ô%ˆEØ!ˆÔÐÐr   c                 ó–   — t          j        | j        |¦  «         |                      | j                             di ¦  «        ¦  «         dS )z(Merge the given config into self.config.r2   N)r   r&   r%   r!   Úget)r   r%   s     r   r&   zApplication.merge|   s@   € åŒ˜œ VÑ,Ô,Ð,ð 	�Š˜œŸš¨¨RÑ0Ô0Ñ1Ô1Ð1Ð1Ð1r   c                 óÎ   — |pd}|r^| j                              |i ¦  «        }||v r||         S |                     d¦  «        }|dk    rn|dk    r	|dk    rd}n
|d|…         }|°^|S )z>Return the most-specific value for key along path, or default.r2   éÿÿÿÿr   N)r%   r;   Úrfind)r   ÚpathÚkeyÚdefaultÚtrailÚnodeconfÚ	lastslashs          r   Úfind_configzApplication.find_configƒ   s�   € à�˜ˆØð 	*Ø”{—’ u¨bÑ1Ô1ˆHà�hˆˆØ ”}Ð$àŸš CÑ(Ô(ˆIØ˜BŠˆØØ˜a’� E¨S¢L LØ��à˜j˜y˜jÔ)�ð ð 	*ð ˆr   c                 ó~  — |                       ||||¦  «        }| |_        | j                             ¦   «         D ]\  }}||j        |<   Œ|                      ¦   «         }t          j                             ||¦  «         t          j	         
                    d¦  «         t          j	         
                    d¦  «         ||fS )z0Create and return a Request and Response object.Úacquire_threadÚbefore_request)Úrequest_classÚappÚ	toolboxesÚitemsr!   Úresponse_classr   r4   ÚloadÚengineÚpublish)	r   ÚlocalÚremoteÚschemeÚsprotoÚreqÚnameÚtoolboxÚresps	            r   Úget_servingzApplication.get_serving–   s´   € à× Ò  ¨°¸Ñ?Ô?ˆØˆŒà!œ^×1Ò1Ñ3Ô3ð 	+ð 	+‰MˆD�'Ø#*ˆCŒN˜4Ñ Ð à×"Ò"Ñ$Ô$ˆÝÔ×Ò˜c 4Ñ(Ô(Ð(ÝŒ×ÒÐ 0Ñ1Ô1Ð1ÝŒ×ÒÐ 0Ñ1Ô1Ð1à�DˆyÐr   c                 ó  — t           j        j        }t           j                             d¦  «         	 |                     ¦   «          n&# t          $ r t          j        dd¬¦  «         Y nw xY wt           j                             ¦   «          dS )z3Release the current serving (request and response).Úafter_requestTé(   )Ú	tracebackÚseverityN)	r   r4   r5   rO   rP   ÚcloseÚ	Exceptionr   Úclear)r   rU   s     r   Úrelease_servingzApplication.release_serving¥   sŠ   € åÔÔ&ˆåŒ×Ò Ñ0Ô0Ð0ð	6Ø�IŠI‰KŒKˆKˆKøÝð 	6ð 	6ð 	6ÝŒL 4°"Ð5Ñ5Ô5Ð5Ð5Ð5ð	6øøøõ 	Ô×ÒÑ Ô Ð Ð Ð s   ²A Á A*Á)A*c                 ó.   — |                       ||¦  «        S )zCall a WSGI-callable.)r    )r   ÚenvironÚstart_responses      r   Ú__call__zApplication.__call__²   s   € à�|Š|˜G ^Ñ4Ô4Ð4r   ©r   Nr   )r-   r,   Ú__qualname__Ú__doc__r   r%   r	   ÚNamespaceSetr!   r   r   rK   r   r    r   ÚRequestrI   ÚResponserM   Úrelative_urlsr'   r/   Úscript_name_docÚpropertyr   Úsetterr&   rE   rY   rb   rf   © r   r   r   r   
   s8  € € € € € ðð ð €Dðð €Fðð '�Ô&Ñ(Ô(€JØ˜(œ.Ð)€Ià
€Cðð
 €Gðð
 Ô&€MØÔ(€Nà€Mðð ð ð ð?ð ?ð ?ð
€Oð  ðPð Pñ „XðPð6 Ôð"ð "ñ Ôð"ð
2ð 2ð 2ðð ð ð ð&ð ð ð!ð !ð !ð5ð 5ð 5ð 5ð 5r   r   c                   ó<   — e Zd ZdZi Z	 d„ Zd	d„Zd
d„Zdd„Zd„ Z	dS )ÚTreezÛA registry of CherryPy applications, mounted at diverse points.

    An instance of this class may also be used as a WSGI callable (WSGI
    application object), in which case it dispatches to all mounted
    apps.
    c                 ó   — i | _         dS )zInitialize registry Tree.N)Úappsr.   s    r   r'   zTree.__init__Æ   s   € àˆŒ	ˆ	ˆ	r   r   Nc                 ó\  — |€t          d¦  «        ‚|                     d¦  «        }t          |t          ¦  «        r*|}|dk    r||j        k    rt          d¦  «        ‚|j        }n¥t          ||¦  «        }|dk    o|duot          |d¦  «         }|rxt          j         	                    t          j
        ¦   «         t          j                             t          ¦  «        d¦  «        }t          j                             |¦  «        |_        |r|                     |¦  «         || j        |<   |S )a·  Mount a new app from a root object, script_name, and config.

        root
            An instance of a "controller class" (a collection of page
            handler methods) which represents the root of the application.
            This may also be an Application instance, or None if using
            a dispatcher other than the default.

        script_name
            A string containing the "mount point" of the application.
            This should start with a slash, and be the path portion of the
            URL at which to mount the given root. For example, if root.index()
            will handle requests to "http://www.example.com:8080/dept/app1/",
            then the script_name argument would be "/dept/app1".

            It MUST NOT end in a slash. If the script_name refers to the
            root of the URI, it MUST be an empty string (not "/").

        config
            A file or dict containing application config.
        Na  The 'script_name' argument may not be None. Application objects may, however, possess a script_name of None (in order to inpect the WSGI environ for SCRIPT_NAME upon each request). You cannot mount such Applications on this Tree; you must pass them to a WSGI server interface directly.r2   r   zYCannot specify a different script name and pass an Application instance to cherrypy.mountÚfavicon_icozfavicon.ico)Ú	TypeErrorr7   Ú
isinstancer   r   Ú
ValueErrorÚhasattrÚosr?   ÚjoinÚgetcwdÚdirnameÚ__file__r   Ú
staticfileÚhandlerrw   r&   ru   )r   r   r   r%   rJ   Úneeds_faviconÚfavicons          r   Úmountz
Tree.mountÊ   sN  € ð, ÐÝðJñKô Kð Kð "×(Ò(¨Ñ-Ô-ˆå�d�KÑ(Ô(ð 	EØˆCØ˜bÒ Ð  [°C´OÒ%CÐ%CÝ ð=ñ>ô >ð >ð œ/ˆKˆKå˜d KÑ0Ô0ˆCð ˜rÒ!ð 5Ø Ð$ð5å  mÑ4Ô4Ð4ð ð
 ð EÝœ'Ÿ,š,Ý”I‘K”KÝ”G—O’O¥HÑ-Ô-Ø!ñô �õ
 $)Ô#3×#;Ò#;¸GÑ#DÔ#D�Ô àð 	Ø�IŠI�fÑÔÐà!$ˆŒ	�+Ñàˆ
r   c                 óD   — |                      d¦  «        }|| j        |<   dS )z/Mount a wsgi callable at the given script_name.r2   N)r7   ru   )r   Úwsgi_callabler   s      r   Úgraftz
Tree.graft
  s)   € ð "×(Ò(¨Ñ-Ô-ˆØ!.ˆŒ	�+ÑÐÐr   c                 óð   — |€C	 t           j        j        }t          j        |j        |j        ¦  «        }n# t          $ r Y dS w xY w	 || j        v r|S |dk    rdS |d| 	                    d¦  «        …         }Œ1)zzReturn the script_name of the app at the given path, or None.

        If path is None, cherrypy.request is used.
        NTr   r2   )
r   r4   r5   r   Úurljoinr   Ú	path_infoÚAttributeErrorru   r>   )r   r?   r5   s      r   r   zTree.script_name  s    € ð
 ˆ<ðÝ"Ô*Ô2�ÝÔ'¨Ô(;Ø(/Ô(9ñ;ô ;��øå!ð ð ð Ø�t�tðøøøð	*Ø�t”yÐ Ð Ø�à�rŠzˆzØ�tð Ð(˜Ÿš C™œÐ(Ô)ˆDð	*s   „05 µ
AÁAc                 óŒ  — |}t          j        |                     dd¦  «        |                     dd¦  «        ¦  «        }|                      |pd¦  «        }|€ |dg ¦  «         g S | j        |         }|                     ¦   «         }||d<   |t          |                     d¦  «        ¦  «        d…         |d<    |||¦  «        S )z/Pre-initialize WSGI env and call WSGI-callable.r1   r   Ú	PATH_INFOr2   Nz404 Not Found)r   rŠ   r;   r   ru   r"   Úlenr7   )r   rd   re   Úenv1xr?   ÚsnrJ   s          r   rf   zTree.__call__'  sÌ   € ð
 ˆÝÔ §	¢	¨-¸Ñ <Ô <Ø %§	¢	¨+°rÑ :Ô :ñ<ô <ˆà×Ò˜d˜k cÑ*Ô*ˆØˆ:ØˆN˜?¨BÑ/Ô/Ð/ØˆIàŒi˜Œmˆð —,’,‘.”.ˆØ!#ˆ�ÑØ#¥C¨¯	ª	°#©¬Ñ$7Ô$7Ð$8Ð$8Ô9ˆ�ÑØˆs�7˜NÑ+Ô+Ð+r   rg   )r   r   )
r-   r,   rh   ri   ru   r'   r…   rˆ   r   rf   rq   r   r   rs   rs   ·   s…   € € € € € ðð ð €Dð?ðð ð ð>ð >ð >ð >ð@/ð /ð /ð /ð*ð *ð *ð *ð.,ð ,ð ,ð ,ð ,r   rs   )ri   r|   r   r   r   r   r   r   Úcherrypy.libr   r	   Úobjectr   rs   rq   r   r   ú<module>r”      sÐ   ðØ ,Ð ,à 	€	€	€	à €€€Ø FÐ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FØ +Ð +Ð +Ð +Ð +Ð +Ð +Ð +ðj5ð j5ð j5ð j5ð j5�&ñ j5ô j5ð j5ðZC,ð C,ð C,ð C,ð C,ˆ6ñ C,ô C,ð C,ð C,ð C,r   