
¡\\i  ã               @   sz   d  Z  d d l Z d d l Z d d l m Z d d „  Z d d „  Z d d	 „  Z d
 d „  Z d d „  Z	 d d „  Z
 d S)z- Utility functions for certbot-apache plugin é    N)Úutilc             C   s"   d d d g i } | j  |  g  ƒ S)a  Get known module dependencies.

    .. note:: This does not need to be accurate in order for the client to
        run.  This simply keeps things clean if the user decides to revert
        changes.
    .. warning:: If all deps are not included, it may cause incorrect parsing
        behavior, due to enable_mod's shortcut for updating the parser's
        currently defined modules (`.ApacheParser.add_mod`)
        This would only present a major problem in extremely atypical
        configs that use ifmod for the missing deps.

    ZsslZsetenvifZmime)Úget)Úmod_nameZdeps© r   ú</usr/lib/python3/dist-packages/certbot_apache/apache_util.pyÚget_mod_deps   s    r   c             C   s)   |  s |  j  d ƒ r d St |  ƒ d S)zÅGet file path from augeas_vhost_path.

    Takes in Augeas path and returns the file name

    :param str vhost_path: Augeas virtual host path

    :returns: filename of vhost
    :rtype: str

    z/files/Nr   )Ú
startswithÚ_split_aug_path)Ú
vhost_pathr   r   r   Úget_file_path   s    r   c             C   s   t  |  ƒ d S)zÊGet the Augeas path for a vhost with the file path removed.

    :param str vhost_path: Augeas virtual host path

    :returns: Augeas path to vhost relative to the containing file
    :rtype: str

    é   )r	   )r
   r   r   r   Úget_internal_aug_path+   s    	r   c             C   sm   |  d d … } g  } x; t  j j | ƒ sS | j d ƒ \ } } } | j | ƒ q W| d j t | ƒ ƒ f S)a:  Splits an Augeas path into a file path and an internal path.

    After removing "/files", this function splits vhost_path into the
    file path and the remaining Augeas path.

    :param str vhost_path: Augeas virtual host path

    :returns: file path and internal Augeas path
    :rtype: `tuple` of `str`

    é   Nú/)ÚosÚpathÚexistsÚ
rpartitionÚappendÚjoinÚreversed)r
   Z	file_pathZinternal_pathÚ_Zinternal_path_partr   r   r   r	   7   s    r	   c             C   sÙ   i  } t  j | |  ƒ j ƒ  } x´ t | ƒ D]¦ \ } } | d k r… t | ƒ | d k r… | | d j d ƒ } | d | | d <q+ t | ƒ d k r+ | j d ƒ r+ | d d … j d ƒ } | d | | d <q+ W| S)zÕ Parses Defines from a variable in configuration file

    :param str filepath: Path of file to parse
    :param str varname: Name of the variable

    :returns: Dict of Define:Value pairs
    :rtype: `dict`

    z-Dé   r   ú=r   N)r   Zget_var_from_fileÚsplitÚ	enumerateÚlenÚ	partitionr   )ÚfilepathZvarnameZreturn_varsZa_optsÚiÚvZ	var_partsr   r   r   Úparse_define_fileO   s    
"!r!   c               C   s   t  j t j d ƒ ƒ j d ƒ S)z< Returns an unique id to be used as a VirtualHost identifieré   zutf-8)ÚbinasciiZhexlifyr   ÚurandomÚdecoder   r   r   r   Ú	unique_idh   s    r&   )Ú__doc__r#   r   Zcertbotr   r   r   r   r	   r!   r&   r   r   r   r   Ú<module>   s   