Ë
    üûàgM3  ã                   óÖ   — d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ ddlmZmZ  G d	„ d
«      Z G d„ d«      Z G d„ de«      Zefd„Z e«       Zy)é    N)Údeepcopy)Úsettings)Úsetting_changed)Úimport_string)ÚDEFAULT_CHANNEL_LAYERé   )ÚChannelFullÚInvalidChannelLayerErrorc                   óP   — e Zd ZdZd„ Zd„ Zed„ «       Zd„ Zd„ Z	d„ Z
d„ Zd	„ Zd
„ Zy)ÚChannelLayerManagerzR
    Takes a settings dictionary of backends and initialises them on request.
    c                 óP   — i | _         t        j                  | j                  «       y ©N)Úbackendsr   ÚconnectÚ_reset_backends©Úselfs    úM/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/channels/layers.pyÚ__init__zChannelLayerManager.__init__   s   € ØˆŒÜ×Ñ × 4Ñ 4Õ5ó    c                 ó   — |dk(  ri | _         yy)zX
        Removes cached channel layers when the CHANNEL_LAYERS setting changes.
        ÚCHANNEL_LAYERSN)r   )r   ÚsettingÚkwargss      r   r   z#ChannelLayerManager._reset_backends   s   € ð Ð&Ò&ØˆD�Mð 'r   c                 ó$   — t        t        di «      S )Nr   )Úgetattrr   r   s    r   ÚconfigszChannelLayerManager.configs"   s   € ô ”xÐ!1°2Ó6Ð6r   c                 ód   — | j                   |   j                  di «      }| j                  ||«      S )z,
        Instantiate channel layer.
        ÚCONFIG)r   ÚgetÚ_make_backend©r   ÚnameÚconfigs      r   Úmake_backendz ChannelLayerManager.make_backend'   s2   € ð —‘˜dÑ#×'Ñ'¨°"Ó5ˆØ×!Ñ! $¨Ó/Ð/r   c                 ó‚   — 	 | j                   |   d   }| j                  ||«      S # t        $ r t        d|z  «      ‚w xY w)zB
        Instantiate channel layer using its test config.
        ÚTEST_CONFIGzNo TEST_CONFIG specified for %s)r   ÚKeyErrorr
   r!   r"   s      r   Úmake_test_backendz%ChannelLayerManager.make_test_backend.   sT   € ð	UØ—\‘\ $Ñ'¨Ñ6ˆFð ×!Ñ! $¨Ó/Ð/øô ò 	UÜ*Ð+LÈtÑ+SÓTÐTð	Uús   ‚& ¦>c                 ó  — d| j                   |   v rt        d|z  «      ‚	 t        | j                   |   d   «      } |di |¤ŽS # t        $ r t        d|z  «      ‚t        $ r" t        d| j                   |   d   ›d|›�«      ‚w xY w)NÚROUTINGzBROUTING key found for %s - this is no longer needed in Channels 2.ÚBACKENDzNo BACKEND specified for %szCannot import BACKEND z specified for © )r   r
   r   r(   ÚImportError)r   r#   r$   Úbackend_classs       r   r!   z!ChannelLayerManager._make_backend8   s¨   € à˜Ÿ™ TÑ*Ñ*Ü*ØTØñóð ð
	Ü)¨$¯,©,°tÑ*<¸YÑ*GÓHˆMñ Ñ&˜vÑ&Ð&øô ò 	QÜ*Ð+HÈ4Ñ+OÓPÐPÜò 	Ý*à—<‘< Ñ% iÓ0±$ð8óð ð	ús   ¡A ÁABc                 óx   — || j                   vr| j                  |«      | j                   |<   | j                   |   S r   )r   r%   ©r   Úkeys     r   Ú__getitem__zChannelLayerManager.__getitem__L   s6   € Ø�d—m‘mÑ#Ø!%×!2Ñ!2°3Ó!7ˆD�M‰M˜#ÑØ�}‰}˜SÑ!Ð!r   c                 ó   — || j                   v S r   )r   r1   s     r   Ú__contains__z ChannelLayerManager.__contains__Q   s   € Ø�d—l‘lÐ"Ð"r   c                 ó\   — | j                   j                  |d«      }|| j                   |<   |S )z»
        Sets an alias to point to a new ChannelLayerWrapper instance, and
        returns the old one that it replaced. Useful for swapping out the
        backend during tests.
        N)r   r    )r   r2   ÚlayerÚolds       r   ÚsetzChannelLayerManager.setT   s-   € ð �m‰m×Ñ  TÓ*ˆØ"ˆ�‰�cÑØˆ
