U
    ̋_(                     @   s   d Z dZdZddlZddlZddlZddlZddlZddlZddl	m
Z
 ejdkrXdZndZd	d
 Zejdd ZG dd deZdd ZdS )z|Module with little helper functions and classes:

deprecated - decorator to emit a warning if a depreacted function is used
z%Sebastian Heinlein <devel@glatzor.de>)
deprecatedIsoCodes    N)ElementTree3gettextZugettextc                    s   t   fdd}|S )zThis is a decorator which can be used to mark functions
    as deprecated. It will result in a warning being emitted
    when the function is used.

    Taken from http://wiki.python.org/moin/PythonDecoratorLibrary
    #GeneratingDeprecationWarnings
    c                     s2   t jdd ji t jj jjd d  | |S )Nz)Call to deprecated function %(funcname)s.funcname   )categoryfilenamelineno)warningswarn_explicit__name__DeprecationWarning__code__co_filenameco_firstlineno)argskwargsfunc 1/usr/lib/python3/dist-packages/aptdaemon/utils.pynew_func1   s     
zdeprecated.<locals>.new_func)	functoolswraps)r   r   r   r   r   r   )   s    
r   c              
   c   s   t  dkr"t  dkr"d V  d S t | t  }t |g t |  z
d V  W 5 t t   t t   t | X d S )Nr   )osgetuidgetgidsetegid	getgroups	setgroupsseteuid)ZuidgidZ
old_groupsr   r   r   set_euid_egid?   s    


r$   c                   @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
r   zPProvides access to the iso-codes language, script and country
    database.
    Nc                 C   sf   d| }t j |d}i | _|| _t| D ]4}||}|sL|rL||}|r,|d| j|< q,d S )Nz/usr/share/xml/iso-codes/%s.xml)filename)r   _dictnormlistiterget)selfr(   tagZfallback_tagr
   ZetelementZiso_coder   r   r   __init__X   s    

zIsoCodes.__init__c                 C   sH   z| j | }W n tk
r$   Y d S X tj| jd|gd}t|t|S )NT)ZdomainZfallbackZ	languages)r'   KeyErrorr   Ztranslationr(   getattr_gettext_method)r,   valueZlocaler&   Ztransr   r   r   get_localised_named   s    
zIsoCodes.get_localised_namec                 C   s(   z| j | W S  tk
r"   Y d S X d S )N)r'   r0   )r,   r3   r   r   r   get_namem   s    zIsoCodes.get_name)N)r   
__module____qualname____doc__r/   r4   r5   r   r   r   r   r   R   s   
	r   c                 C   sR   d| kr|  dd\}}d}n*d| kr<|  dd\}}d}n| }d }}|||fS )zQReturn the name, the version number and the release of the
    specified package.=r   N/)split)packager&   versionreleaser   r   r   split_package_idt   s    r?   )r8   
__author____all__r   sys
contextlibr   r   r   Z	xml.etreer   r=   r2   r   contextmanagerr$   objectr   r?   r   r   r   r   <module>   s"   

"