Viewing: cryptdev.cpython-36.pyc
3 �N�bS( � @ s� d Z ddlZddlZddlZddlZddlZddlZddlm Z ej e�ZdZ dd� ZG dd� d�Zd d � Zddd �Zddd�Zddd�Zdd� Zdd� ZdS )z^ Salt module to manage Unix cryptsetup jobs and the crypttab file .. versionadded:: 2018.3.0 � N)�CommandExecutionErrorZcryptdevc C s t jjj� rdS dS )z) Only load on POSIX-like systems F�=The cryptdev module cannot be loaded: not a POSIX-like systemT)Fr )�salt�utils�platformZ is_windows� r r �/usr/lib/python3.6/cryptdev.py�__virtual__ s r c @ s� e Zd ZdZG dd� de�ZdZdZeefd d ��Z edd� �Z ed d� �Zdd� Zdd� Z dd� Zdd� Zedd� �Zdd� ZdS )�_crypttab_entryz� Utility class for manipulating crypttab entries. Primarily we're parsing, formatting, and comparing lines. Parsing emits dicts expected from crypttab() or raises a ValueError. c @ s e Zd ZdZdS )z_crypttab_entry.ParseErrorz;Error raised when a line isn't parsible as a crypttab entryN)�__name__� __module__�__qualname__�__doc__r r r r � ParseError+ s r �name�device�password�optionsz4{name: <12} {device: <44} {password: <22} {options} c C sp t |�dkrtdj|���|jd�r.| jd��|j� }t |�dkrL|dg7 }t |�dkrb| jd��tt||��S )N� zInvalid key array: {}�#zComment!� � zInvalid Entry!)�len� ValueError�format� startswithr �split�dict�zip)�cls�line�keys�compsr r r �dict_from_line1 s z_crypttab_entry.dict_from_linec O s | f | j ||��S )N)r# )r �args�kwargsr r r � from_lineB s z_crypttab_entry.from_linec C s | j jf |�S )N)�crypttab_formatr )r �entryr r r �dict_to_lineF s z_crypttab_entry.dict_to_linec C s | j | j�S )z&String value, only works for full repr)r) �criteria)�selfr r r �__str__J s z_crypttab_entry.__str__c C s t | j�S )zAlways works)�reprr* )r+ r r r �__repr__N s z_crypttab_entry.__repr__c s � fdd�|D �}� j f |�S )z(Returns an instance with just those keysc s i | ]}� j | |�qS r )r* )�.0�key)r+ r r � <dictcomp>T s z(_crypttab_entry.pick.<locals>.<dictcomp>)� __class__)r+ r! Zsubsetr )r+ r �pickR s z_crypttab_entry.pickc K s dd� |j � D �| _dS )z1Store non-empty, non-null values to use as filterc S s( i | ] \}}|d k rt jjj|�|�qS )N)r r �stringutils� to_unicode)r/ r0 �valuer r r r1 Y s z,_crypttab_entry.__init__.<locals>.<dictcomp>N)�itemsr* )r+ r* r r r �__init__W s z_crypttab_entry.__init__c C s t jjt jj| ��S )z%Resolve equivalent paths equivalently)�os�path�normcase�normpath)r: r r r � norm_path_ s z_crypttab_entry.norm_pathc C s6 | j |�}x&| jj� D ]\}}|| |krdS qW dS )z<Compare potentially partial criteria against a complete lineFT)r# r* r7 )r+ r r( r0 r6 r r r �matchd s z_crypttab_entry.matchN)r r r r )r r r r r r � crypttab_keysr'