
    =[j
                         d Z ddlmZ ddlmZmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZ  G d d	e          Z G d
 d          ZdS )zFile service.    )datetime)AnyOptional)Response)PyiCloudAPIResponseExceptionPyiCloudServiceUnavailable)BaseService)PyiCloudSessionc                        e Zd ZdZdededeeef         ddf fdZe	dd	            Z
ddefdZddZded         fdZdefdZd ZddZ xZS )UbiquityServicezThe 'Ubiquity' iCloud service.service_rootsessionparamsreturnNc                     t                                          |||           d | _        	 | j         d S # t          $ r&}|j        dk    rt          |j                  | d }~ww xY w)Ni  )super__init___rootrootr   coder   reason)selfr   r   r   error	__class__s        b/home/thesage/.hermes/hermes-agent/venv/lib/python3.11/site-packages/pyicloud/services/ubiquity.pyr   zUbiquityService.__init__   sy     	w777/3
	IIII+ 	 	 	zS  0>>EI	s   6 
A& !A!!A&UbiquityNodec                 R    | j         s|                     d          | _         | j         S )zGets the root node.r   )r   get_noder   s    r   r   zUbiquityService.root   s)     z 	*q))DJz    itemc                 <    | j          d| j        d          d| d| S )zReturns a node URL.z/ws/dsid/)r   r   )r   node_idvariants      r   get_node_urlzUbiquityService.get_node_url%   s0    #RRV)<RRwRRRRRr    c                     | j                             |                     |                    }t          | |                                          S )zReturns a node.)r   getr'   r   json)r   r%   responses      r   r   zUbiquityService.get_node)   s=    !\--d.?.?.H.HIID(--//222r    c                       j                                                  |d                    }|                                d         } fd|D             S )zReturns a node children.parent	item_listc                 0    g | ]}t          |          S  )r   ).0r!   r   s     r   
<listcomp>z0UbiquityService.get_children.<locals>.<listcomp>2   s#    ;;;TT4((;;;r    )r   r)   r'   r*   )r   r%   r+   itemss   `   r   get_childrenzUbiquityService.get_children.   sT    !\--d.?.?.R.RSS&.mmook&B;;;;U;;;;r    c                 P     | j         j        |                     |d          fi |S )zReturns a node file.file)r   r)   r'   )r   r%   kwargss      r   get_filezUbiquityService.get_file4   s/    t| 1 1'6 B BMMfMMMr    c                 ,    t          | j        |          S N)getattrr   )r   attrs     r   __getattr__zUbiquityService.__getattr__8   s    ty$'''r    c                     | j         |         S r:   )r   )r   keys     r   __getitem__zUbiquityService.__getitem__;   s    y~r    )r   r   )r!   )__name__
__module____qualname____doc__strr
   dictr   r   propertyr   r'   r   listr4   r   r8   r=   r@   __classcell__)r   s   @r   r   r      s(       ((*9CGS>	         XS Ss S S S S3 3 3 3
<tN'; < < < <NX N N N N( ( (       r    r   c                   N   e Zd ZdZdedeeef         ddfdZede	e         fd            Z
edefd            Zedefd	            Zede	e         fd
            Zedefd            ZdefdZded          fdZdee         fdZdedd fdZdedd fdZdefdZdefdZdS )r   zUbiquity node.conndatar   Nc                 0    || _         || _        d | _        d S r:   )rL   
connection	_children)r   rK   rL   s      r   r   zUbiquityNode.__init__B   s    $(	+/7;r    c                 6    | j                             d          S )zGets the node id.item_idrL   r)   r   s    r   rQ   zUbiquityNode.item_idH   s     y}}Y'''r    c                 8    | j                             dd          S )zGets the node name.name	<unknown>rR   r   s    r   rT   zUbiquityNode.nameM        y}}V[111r    c                 8    | j                             dd          S )zGets the node type.typerU   rR   r   s    r   rX   zUbiquityNode.typeR   rV   r    c                 v    	 t          | j                            dd                    S # t          $ r Y dS w xY w)zGets the node size.sizez-1N)intrL   r)   
ValueErrorr   s    r   rZ   zUbiquityNode.sizeW   sG    	ty}}VT22333 	 	 	44	s   '* 
88c                 ^    t          j        | j                            dd          d          S )zGets the node modified date.modified z%Y-%m-%dT%H:%M:%SZ)r   strptimerL   r)   r   s    r   r^   zUbiquityNode.modified_   s(      z2!>!>@TUUUr    c                 2     | j         j        | j        fi |S )zReturns the node file.)rN   r8   rQ   )r   r7   s     r   openzUbiquityNode.opend   s!    't'?????r    c                 f    | j         s$| j                            | j                  | _         | j         S )zReturns the node children.)rO   rN   r4   rQ   r   s    r   r4   zUbiquityNode.get_childrenh   s.    ~ 	H!_99$,GGDN~r    c                 >    d |                                  D             S )z1Returns children node directories by their names.c                     g | ]	}|j         
S r0   rT   )r1   childs     r   r2   z$UbiquityNode.dir.<locals>.<listcomp>p   s    <<<u
<<<r    r4   r   s    r   dirzUbiquityNode.dirn   s"    <<(9(9(;(;<<<<r    rT   c                 P    fd|                                  D             d         S )z!Returns a child node by its name.c                 *    g | ]}|j         k    |S r0   rf   )r1   rg   rT   s     r   r2   z$UbiquityNode.get.<locals>.<listcomp>t   s%    MMM%%*:L:L:L:L:Lr    r   rh   )r   rT   s    `r   r)   zUbiquityNode.getr   s.    MMMM4#4#4#6#6MMMaPPr    r?   c                 z    	 |                      |          S # t          $ r}t          d| d          |d }~ww xY w)NzNo child named z exists)r)   
IndexErrorKeyError)r   r?   is      r   r@   zUbiquityNode.__getitem__v   sW    	B88C==  	B 	B 	B9S999::A	Bs    
:5:c                     | j         S r:   rf   r   s    r   __str__zUbiquityNode.__str__|   s
    yr    c                 B    d| j                                          d|  dS )N<z: 'z'>)rX   
capitalizer   s    r   __repr__zUbiquityNode.__repr__   s)    649''))66d6666r    )rA   rB   rC   rD   r   rF   rE   r   rG   r   rQ   rT   rX   r[   rZ   r   r^   r   rb   rH   r4   ri   r)   r@   rq   ru   r0   r    r   r   r   ?   s        <_ <DcN <t < < < < (# ( ( ( X( 2c 2 2 2 X2 2c 2 2 2 X2 hsm    X V( V V V XV@ @ @ @ @d>2    =T#Y = = = =Q Q Q Q Q QBs B~ B B B B    7# 7 7 7 7 7 7r    r   N)rD   r   typingr   r   requestsr   pyicloud.exceptionsr   r   pyicloud.services.baser	   pyicloud.sessionr
   r   r   r0   r    r   <module>r{      s                                  X X X X X X X X . . . . . . , , , , , ,/ / / / /k / / /dA7 A7 A7 A7 A7 A7 A7 A7 A7 A7r    