§
    §Mºf¨  ã                   ór   — d dl mZ d dlmZ d dlmZ ddlmZ  G d„ d¦  «        Zd„ Z	 G d	„ d
e¦  «        Z
dS )é    )Úurlparse)Úsettings)Úis_same_domainé   )ÚAsyncWebsocketConsumerc                   ó6   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	dS )	ÚOriginValidatorze
    Validates that the incoming connection has an Origin header that
    is in an allowed list.
    c                 ó"   — || _         || _        d S ©N)ÚapplicationÚallowed_origins)Úselfr   r   s      úZ/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/channels/security/websocket.pyÚ__init__zOriginValidator.__init__   s   € Ø&ˆÔØ.ˆÔÐÐó    c              ƒ   ó’  K  — |d         dk    rt          d¦  «        ‚d }|                     dg ¦  «        D ]?\  }}|dk    r4	 t          |                     d¦  «        ¦  «        }Œ/# t          $ r Y Œ;w xY wŒ@|                      |¦  «        r|                      |||¦  «        ƒ d {V —†S t          ¦   «         } ||||¦  «        ƒ d {V —†S )NÚtypeÚ	websocketz<You cannot use OriginValidator on a non-WebSocket connectionÚheaderss   originÚlatin1)Ú
ValueErrorÚgetr   ÚdecodeÚUnicodeDecodeErrorÚvalid_originr   ÚWebsocketDenier)r   ÚscopeÚreceiveÚsendÚparsed_originÚheader_nameÚheader_valueÚdeniers           r   Ú__call__zOriginValidator.__call__   s  è è € à�Œ=˜KÒ'Ð'ÝØNñô ð ð ˆØ).¯ª°9¸bÑ)AÔ)Að 	ð 	Ñ%ˆK˜Ø˜iÒ'Ð'ðå$,¨\×-@Ò-@ÀÑ-JÔ-JÑ$KÔ$K�M�MøÝ)ð ð ð Ø�Dðøøøð	 (ð ×Ò˜]Ñ+Ô+ð 	6à×)Ò)¨%°¸$Ñ?Ô?Ð?Ð?Ð?Ð?Ð?Ð?Ð?õ %Ñ&Ô&ˆFØ˜  w°Ñ5Ô5Ð5Ð5Ð5Ð5Ð5Ð5Ð5s   Á"A%Á%
A2Á1A2c                 óF   — |€d| j         vrdS |                      |¦  «        S )z¼
        Checks parsed origin is None.

        Pass control to the validate_origin function.

        Returns ``True`` if validation function was successful, ``False`` otherwise.
        NÚ*F)r   Úvalidate_origin©r   r    s     r   r   zOriginValidator.valid_origin+   s0   € ð Ð  S°Ô0DÐ%DÐ%DØ�5Ø×#Ò# MÑ2Ô2Ð2r   c                 óH   ‡ ‡— t          ˆˆ fd„‰ j        D ¦   «         ¦  «        S )aÖ  
        Validate the given origin for this site.

        Check than the origin looks valid and matches the origin pattern in
        specified list ``allowed_origins``. Any pattern begins with a scheme.
        After the scheme there must be a domain. Any domain beginning with a
        period corresponds to the domain and all its subdomains (for example,
        ``http://.example.com``). After the domain there must be a port,
        but it can be omitted. ``*`` matches anything and anything
        else must match exactly.

        Note. This function assumes that the given origin has a schema, domain
        and port, but port is optional.

        Returns ``True`` for a valid host, ``False`` otherwise.
        c              3   óP   •K  — | ] }|d k    p‰                      ‰|¦  «        V — Œ!dS )r&   N)Úmatch_allowed_origin)Ú.0Úpatternr    r   s     €€r   ú	<genexpr>z2OriginValidator.validate_origin.<locals>.<genexpr>I   sP   øè è € ð 
