ó
    ?�‘h§  ã                   ód   • S SK Jr  S SKJr  S SKJr  SSKJr   " S S5      rS r	 " S	 S
\5      r
g)é    )Úurlparse)Úsettings)Úis_same_domainé   )ÚAsyncWebsocketConsumerc                   ó<   • \ rS rSrSrS rS rS rS rS r	S r
S	rg
)ÚOriginValidatoré	   zY
Validates that the incoming connection has an Origin header that
is in an allowed list.
c                 ó   • Xl         X l        g ©N)ÚapplicationÚallowed_origins)Úselfr   r   s      Ú_C:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\channels/security/websocket.pyÚ__init__ÚOriginValidator.__init__   s   € Ø&ÔØ.Õó    c              ƒ   ór  #   • US   S:w  a  [        S5      eS nUR                  S/ 5       H(  u  pVUS:X  d  M   [        UR                  S5      5      nM*     U R                  U5      (       a  U R                  XU5      I S h  v•N $ [        5       nU" XU5      I S h  v•N $ ! [         a     M„  f = f N0 N7f)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__ÚOriginValidator.__call__   sÅ   é € à�‰=˜KÓ'ÜØNóð ð ˆØ).¯©°9¸bÖ)AÑ%ˆKØ˜iÕ'ðä$,¨\×-@Ñ-@ÀÓ-JÓ$K’Mñ	 *Bð ×Ñ˜]×+Ñ+à×)Ñ)¨%¸$Ó?×?Ð?ô %Ó&ˆFÙ °Ó5×5Ð5øô *ó Úðúñ
 @ñ 6ùsF   ‚2B7¹B"Á/B7ÂB3ÂB7ÂB5ÂB7Â"
B0Â,B7Â/B0Â0B7Â5B7c                 óL   • Uc  SU R                   ;  a  gU R                  U5      $ )zœ
Checks parsed origin is None.

Pass control to the validate_origin function.

Returns ``True`` if validation function was successful, ``False`` otherwise.
Ú*F)r   Úvalidate_origin©r   r"   s     r   r   ÚOriginValidator.valid_origin+   s+   € ð Ñ  S°×0DÑ0DÓ%DØØ×#Ñ# MÓ2Ð2r   c                 óF   ^ ^• [        UU 4S jT R                   5       5      $ )av  
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   ó`   >#   • U  H#  nUS :H  =(       d    TR                  TU5      v •  M%     g7f)r)   N)Úmatch_allowed_origin)Ú.0Úpatternr"   r   s     €€r   Ú	<genexpr>Ú2OriginValidator.validate_origin.<locals>.<genexpr>I   s1   øé € ð 
â/�ð �s‰N×O˜d×7Ñ7¸ÀwÓOÔOÚ/ùs   ƒ+.)Úanyr   r+   s   ``r   r*   ÚOriginValidator.validate_origin8   s%   ù€ ô" õ 
à×/Ò/ó
ó 
ð 	
r   c                 ó¸  • Uc  g[        UR                  5       5      nUR                  c  gUR                  (       d7  [        SU-   5      R                  =(       d    Un[	        UR                  U5      $ U R                  U5      nU R                  U5      nUR                  UR                  :X  a+  XV:X  a&  [	        UR                  UR                  5      (       a  gg)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://example.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
Fz//T)r   ÚlowerÚhostnameÚschemer   Úget_origin_port)r   r"   r1   Úparsed_patternÚpattern_hostnameÚorigin_portÚpattern_ports          r   r/   Ú$OriginValidator.match_allowed_originN   sÀ   € ð  Ñ Øô " '§-¡-£/Ó2ˆØ×!Ñ!Ñ)ØØ×$×$Ü'¨¨w©Ó7×@Ñ@×KÀGÐÜ! -×"8Ñ"8Ð:JÓKÐKà×*Ñ*¨=Ó9ˆà×+Ñ+¨NÓ;ˆð ×!Ñ! ]×%9Ñ%9Ó9ØÓ+Ü˜}×5Ñ5°~×7NÑ7N×OÑOàØr   c                 óº   • UR                   b  UR                   $ UR                  S:X  d  UR                  S:X  a  gUR                  S:X  d  UR                  S:X  a  gg)zY
Returns the origin.port or port for this schema by default.
Otherwise, it returns None.
NÚhttpÚwséP   ÚhttpsÚwssi»  )Úportr9   )r   Úorigins     r   r:   ÚOriginValidator.get_origin_portu   sO   € ð
 �;‰;Ñ"à—;‘;Ðà�=‰=˜FÓ" f§m¡m°tÓ&;àØ�]‰]˜gÓ%¨¯©¸%Ó)?ààr   )r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r&   r   r*   r/   r:   Ú__static_attributes__© r   r   r	   r	   	   s&   † ñò
/ò6ò03ò
ò,%õNr   r	   c                 óx   • [         R                  n[         R                  (       a  U(       d  / SQn[        X5      $ )z]
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   ÚAllowedHostsOriginValidatorrU   ˆ   s(   € ô
 ×*Ñ*€MÜ‡~‡~žmÚ;ˆÜ˜;Ó6Ð6r   c                   ó   • \ rS rSrSrS rSrg)r   é“   z5
Simple application which denies all requests to it.
c              ƒ   ó@   #   • U R                  5       I S h  v•N   g  N7fr   )Úclose)r   s    r   ÚconnectÚWebsocketDenier.connect˜   s   é € Ø�j‰j‹l×Óùs   ‚–—rO   N)rI   rJ   rK   rL   rM   rZ   rN   rO   r   r   r   r   “   s   † ñõr   r   N)Úurllib.parser   Údjango.confr   Údjango.http.requestr   Úgeneric.websocketr   r	   rU   r   rO   r   r   Ú<module>r`      s0   ðÝ !å  Ý .å 6÷|ñ |ò~7ôÐ,õ r   