
    h                     b    d dl Z d dlZd dlmZ  ej                  d      Zd Zd Z	 	 	 	 	 ddZy)    N)Headerss   [-!#$%&'*+.^_`|~0-9a-zA-Z]+c                     | j                  dd      \  }}t        j                  |      }|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        H/var/www/Befach/backend/env/lib/python3.12/site-packages/daphne/utils.pyimport_by_pathr      sO    
  $zz#q1K$$[1F  %% &M    c                 X    | |   }t        |t              r|d   }|j                  d      S )Nr   utf-8)
isinstancelistdecode)headersheader_namevalues      r   header_valuer      s.    K E%a<<  r   c                    |s||fS t        | t              rt        | j                               } | j	                         D ci c]  \  }}|j                         | } }}t        d | j                         D              sJ |j                         j                  d      }|}|}	|| v rt        | |      }
d|
v r"|
j                  d      d   j                         }
|
dg}|r>|j                         j                  d      }|| v rt        | |      }	 t        |      |d<   |r/|j                         j                  d      }|| v rt        | |      }	||	fS c c}}w # t        $ r Y Fw xY w)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              3   <   K   | ]  }t        |t                y w)N)r   bytes).0names     r   	<genexpr>z(parse_x_forwarded_for.<locals>.<genexpr><   s     B4z$&Bs   r   ,r   r   )r   r   dictgetAllRawHeadersitemslowerallkeysencoder   r   stripint
ValueError)r   address_header_nameport_header_nameproto_header_nameoriginal_addroriginal_schemer!   valuesresult_addrresult_schemeaddress_value
port_values               r   parse_x_forwarded_forr8      s   & o-- '7#w//12 9@Hftzz|V#HGH B7<<>BBBB-335<<WEK#Mg%$W.AB-)//4Q7==?M$a(  0557>>wG7*)'3CD
%(_KN  1 7 7 9 @ @ I G+ ,W6G H%%A I0 " s   EE 	E'&E')zX-Forwarded-ForzX-Forwarded-PortzX-Forwarded-ProtoNN)	r	   retwisted.web.http_headersr   compileHEADER_NAME_REr   r   r8    r   r   <module>r>      sA     	 , ;<	! *');&r   