o
    >h                     @   sN   d dl Z d dlZd dlmZ edZdd Zdd Z				
		dddZdS )    N)Headerss   [-!#$%&'*+.^_`|~0-9a-zA-Z]+c                 C   s8   |  dd\}}t|}| dD ]}t||}q|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bit r   l/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/daphne/utils.pyimport_by_path   s
   
r   c                 C   s$   | | }t |tr|d }|dS )Nr   utf-8)
isinstancelistdecode)headersheader_namevaluer   r   r   header_value   s   

r   X-Forwarded-ForX-Forwarded-PortX-Forwarded-Protoc           
      C   s  |s||fS t | trt|  } dd |  D } tdd |  D s'J | d}|}|}|| v rt	| |}d|v rH|
dd  }|dg}|rp| d}|| v rpt	| |}	zt|	|d< W n	 tyo   Y nw |r| d}|| v rt	| |}||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                 S   s   i | ]	\}}|  |qS r   )lower).0namevaluesr   r   r   
<dictcomp>9   s    z)parse_x_forwarded_for.<locals>.<dictcomp>c                 s   s    | ]}t |tV  qd S )N)r   bytes)r   r   r   r   r   	<genexpr><   s    z(parse_x_forwarded_for.<locals>.<genexpr>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_valuer   r   r   parse_x_forwarded_for   s8   



r7   )r   r   r   NN)	r   retwisted.web.http_headersr   compileHEADER_NAME_REr   r   r7   r   r   r   r   <module>   s    
	