3
_(                 @   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 j  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    c             c   s   t j dkr"t j dkr"d V  d S t j| t j }t j|g t j|  z
d V  W d t jt j  t jt j  t j| 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   sl   d| }t j |d}i | _|| _xFt|j D ]6}|j|}| rP|rP|j|}|r.|jd| j|< q.W 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   sF   y| j | }W n tk
r"   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$   y
| j | S  tk
r   d S X d S )N)r&   r/   )r+   r2   r   r   r   get_namem   s    
zIsoCodes.get_name)N)r   
__module____qualname____doc__r.   r3   r4   r   r   r   r   r   R   s   
	c             C   sR   d| kr| j dd\}}d}n*d| kr<| j 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>   )r   r   )r7   
__author____all__r   sys
contextlibr   r   r   Z	xml.etreer   r<   r1   r   contextmanagerr#   objectr   r>   r   r   r   r   <module>   s    
"