
    ?h%                        d dl mZmZmZmZ d dlZd dlZd dlZd dlZd dl	Z	dZ
 ej                  d      Z ej                  de
 d      Z ej                  d      Z ej                  d      Z ej                  d	      Zej"                  d
k  rdZndZej"                  d
k  rdZndZd Zd Zd Zd Zd Zd ZdefdZd Zd Zd Zy)    )print_functionunicode_literalsabsolute_importdivisionNz#server-to-user-z\A[-a-zA-Z0-9_=@,.;]+\Zz\Az[-a-zA-Z0-9_=@,.;]+\Zz
\A[0-9]+\Zz/\A(http|https)://(.*):(.*)@(.*)/apps/([0-9]+)\Zz\A\d+\.\d+\Z)   za unicode stringza stringza python2 strza python3 bytesc           	      @   t        | t        j                        r| S t        | t        j                        rt        j                  |       S t        | t        j                        rt        |       j                  d      S t        |dt        dt        |             )Nutf-8 should be  instead it is a )

isinstancesix	text_typestring_typesbinary_typebytesdecode	TypeErrortexttypeobjnames     L/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/pusher/util.pyensure_textr   !   sm    #s}}%
#s''(}}S!!#s'Sz  ))
D$S	R
SS    c           	         t        | t        j                        r| S t        | t        j                        st        | t        j                        r| j                  d      S t        |dt        dt        |             )z
    ensure_binary() ensures that the value is a
    python2 str or python3 bytes
    more on this here: https://pythonhosted.org/six/#six.binary_type
    r	   r
   r   )	r   r   r   r   r   encoder   	byte_typer   r   s     r   ensure_binaryr   .   sZ     #s'
#s}}%C9I9I)Jzz'""
D)TRUYW
XXr   c                     	 t        j                  | d      } t        j                  t        j                  |             | k(  S # t
        $ r
}Y d}~yd}~ww xY w)z
    is_base64 tests whether a string is valid base64 by testing that it round-trips accurately.
    This is required because python 2.7 does not have a Validate option to the decoder.
    r	   NF)r   r   base64	b64encode	b64decode	Exception)ses     r   	is_base64r'   =   sM    
a) 0 0 3499 s   A A 	AAc                     t        | d      } t        |       }|dk(  rt        d      |dkD  rt        dj                  |             t        j                  |       st        dj                  |             | S )Nuser_idr   zUser id is empty   zUser id too long: '{}'zInvalid user id: '{}')r   len
ValueErrorformatchannel_name_rematch)r)   lengths     r   validate_user_idr1   I   sr    '9-G\F{+,,|188ABB  )077@AANr   c                    t        | d      } t        |       dkD  rt        d| z        | j                  t              r%t
        j                  |       st        d| z        | S t        j                  |       st        d| z        | S )Nchannelr*   zChannel too long: %sz"Invalid server to user Channel: %szInvalid Channel: %s)r   r+   r,   
startswithSERVER_TO_USER_PREFIXserver_to_user_channel_rer/   r.   )r3   s    r   validate_channelr7   Y   s    '9-G
7|c/'9::/0(..w7AGKLL N ""7+.899Nr   c                 d    t        | d      } t        j                  |       st        d| z        | S )N	socket_idzInvalid socket ID: %s)r   socket_id_rer/   r,   )r9   s    r   validate_socket_idr;   h   s3    I{3Ii(09<==r   	user_datac                     | t        d      | j                  d      t        d      t        | j                  d             y )Nzuser_data is nullidzuser_data has no id field)r,   getr1   )r<   s    r   validate_user_datar@   q   s@    ,--}}T"455Y]]4()r   c                 J    t        j                  d      j                  |       S )N,)r   r   join)
attributess    r   join_attributesrE   y   s    =="":..r   c                 ~    t        | t        j                        rt        | d      S t	        j
                  | |d      S )NdataF)clsensure_ascii)r   r   r   r   jsondumps)rG   json_encoders     r   data_to_stringrM   }   s4    $(()4(( zz$LuEEr   c                       fd}|S )Nc                     | _         | S )N)__doc__)fdocs    r   	decoratorzdoc_string.<locals>.decorator   s    	r    )rR   rS   s   ` r   
doc_stringrU      s     r   )
__future__r   r   r   r   rJ   rer   sysr!   r5   compiler.   r6   	app_id_repusher_url_rer:   version_infor   r   r   r   r'   r1   r7   r;   dictr@   rE   rM   rU   rT   r   r   <module>r^      s      	 
 
 * "**78&BJJ"-B,CCX'YZ BJJ}%	

MNrzz/*dDDdI!I
TY	 *$ */Fr   