o
    g÷§i+  ã                   @   s:   d Z ddlZddlZddlZddlmZ G dd„ dƒZdS )zP
This class is responsible for getting/setting an anonymous (GDPR-compliant) ID
é    N)ÚUUIDc                   @   s|   e Zd ZU dZdZeje ed< dZ	eed< e
dejej fdd„ƒZe
dejej fd	d
„ƒZe
deje fdd„ƒZdS )ÚPersistentRandomUserIDzX
    This class is responsible for getting/setting an anonymous (GDPR-compliant) ID
    NÚUSER_IDÚanonymous_user_idÚUSER_ID_FILE_NAMEÚreturnc                  C   sD   t  ¡ D ]} t t  | ¡¡}| ¡ sq|d }| ¡ r|  S qd S )NÚborb)Ú	sysconfigÚget_path_namesÚpathlibÚPathÚget_pathÚexists)Ú	path_nameÚinstallation_pathÚborb_dir© r   úZ/home/ubuntu/.local/lib/python3.10/site-packages/borb/license/persistent_random_user_id.pyÚ_get_borb_installation_dir   s   ÿÿz1PersistentRandomUserID._get_borb_installation_dirc                  C   s.   t  ¡ } | d u r
d S | t j }| ¡ r|S d S )N)r   r   r   r   )Úinstallation_dirÚuser_id_filer   r   r   Ú_get_user_id_file_from_borb_dir,   s   þÿz6PersistentRandomUserID._get_user_id_file_from_borb_dirc                  C   sè   t  ¡ } t  ¡ }| durC|  ¡ rC|du s| ¡ sCz&t ¡ }t| t j dƒ}| |¡ W d  ƒ |W S 1 s7w   Y  |W S    Y |durr| ¡ rrd}zt|dƒ}| 	¡ }W d  ƒ W |S 1 sdw   Y  W |S    Y |S dS )zå
        This function (creates and then) returns an anonymous user ID.
        This ID is stored in a file in the borb installation directory to ensure consistency between calls.
        :return:    an anonymous user ID
        NÚwÚr)
r   r   r   r   r   ÚgetÚopenr   ÚwriteÚread)r   r   Únew_uuidÚfhÚ	prev_uuidr   r   r   r   @   s>   þþÿ
ÿþ
ÿüþzPersistentRandomUserID.get)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚtypingÚOptionalÚstrÚ__annotations__r   Ústaticmethodr   r   r   r   r   r   r   r   r   r      s   
 
r   )r$   r	   r%   r   Úborb.license.uuidr   r   r   r   r   r   Ú<module>   s   