Your IP : 216.73.216.213
B
�d{T�4 � @ sp d Z ddlmZ dZddlZddlZddlZddlmZ ddlm Z ddl
mZm
ZmZmZmZmZmZmZmZmZ yddlmZ d ZW n ek
r� d
ZY nX ddlmZmZmZmZ dd
� Z dd� Z!dd� Z"dd� Z#dd� Z$dd� Z%dd� Z&dd� Z'dd� Z(dd� Z)G d d!� d!e�Z
G d"d#� d#e�Zde_*d$d%� Z+d&d'� Z,e,e_,G d(d)� d)e�Z-d*ej.dfd+d,�Z/d-Z0dS ).a Add an abstraction level to transparently import optik classes from optparse
(python >= 2.3) or the optik package.
It also defines three new types for optik/optparse command line parser :
* regexp
argument of this type will be converted using re.compile
* csv
argument of this type will be converted using split(',')
* yn
argument of this type will be true if 'y' or 'yes', false if 'n' or 'no'
* named
argument of this type are in the form <NAME>=<VALUE> or <NAME>:<VALUE>
* password
argument of this type wont be converted but this is used by other tools
such as interactive prompt for configuration to double check value and
use an invisible field
* multiple_choice
same as default "choice" type but multiple choices allowed
* file
argument of this type wont be converted but checked that the given file exists
* color
argument of this type wont be converted but checked its either a
named color or a color specified using hexadecimal notation (preceded by a #)
* time
argument of this type will be converted to a float value in seconds
according to time units (ms, s, min, h, d)
* bytes
argument of this type will be converted to a float value in bytes
according to byte units (b, kb, mb, gb, tb)
� )�print_functionzrestructuredtext enN)�copy)�exists)
�OptionParser�Option�OptionGroup�OptionContainer�OptionValueError�OptionError�Values�
HelpFormatter�
NO_DEFAULT�
SUPPRESS_HELP)�DateTimeTF)�
splitstrip�
TIME_UNITS�
BYTE_UNITS�apply_unitsc C sB t |d�r|S y
t�|�S tk
r< td||f ��Y nX dS )zPcheck a regexp value by trying to compile it
return the compiled regexp
�patternz#option %s: invalid regexp value: %rN)�hasattr�re�compile�
ValueErrorr )�option�opt�value� r �I/opt/alt/python37/lib/python3.7/site-packages/logilab/common/optik_ext.py�check_regexpJ s
r c C sD t |ttf�r|S yt|�S tk
r> td||f ��Y nX dS )zTcheck a csv value by trying to split it
return the list of separated values
z option %s: invalid csv value: %rN)�
isinstance�list�tupler r r )r r r r r r � check_csvV s r"