o
    54g                     @   sD   d dl Z d dlmZmZ ddlmZ ddlmZ dd Zdd	 Z	dS )
    N)WebPushExceptionwebpush   )get_manager)WebPushErrorc                 C   sJ   | dr|}nt | |}d||}tjdtdd |||ddS )Nzhttps://z{}/{}zOregistration_id should be the full endpoint returned from pushManager.subscribe   )
stacklevel)authp256dh)endpointkeys)
startswithr   get_wp_post_urlformatwarningswarnDeprecationWarning)application_iduribrowserr	   r
   r   url r   `/var/www/html/notificationserver/venv/lib/python3.10/site-packages/push_notifications/webpush.pyget_subscription_info	   s   
r   c              
   K   s   t | j| j| j| j| j}z:dd| jigi}td||t | jt 	| j
 d|}|jr8d|d< |W S d|d< |j|d d d< |W S  ty } z,|jd urv|jjd	v rvd|d< |j|d d d< d
| _|   |W  Y d }~S t|jd }~ww )Nresultsoriginal_registration_id)subscription_infodatavapid_private_keyvapid_claimsr   successfailurer   error)i  i  Fr   )r   r   registration_idr   r	   r
   r   r   get_wp_private_keyget_wp_claimscopyokcontentr   responsestatus_codemessageactivesaver   )devicer+   kwargsr   r   r)   er   r   r   webpush_send_message   s<   
r1   )
r   	pywebpushr   r   confr   
exceptionsr   r   r1   r   r   r   r   <module>   s    