a
    {b$                     @   sp   d Z dZddlmZ ddlmZ ddlmZ G dd dZe ZG dd	 d	Z	d
d Z
G dd dZdd ZdS )z
Utils
=====

)platformreify
deprecated    )environ)path)r   c                       sP   e Zd ZdZdd Zdd Zdd Zdd	 Z fd
dZdd Z	dd Z
  ZS )Platformz_
    Refactored to class to allow module function to be replaced
    with module variable.
    c                 C   s   d | _ d | _d S N)_platform_ios_platform_androidself r   [/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/plyer/utils.py__init__   s    zPlatform.__init__c                 C   s   ||   kS r   _get_platformr   otherr   r   r   __eq__   s    zPlatform.__eq__c                 C   s   ||   kS r   r   r   r   r   r   __ne__   s    zPlatform.__ne__c                 C   s   |   S r   r   r   r   r   r   __str__   s    zPlatform.__str__c                    s   dj |  t  dS )Nz-platform name: '{platform}' from: 
{instance})r   instance)formatr   super__repr__r   	__class__r   r   r       s    zPlatform.__repr__c                 C   s   |    S r   )r   __hash__r   r   r   r   r   &   s    zPlatform.__hash__c                 C   s|   | j d u rdtv | _ | jd u r0tdddk| _| j du r>dS | jdu rLdS tdv rXdS td	krdd
S td d dkrxdS dS )NZANDROID_ARGUMENTZ
KIVY_BUILD ZiosTZandroid)win32cygwinwindarwinmacosx   linuxunknown)r
   r   r	   get_sys_platformr   r   r   r   r   )   s    




zPlatform._get_platform)__name__
__module____qualname____doc__r   r   r   r   r   r   r   __classcell__r   r   r   r   r      s   r   c                   @   sX   e Zd ZdZg dZdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd ZdS )Proxyzw
    Based on http://code.activestate.com/recipes/496741-object-proxying
    version by Tomer Filiba, PSF license.
    )_obj_name_facadec                 C   s8   t |  t | dd  t | d| t | d| d S )Nr/   r0   r1   )objectr   __setattr__)r   namefacader   r   r   r   N   s    
zProxy.__init__c                 C   s   t | d}|r|S z0t | d}dt|}t|dd}| }W n4 tyx   dd l}|  t | d}| }Y n0 t 	| d| |S )Nr/   r0   zplyer.platforms.{}.{}.)fromlistr   r1   )
r2   __getattribute__r   r   
__import__r   	Exception	traceback	print_excr3   )r   objr4   modulemodr;   r5   r   r   r   _ensure_objT   s"    zProxy._ensure_objc                 C   s4   d }|dkr|S t | d  tt | d|}|S )Nr,   r@   r/   )r2   r8   getattr)r   r4   resultr   r   r   r8   h   s    zProxy.__getattribute__c                 C   s$   t | d  tt | d| d S Nr@   r/   )r2   r8   delattr)r   r4   r   r   r   __delattr__u   s    zProxy.__delattr__c                 C   s&   t | d  tt | d|| d S rC   )r2   r8   setattr)r   r4   valuer   r   r   r3   y   s    zProxy.__setattr__c                 C   s   t | d  tt | dS rC   )r2   r8   boolr   r   r   r   __bool__}   s    zProxy.__bool__c                 C   s   t | d  tt | dS rC   )r2   r8   strr   r   r   r   r      s    zProxy.__str__c                 C   s   t | d  tt | dS rC   )r2   r8   reprr   r   r   r   r      s    zProxy.__repr__N)r)   r*   r+   r,   	__slots__r   r@   r8   rE   r3   rI   r   r   r   r   r   r   r.   F   s   r.   c                 C   sh   t dkrdnd}tdd|D ]@}tt|| }tt|| }|r"|s"t||   S q"dS )zv Tries to find the program on the system path.
        Returns the path if it is found or None if it's not found.
    r!   ;:PATHr   N)r   r   r'   splitr   isdirjoinexists)programZ
path_splitpthfolder	availabler   r   r   whereis_exe   s    rX   c                   @   s    e Zd ZdZdd Zdd ZdS )r   a  
    Put the result of a method which uses this (non-data) descriptor decorator
    in the instance dict after the first call, effectively replacing the
    decorator with an instance variable.

    It acts like @property, except that the function is only ever called once;
    after that, the value is cached as a regular attribute. This gives you lazy
    attribute creation on objects that are meant to be immutable.

    Taken from the `Pyramid project <https://pypi.python.org/pypi/pyramid/>`_.

    To use this as a decorator::

         @reify
         def lazy(self):
              ...
              return hard_to_compute_int
         first_time = self.lazy   # lazy is reify obj, reify.__get__() runs
         second_time = self.lazy  # lazy is hard_to_compute_int
    c                 C   s   || _ |j| _d S r   )funcr,   )r   rY   r   r   r   r      s    zreify.__init__c                 C   s*   |d u r| S |  |}t|| j j| |S r   )rY   rF   r)   )r   instclsretvalr   r   r   __get__   s
    
zreify.__get__N)r)   r*   r+   r,   r   r]   r   r   r   r   r      s   r   c                    s   ddl ddlm ddlm} ddlm}m} d}t |r\|  fdd}|}n6tt	 t	r fdd	} j
 _||  _
 }|S )
a  
    This is a decorator which can be used to mark functions and classes as
    deprecated. It will result in a warning being emitted when a deprecated
    function is called or a new instance of a class created.

    In case of classes, the warning is emitted before the __new__ method
    of the decorated class is called, therefore a way before the __init__
    method itself.
    r   N)stack)wraps)FunctionType
MethodTypec                     sl    d dd \}}}d  j jj jjd |||}d d|  jr^ j  | i |S )N      zNCall to deprecated function {} in {} line {}. Called from {} line {} by {}().
z[{}] {}WARNING)r   r)   __code__co_filenameco_firstlinenowarnr,   )argskwargs	call_file	call_linecallerwarningr=   r^   warningsr   r   new_func   s    
zdeprecated.<locals>.new_funcc              
      s    d dd \}}} j }dd j||||  jrL j  | u sXJ t|jt| jkr| |jd u sJ | j|jfn t|jt| jkr| |u sJ  |S )z
            Custom metaclass instance's __new__ method with deprecated warning.
            Calls the original __new__ method afterwards.
            rb   rc   zZ[{}] Creating an instance of a deprecated class {} in {}. Called from {} line {} by {}().
rd   )r*   rh   r   r)   r,   len__mro____old_new__)r[   childri   rj   rk   rl   rm   Zloc_filero   r   r   obj_new   s     	 zdeprecated.<locals>.obj_new)rp   inspectr^   	functoolsr_   typesr`   ra   
isinstancetype__new__rt   )r=   r_   r`   ra   Znew_objrq   rv   r   ro   r   r      s    
)r   N)r,   __all__osr   r   sysr   r(   r   r.   rX   r   r   r   r   r   r   <module>   s   6D"