
    z
g%                     8    d dl Z d dlmZ d Zd Z	 	 	 	 	 d	dZdS )
    N)Headersc                     |                      dd          \  }}t          j        |          }|                     d          D ]}t          ||          }|S )z{
    Given a dotted/colon path, like project.module:ClassName.callable,
    returns the object at the end of the path.
    :   .)split	importlibimport_modulegetattr)pathmodule_pathobject_pathtargetbits        >/var/www/html/env/lib/python3.11/site-packages/daphne/utils.pyimport_by_pathr      s_    
  $zz#q11K$[11F  %% & &%%M    c                 v    | |         }t          |t                    r|d         }|                    d          S )Nr   utf-8)
isinstancelistdecode)headersheader_namevalues      r   header_valuer      s9    K E% a<<   r   X-Forwarded-ForX-Forwarded-PortX-Forwarded-Protoc                 <   |s||fS t          | t                    r!t          |                                           } d |                                 D             } t          d |                                 D                       sJ |                                                    d          }|}|}|| v rt          | |          }d|v r-|
                    d          d                                         }|dg}|r_|                                                    d          }|| v r4t          | |          }		 t          |	          |d<   n# t          $ r Y nw xY w|r;|                                                    d          }|| v rt          | |          }||fS )a  
    Parses an X-Forwarded-For header and returns a host/port pair as a list.

    @param headers: The twisted-style object containing a request's headers
    @param address_header_name: The name of the expected host header
    @param port_header_name: The name of the expected port header
    @param proto_header_name: The name of the expected proto header
    @param original_addr: A host/port pair that should be returned if the headers are not in the request
    @param original_scheme: A scheme that should be returned if the headers are not in the request
    @return: A list containing a host (string) as the first entry and a port (int) as the second.
    c                 >    i | ]\  }}|                                 |S  )lower).0namevaluess      r   
<dictcomp>z)parse_x_forwarded_for.<locals>.<dictcomp>4   s&    HHHftzz||VHHHr   c              3   @   K   | ]}t          |t                    V  d S )N)r   bytes)r$   r%   s     r   	<genexpr>z(parse_x_forwarded_for.<locals>.<genexpr>7   s,      BB4z$&&BBBBBBr   r   ,r   r   )r   r   dictgetAllRawHeadersitemsallkeysr#   encoder   r   stripint
ValueError)
r   address_header_nameport_header_nameproto_header_nameoriginal_addroriginal_schemeresult_addrresult_schemeaddress_value
port_values
             r   parse_x_forwarded_forr>      s   &  .o-- '7## 3w//1122 IHHHHG BB7<<>>BBBBBBBB-3355<<WEEK#Mg%%$W.ABB-)//44Q7==??M$a( 		  05577>>wGG7**)'3CDD
%(__KNN!   D  	I 1 7 7 9 9 @ @ I I G++ ,W6G H H%%s   :E 
EE)r   r   r   NN)r	   twisted.web.http_headersr   r   r   r>   r"   r   r   <module>r@      sp        , , , , , ,	 	 	! ! ! *');& ;& ;& ;& ;& ;&r   