ð 
àð �sŠNÐO˜d×7Ò7¸ÀwÑOÔOð
ð 
ð 
ð 
ð 
ð 
r   )Úanyr   r(   s   ``r   r'   zOriginValidator.validate_origin8   sF   øø€ õ" ð 
ð 
ð 
ð 
ð 
àÔ/ð
ñ 
ô 
ñ 
ô 
ð 	
r   c                 ó„  — |€dS t          |                     ¦   «         ¦  «        }|j        €dS |j        s.t          d|z   ¦  «        j        p|}t	          |j        |¦  «        S |                      |¦  «        }|                      |¦  «        }|j        |j        k    r"||k    rt	          |j        |j        ¦  «        rdS dS )aü  
        Returns ``True`` if the origin is either an exact match or a match
        to the wildcard pattern. Compares scheme, domain, port of origin and pattern.

        Any pattern can be begins with a scheme. After the scheme must be a domain,
        or just domain without scheme.
        Any domain beginning with a period corresponds to the domain and all
        its subdomains (for example, ``.example.com`` ``example.com``
        and any subdomain). Also with scheme (for example, ``http://.example.com``
        ``http://exapmple.com``). After the domain there must be a port,
        but it can be omitted.

        Note. This function assumes that the given origin is either None, a
        schema-domain-port string, or just a domain string
        NFz//T)r   ÚlowerÚhostnameÚschemer   Úget_origin_port)r   r    r-   Úparsed_patternÚpattern_hostnameÚorigin_portÚpattern_ports          r   r+   z$OriginValidator.match_allowed_originN   sÖ   € ð  Ð Ø�5õ " '§-¢-¡/¤/Ñ2Ô2ˆØÔ!Ð)Ø�5ØÔ$ð 	LÝ'¨¨w©Ñ7Ô7Ô@ÐKÀGÐÝ! -Ô"8Ð:JÑKÔKÐKà×*Ò*¨=Ñ9Ô9ˆà×+Ò+¨NÑ;Ô;ˆð Ô! ]Ô%9Ò9Ð9Ø˜|Ò+Ð+Ý˜}Ô5°~Ô7NÑOÔOð ,ð �4Øˆur   c                 ó‚   — |j         �|j         S |j        dk    s|j        dk    rdS |j        dk    s|j        dk    rdS dS )zq
        Returns the origin.port or port for this schema by default.
        Otherwise, it returns None.
        NÚhttpÚwséP   ÚhttpsÚwssi»  )Úportr3   )r   Úorigins     r   r4   zOriginValidator.get_origin_portu   sU   € ð
 Œ;Ð"à”;ÐàŒ=˜FÒ"Ð" f¤m°tÒ&;Ð&;à�2ØŒ]˜gÒ%Ð%¨¬¸%Ò)?Ð)?à�3à�4r   N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r$   r   r'   r+   r4   © r   r   r	   r	   	   sy   € € € € € ðð ð
/ð /ð /ð6ð 6ð 6ð03ð 3ð 3ð
ð 
ð 
ð,%ð %ð %ðNð ð ð ð r   r	   c                 ó^   — t           j        }t           j        r|sg d¢}t          | |¦  «        S )zi
    Factory function which returns an OriginValidator configured to use
    settings.ALLOWED_HOSTS.
    )Ú	localhostz	127.0.0.1z[::1])r   ÚALLOWED_HOSTSÚDEBUGr	   )r   Úallowed_hostss     r   ÚAllowedHostsOriginValidatorrK   ˆ   s8   € õ
 Ô*€MÝ„~ð <˜mð <Ø;Ð;Ð;ˆÝ˜;¨Ñ6Ô6Ð6r   c                   ó   — e Zd ZdZd„ ZdS )r   z=
    Simple application which denies all requests to it.
    c              ƒ   ó>   K  — |                       ¦   «         ƒ d {V —† d S r   )Úclose)r   s    r   ÚconnectzWebsocketDenier.connect˜   s,   è è € Ø�jŠj‰lŒlÐÐÐÐÐÐÐÐÐr   N)rA   rB   rC   rD   rO   rE   r   r   r   r   “   s-   € € € € € ðð ðð ð ð ð r   r   N)Úurllib.parser   Údjango.confr   Údjango.http.requestr   Úgeneric.websocketr   r	   rK   r   rE   r   r   ú<module>rT      sÂ   ðØ !Ð !Ð !Ð !Ð !Ð !à  Ð  Ð  Ð  Ð  Ð  Ø .Ð .Ð .Ð .Ð .Ð .à 6Ð 6Ð 6Ð 6Ð 6Ð 6ð|ð |ð |ð |ð |ñ |ô |ð |ð~7ð 7ð 7ðð ð ð ð Ð,ñ ô ð ð ð r   