r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úpropertyr   r%   r)   r!   r3   r5   r9   r-   r   r   r   r      sC   „ ñò6òð ñ7ó ð7ò0ò0ò'ò("ò
#ór   r   c                   óð   — e Zd ZdZdZdd„Zd„ Zd„ Zd„ Z e	j                  d«      Z e	j                  d	«      Zd
dj                  e«      z   dz   dz   Zdd„Zd„ Zdd„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚBaseChannelLayerzf
    Base channel layer class that others can inherit from, with useful
    common functionality.
    éd   Nc                 ó6   — || _         || _        |xs i | _        y r   ©ÚexpiryÚcapacityÚchannel_capacity)r   rD   rE   rF   s       r   r   zBaseChannelLayer.__init__g   s   € ØˆŒØ ˆŒØ 0Ò 6°BˆÕr   c                 óì   — g }|j                  «       D ]^  \  }}t        |d«      r|j                  ||f«       Œ&|j                  t        j                  t        j                  |«      «      |f«       Œ` |S )z 
        Takes an input channel_capacity dict and returns the compiled list
        of regexes that get_capacity will look for as self.channel_capacity
        Úmatch)ÚitemsÚhasattrÚappendÚreÚcompileÚfnmatchÚ	translate)r   rF   ÚresultÚpatternÚvalues        r   Úcompile_capacitiesz#BaseChannelLayer.compile_capacitiesl   sp   € ð
 ˆØ.×4Ñ4Ó6ò 	O‰NˆG�Uô �w Ô(Ø—‘˜w¨Ð.Õ/à—‘œrŸz™z¬'×*;Ñ*;¸GÓ*DÓEÀuÐMÕNð	Oð ˆr   c                 ól   — | j                   D ]  \  }}|j                  |«      sŒ|c S  | j                  S )a  
        Gets the correct capacity for the given channel; either the default,
        or a matching result from channel_capacity. Returns the first matching
        result; if you want to control the order of matches, use an ordered dict
        as input.
        )rF   rH   rE   )r   ÚchannelrQ   rE   s       r   Úget_capacityzBaseChannelLayer.get_capacity{   s;   € ð "&×!6Ñ!6ò 	 ÑˆG�XØ�}‰}˜WÕ%Ø’ð	 ð �}‰}Ðr   c                 óV   — t        |t        «      rt        |«      | j                  k  ryy)NTF)Ú
isinstanceÚstrÚlenÚMAX_NAME_LENGTH©r   r#   s     r   Úmatch_type_and_lengthz&BaseChannelLayer.match_type_and_length‡   s#   € Ü�dœCÔ ¤c¨$£i°$×2FÑ2FÒ&FØØr   z!^[a-zA-Z\d\-_.]+(\![\d\w\-_.]*)?$z^[a-zA-Z\d\-_.]+$z'{} name must be a valid unicode string zwith length < {} zGcontaining only ASCII alphanumerics, hyphens, underscores, or periods, znot {}c                 óü   — | j                  |«      rGt        | j                  j                  |«      «      r#d|v r|j	                  d«      s|rt        d«      ‚yt        | j                  j                  d|«      «      ‚)Nú!z5Specific channel names in receive() must end at the !TÚChannel)r]   ÚboolÚchannel_name_regexrH   ÚendswithÚ	TypeErrorÚinvalid_name_errorÚformat)r   r#   Úreceives      r   Úvalid_channel_namez#BaseChannelLayer.valid_channel_name—   sp   € Ø×%Ñ% dÔ+Ü�D×+Ñ+×1Ñ1°$Ó7Ô8à˜$‘; t§}¡}°SÔ'9¹gÜ#ØOóð ð Ü˜×/Ñ/×6Ñ6°yÀ$ÓGÓHÐHr   c                 ó¸   — | j                  |«      r%t        | j                  j                  |«      «      ryt	        | j
                  j                  d|«      «      ‚)NTÚGroup)r]   ra   Úgroup_name_regexrH   rd   re   rf   r\   s     r   Úvalid_group_namez!BaseChannelLayer.valid_group_name¢   sJ   € Ø×%Ñ% dÔ+Ü�D×)Ñ)×/Ñ/°Ó5Ô6ØÜ˜×/Ñ/×6Ñ6°wÀÓEÓFÐFr   c                 óx   ‡ ‡— |rdnd}t        |t        «      }|r|sJ d«       ‚t        ˆˆ fd„|D «       «      sJ ‚y)NTFznames must be a non-empty listc              3   óD   •K  — | ]  }‰j                  |‰¬ «      –— Œ y­w))rg   N)rh   )Ú.0rU   rg   r   s     €€r   ú	<genexpr>z7BaseChannelLayer.valid_channel_names.<locals>.<genexpr>­   s&   øè ø€ ò 
ØBIˆD×#Ñ# G°WÐ#×=ñ
ùs   ƒ )rX   ÚlistÚall)r   Únamesrg   Ú_non_empty_listÚ_names_types   ` `  r   Úvalid_channel_namesz$BaseChannelLayer.valid_channel_names¨   sM   ù€ Ù"'™$¨UˆÜ  ¬Ó-ˆÙ¡;ÐPÐ0PÓPÐ.äô 
ØMRô
ô 
ð 	
ð 
ð r   c                 ó<   — d|v r|d|j                  d«      dz    S |S )zõ
        Given a channel name, returns the "non-local" part. If the channel name
        is a process-specific channel (contains !) this means the part up to
        and including the !; if it is anything else, this means the full name.
        r_   Nr   )Úfindr\   s     r   Únon_local_namezBaseChannelLayer.non_local_name²   s+   € ð �$‰;ØÐ,˜$Ÿ)™) C›.¨1Ñ,Ð-Ð-àˆKr   c              ƒ   ó    K  — t        d«      ‚­w)Nz/send() should be implemented in a channel layer©ÚNotImplementedError)r   rU   Úmessages      r   ÚsendzBaseChannelLayer.send½   ó   è ø€ Ü!Ð"SÓTÐTùó   ‚c              ƒ   ó    K  — t        d«      ‚­w)Nz2receive() should be implemented in a channel layerr{   )r   rU   s     r   rg   zBaseChannelLayer.receiveÀ   ó   è ø€ Ü!Ð"VÓWÐWùr€   c              ƒ   ó    K  — t        d«      ‚­w)Nz6new_channel() should be implemented in a channel layerr{   r   s    r   Únew_channelzBaseChannelLayer.new_channelÃ   s   è ø€ Ü!ØDó
ð 	
ùr€   c              ƒ   ó    K  — t        d«      ‚­w)Nz)flush() not implemented (flush extension)r{   r   s    r   ÚflushzBaseChannelLayer.flushÈ   s   è ø€ Ü!Ð"MÓNÐNùr€   c              ƒ   ó    K  — t        d«      ‚­w)Nz.group_add() not implemented (groups extension)r{   ©r   ÚgrouprU   s      r   Ú	group_addzBaseChannelLayer.group_addË   s   è ø€ Ü!Ð"RÓSÐSùr€   c              ƒ   ó    K  — t        d«      ‚­w)Nz2group_discard() not implemented (groups extension)r{   rˆ   s      r   Úgroup_discardzBaseChannelLayer.group_discardÎ   r‚   r€   c              ƒ   ó    K  — t        d«      ‚­w)Nz/group_send() not implemented (groups extension)r{   )r   r‰   r}   s      r   Ú
group_sendzBaseChannelLayer.group_sendÑ   r   r€   )é<   rA   N)F)r:   r;   r<   r=   r[   r   rS   rV   r]   rL   rM   rb   rk   rf   re   rh   rl   rv   ry   r~   rg   r„   r†   rŠ   rŒ   rŽ   r-   r   r   r@   r@   _   sµ   „ ñð
 €Oó7ò
ò
òð $˜Ÿ™Ð$HÓIÐØ!�r—z‘zÐ"6Ó7Ðà1Ø
×
$Ñ
$ _Ó
5ñ	6à
Sñ	Tð ñ	ð ó	IòGóò	òUòXò
ò
OòTòXóUr   r@   c                   ór   ‡ — e Zd ZdZ	 	 	 	 dˆ fd„	ZddgZd„ Zd„ Zdd„Zd„ Z	d	„ Z
d
„ Zd„ Zd„ Zd„ Zd„ Zˆ xZS )ÚInMemoryChannelLayerz0
    In-memory channel layer implementation
    c                 óV   •— t        ‰| �  d|||dœ|¤Ž i | _        i | _        || _        y )NrC   r-   )Úsuperr   ÚchannelsÚgroupsÚgroup_expiry)r   rD   r–   rE   rF   r   Ú	__class__s         €r   r   zInMemoryChannelLayer.__init__Ú   sB   ø€ ô 	‰Ñð 	
ØØØ-ñ	
ð ò		
ð ˆŒØˆŒØ(ˆÕr   r•   r†   c              ƒ   óÄ  K  — t        |t        «      sJ d«       ‚| j                  |«      sJ d«       ‚d|vsJ ‚| j                  j	                  |t        j                  | j                  |«      ¬«      «      }	 |j                  t        j                  «       | j                  z   t        |«      f«       y# t
        j                  j                  $ r t        |«      ‚w xY w­w)zF
        Send a message onto a (general or specific) channel.
        zmessage is not a dictúChannel name not validÚ__asgi_channel__©ÚmaxsizeN)rX   Údictrh   r”   Ú
setdefaultÚasyncioÚQueuerV   Ú
put_nowaitÚtimerD   r   ÚqueuesÚ	QueueFullr	   )r   rU   r}   Úqueues       r   r~   zInMemoryChannelLayer.sendð   sÄ   è ø€ ô
 ˜'¤4Ô(ÐAÐ*AÓAÐ(Ø×&Ñ& wÔ/ÐIÐ1IÓIÐ/ð "¨Ñ0Ð0Ð0à—‘×(Ñ(Ø”W—]‘]¨4×+<Ñ+<¸WÓ+EÔFó
ˆð	'Ø×ÑœdŸi™i›k¨D¯K©KÑ7¼À'Ó9JÐKÕLøÜ�~‰~×'Ñ'ò 	'Ü˜gÓ&Ð&ð	'üs   ‚A5C Á8;B4 Â3C Â4)CÃC c              ƒ   óÊ  K  — | j                  |«      sJ ‚| j                  «        | j                  j                  |t	        j
                  | j                  |«      ¬«      «      }	 |j                  «       ƒ d{  –—† \  }}|j                  «       r| j                  j                  |d«       |S 7 Œ5# |j                  «       r| j                  j                  |d«       w w xY w­w)zÊ
        Receive the first message that arrives on the channel.
        If more than one coroutine waits on the same channel, a random one
        of the waiting coroutines will get the result.
        r›   N)
rh   Ú_clean_expiredr”   rž   rŸ   r    rV   r    ÚemptyÚpop)r   rU   r¥   Ú_r}   s        r   rg   zInMemoryChannelLayer.receive  s¶   è ø€ ð ×&Ñ& wÔ/Ð/Ð/Ø×ÑÔà—‘×(Ñ(Ø”W—]‘]¨4×+<Ñ+<¸WÓ+EÔFó
ˆð
	1Ø$Ÿy™y›{×*‰JˆAˆwà�{‰{Œ}Ø—‘×!Ñ! '¨4Ô0àˆð +ùà�{‰{Œ}Ø—‘×!Ñ! '¨4Õ0ð üs0   ‚A#C#Á&B1 Á9B/Á:B1 Â.C#Â/B1 Â1/C Ã C#c              ƒ   óV   K  — |›ddj                  d„ t        d«      D «       «      ›�S ­w)zx
        Returns a new channel name that can be used by something in our
        process as a specific channel.
        z
.inmemory!Ú c              3   ób   K  — | ]'  }t        j                  t        j                  «      –— Œ) y ­wr   )ÚrandomÚchoiceÚstringÚascii_letters)ro   Úis     r   rp   z3InMemoryChannelLayer.new_channel.<locals>.<genexpr>!  s   è ø€ ÒK¸A”F—M‘M¤&×"6Ñ"6×7ÑKùs   ‚-/é   )ÚjoinÚrange)r   Úprefixs     r   r„   z InMemoryChannelLayer.new_channel  s+   è ø€ ò Ø�G‰GÑKÄÀrÃÔKÔKð
ð 	
ùs   ‚')c                 óâ  — t        | j                  j                  «       «      D ]Ä  \  }}|j                  «       rŒ|j                  d   d   t        j
                  «       k  sŒ?|j                  «        | j                  |«       |j                  «       r| j                  j                  |d«       |j                  «       rŒ�|j                  d   d   t        j
                  «       k  rŒ†ŒÆ t        t        j
                  «       «      | j                  z
  }| j                  j                  «       D ]>  }t        |j                  «       «      D ]   \  }}|sŒ	||k  sŒ|j                  |d«       Œ" Œ@ y)z¢
        Goes through all messages and groups and removes those that are expired.
        Any channel with an expired message is removed from all groups.
        r   N)rq   r”   rI   r¨   Ú_queuer¢   Ú
get_nowaitÚ_remove_from_groupsr©   Úintr–   r•   Úvalues)r   rU   r¥   Útimeoutr”   r#   Ú	timestamps          r   r§   z#InMemoryChannelLayer._clean_expired&  s  € ô # 4§=¡=×#6Ñ#6Ó#8Ó9ò 	5‰NˆG�Uà—k‘k•m¨¯©°Q©¸Ñ(:¼T¿Y¹Y»[Ó(HØ× Ñ Ô"à×(Ñ(¨Ô1à—;‘;”=Ø—M‘M×%Ñ% g¨tÔ4ð —k‘k•m¨¯©°Q©¸Ñ(:¼T¿Y¹Y»[Ô(Hð	5ô ”d—i‘i“kÓ" T×%6Ñ%6Ñ6ˆØŸ™×*Ñ*Ó,ò 	-ˆHÜ#'¨¯©Ó(8Ó#9ò -‘��iò  ¨WÓ!4à—L‘L  tÕ,ñ-ñ	-r   c              ƒ   ó(   K  — i | _         i | _        y ­wr   )r”   r•   r   s    r   r†   zInMemoryChannelLayer.flushB  s   è ø€ ØˆŒØˆ�ùs   ‚c              ƒ   ó   K  — y ­wr   r-   r   s    r   ÚclosezInMemoryChannelLayer.closeF  s	   è ø€ àùs   ‚c                 óf   — | j                   j                  «       D ]  }|j                  |d«       Œ y)zW
        Removes a channel from all groups. Used when a message on it expires.
        N)r•   r¼   r©   )r   rU   r”   s      r   rº   z(InMemoryChannelLayer._remove_from_groupsJ  s.   € ð Ÿ™×*Ñ*Ó,ò 	(ˆHØ�L‰L˜ $Õ'ñ	(r   c              ƒ   óì   K  — | j                  |«      sJ d«       ‚| j                  |«      sJ d«       ‚| j                  j                  |i «       t	        j                  «       | j                  |   |<   y­w)z3
        Adds the channel name to a group.
        zGroup name not validr™   N)rl   rh   r•   rž   r¢   rˆ   s      r   rŠ   zInMemoryChannelLayer.group_addS  si   è ø€ ð
 ×$Ñ$ UÔ+ÐCÐ-CÓCÐ+Ø×&Ñ& wÔ/ÐIÐ1IÓIÐ/à�‰×Ñ˜u bÔ)Ü&*§i¡i£kˆ�‰�EÑ˜7Ò#ùs   ‚A2A4c              ƒ   ó  K  — | j                  |«      sJ d«       ‚| j                  |«      sJ d«       ‚| j                  j                  |d «      }|r2|j	                  |d «       |s| j                  j	                  |d «       y y y ­w)NzInvalid channel nameúInvalid group name)rh   rl   r•   r    r©   )r   r‰   rU   Úgroup_channelss       r   rŒ   z"InMemoryChannelLayer.group_discard^  s€   è ø€ à×&Ñ& wÔ/ÐGÐ1GÓGÐ/Ø×$Ñ$ UÔ+ÐAÐ-AÓAÐ+àŸ™Ÿ™¨°Ó5ˆÙà×Ñ˜w¨Ô-á!Ø—‘—‘  tÕ,ð "ð	 ùs   ‚BBc           	   ƒ   óÂ  K  — t        |t        «      sJ d«       ‚| j                  |«      sJ d«       ‚| j                  «        g }|| j                  v rV| j                  |   j                  «       D ]6  }|j                  t        j                  | j                  ||«      «      «       Œ8 t        j                  |«      D ]  }	 |ƒ d {  –—†  Œ y 7 Œ# t        $ r Y Œw xY w­w)NzMessage is not a dictrÅ   )rX   r�   rl   r§   r•   ÚkeysrK   rŸ   Úcreate_taskr~   Úas_completedr	   )r   r‰   r}   ÚopsrU   Úsend_results         r   rŽ   zInMemoryChannelLayer.group_sendk  sÖ   è ø€ ä˜'¤4Ô(ÐAÐ*AÓAÐ(Ø×$Ñ$ UÔ+ÐAÐ-AÓAÐ+à×ÑÔð ˆØ�D—K‘KÑØŸ;™; uÑ-×2Ñ2Ó4ò M�Ø—
‘
œ7×.Ñ.¨t¯y©y¸À'Ó/JÓKÕLðMä"×/Ñ/°Ó4ò 	ˆKðØ!×!Ñ!ñ	à!ùÜò Ùðüs<   ‚B>CÃCÃCÃCÃCÃCÃ	CÃCÃCÃC)r�   i€Q rA   N)z	specific.)r:   r;   r<   r=   r   Ú
extensionsr~   rg   r„   r§   r†   rÁ   rº   rŠ   rŒ   rŽ   Ú__classcell__)r—   s   @r   r‘   r‘   Õ   sY   ø„ ñð ØØØõ)ð( ˜GÐ$€Jò'ò(ó,
ò-ò8òò(ò	2ò-ör   r‘   c                 ó4   — 	 t         |    S # t        $ r Y yw xY w)zL
    Returns a channel layer by alias, or None if it is not configured.
    N)Úchannel_layersr(   )Úaliass    r   Úget_channel_layerrÒ   ~  s$   € ðÜ˜eÑ$Ð$øÜò Ùðús   ‚ ‹	–)rŸ   rN   r®   rL   r°   r¢   Úcopyr   Údjango.confr   Údjango.core.signalsr   Údjango.utils.module_loadingr   r”   r   Ú
exceptionsr	   r
   r   r@   r‘   rÒ   rÐ   r-   r   r   ú<module>rØ      si   ðÛ Û Û Û 	Û Û Ý å  Ý /Ý 5å *ç =÷Jñ J÷ZsUñ sUôlfÐ+ô fðR 2ó ñ %Ó&�r   