o
    l>j>	                     @   s   d Z ddlZddlZddlZddlmZ ddlZdZej	 fde
dee
 fddZde
defd	d
Zde
dee
 fddZde
de
ddfddZde
ddfddZd de
dede
fddZde
de
fddZde
defddZdede
fddZdS )!zUtils.    N)Optionalzpyicloud://icloud-passwordusernamereturnc                 C   s*   t | }|r|S |rtd|  dS dS )zGet the password from a username.
    Returns the password if found in keyring or if interactive is True.
    Returns None if no password is found and interactive is False.zEnter iCloud password for z: N)get_password_from_keyringgetpass)r   interactiveresult r	   C/home/thesage/.local/lib/python3.10/site-packages/pyicloud/utils.pyget_password   s   r   c                 C   s   t | duS )z@Return true if the password of a username exists in the keyring.N)r   r   r	   r	   r
   password_exists_in_keyring      r   c                 C      t t| S )z!Get the password from a username.)keyringr   KEYRING_SYSTEMr   r	   r	   r
   r      r   r   passwordc                 C   s   t t| |S )z!Store the password of a username.)r   set_passwordr   )r   r   r	   r	   r
   store_password_in_keyring#   s
   r   c                 C   r   )z"Delete the password of a username.)r   delete_passwordr   r   r	   r	   r
   delete_password_in_keyring,   s   r   Fwordinitial_capitalc                 C   s2   dd |  dD }|s|d  |d< d|S )zTransform a word to camelCase.c                 S   s   g | ]}|  p	d qS )_)
capitalize).0xr	   r	   r
   
<listcomp>6   s    z+underscore_to_camelcase.<locals>.<listcomp>r   r    )splitlowerjoin)r   r   wordsr	   r	   r
   underscore_to_camelcase4   s   
r#   	camel_strc                 C   sH   g }t | D ]\}}| r|dkr|d ||  qd|S )z
    Convert camelCase string to snake_case.

    Examples:
        startDate -> start_date
        localStartDate -> local_start_date
        hasAttachments -> has_attachments
    r   r   r   )	enumerateisupperappendr    r!   )r$   r   icharr	   r	   r
   camelcase_to_underscore=   s   	

r*   sc                 C   s   t | dt|  d   S )z"Decode a base64url encoded string.=   )base64urlsafe_b64decodelen)r+   r	   r	   r
   b64url_decodeN   s   r1   bc                 C   s   t |  S )z(Encode bytes to a base64 encoded string.)r.   	b64encodedecode)r2   r	   r	   r
   
b64_encodeS   s   r5   )F)__doc__r.   r   systypingr   r   r   stdoutisattystrr   boolr   r   r   r   r#   r*   bytesr1   r5   r	   r	   r	   r
   <module>   s      		