
    >Tf                     f    d dl mZ d dlmZmZ d dlmZ ddlm	Z	 dZ
 G d d          Zd	 ZddZdS )    )gettext_lazy)AddrFormatError	IPAddress)urlparse   )HTTP_REQUEST_META_SAFE_COPY)NetBoxFakeRequestcopy_safe_requestget_client_ipc                       e Zd ZdZd ZdS )r	   z
    A fake request object which is explicitly defined at the module level so it is able to be pickled. It simply
    takes what is passed to it as kwargs on init and sets them as instance variables.
    c                     || _         d S )N)__dict__)self_dicts     6/var/www/html/netbox-4.1.3/netbox/utilities/request.py__init__zNetBoxFakeRequest.__init__   s        N)__name__
__module____qualname____doc__r    r   r   r	   r	      s-             r   r	   c                       fdt           D             }t          | j         j         j         j         j         j        t           dd          d          S )z
    Copy selected attributes from a request object into a new fake request object. This is needed in places where
    thread safe pickling of the useful request data is needed.
    c                 ~    i | ]9}|j         v t          j         |         t                    +|j         |         :S r   )META
isinstancestr).0krequests     r   
<dictcomp>z%copy_safe_request.<locals>.<dictcomp>$   sM       GLOS!A!A 	
7<?r   idN)r   COOKIESPOSTGETFILESuserpathr"   )	r   r	   r#   r$   r%   r&   r'   r(   getattr)r    metas   ` r   r
   r
      sy    
   ,  D
 ?{gtT**	 	 	 	 	r   r   c                    dddg|R }|D ]}|| j         v r| j         |                             d          d                                         }	 t          |          c S # t          $ r t          d|           j        }Y nw xY w	 t          |          c S # t          $ r2 t          t          d          	                    ||                    w xY wd	S )
zE
    Return the client (source) IP address of the given request.
    HTTP_X_REAL_IPHTTP_X_FORWARDED_FORREMOTE_ADDR,r   z//z)Invalid IP address set for {header}: {ip})headeripN)
r   splitstripr   r   r   hostname
ValueError_format)r    additional_headersHTTP_HEADERSr0   r1   s        r   r   r   5   s)   
 	 
	 L  n nW\!!f%++C00399;;B2 }}$$$" 2 2 2i2ii((12n }}$$$" n n n #N!O!O!V!V^dik!V!l!lmmmn " 4s   A  !BBB<CN)r   )django.utils.translationr   r6   netaddrr   r   urllib.parser   	constantsr   __all__r	   r
   r   r   r   r   <module>r?      s    6 6 6 6 6 6 . . . . . . . . ! ! ! ! ! ! 2 2 2 2 2 2         ,     r   