
    \e                     (   d dl Z d dlZd dlZd Zd Zi dd dd dd	 d
d dd dd dd dej
                  dej                  dej                  dej                  dej                  dej                  dedd dd deZd Zd Zy)     Nc                      t        j                          t         t              st	        dddgd      t         fd|D              S )Nz6<all-in> must compare with a list literal string, EG "aesmmx"c              3   &   K   | ]  }|v  
 y wN ).0valxs     :/usr/lib/python3/dist-packages/oslo_utils/specs_matcher.py	<genexpr>z_all_in.<locals>.<genexpr>   s     %Csax%s   )astliteral_eval
isinstancelist	TypeErrorallr   ys   ` r   _all_inr      sJ    Aa16A B 	B%1%%%    c                 t   t        j                  |       } t        |      dk7  rt        d      t	        |       }t	        |d         }t	        |d         }||kD  rt        d      |d   dk(  r||k\  }n|d   dk(  r||kD  }nt        d	      |d
   dk(  r||k  }n|d
   dk(  r||k  }nt        d      |xr |S )N   zv<range-in> operator has to be followed by 2 space separated numeric value surrounded by brackets "range_in [ 10 20 ] "      zo<range-in> operator's first argument has to be smaller or equal to the second argument EG"range_in  ( 10 20 ] "r   [(z;The first element should be an opening bracket ("(" or "[")   ])z9The last element should be a closing bracket (")" or "]"))r   r   lenr   float)r   r   num_xnum_ynum_zloweruppers          r   	_range_inr)      s    A
1v{ ; < 	< !HE!A$KE!A$KEu} 3 4 	4 	ts{	
1 + , 	, 	ts{	
1 + , 	,?Ur   =c                 0    t        |       t        |      k\  S r   r#   r   s     r   <lambda>r-   B   s    eAh%(* r   !=c                 0    t        |       t        |      k7  S r   r,   r   s     r   r-   r-   E       uQx58+ r   <=c                 0    t        |       t        |      k  S r   r,   r   s     r   r-   r-   F   r0   r   <c                 0    t        |       t        |      k  S r   r,   r   s     r   r-   r-   G       eAhq) r   ==c                 0    t        |       t        |      k(  S r   r,   r   s     r   r-   r-   H   r0   r   >=c                 0    t        |       t        |      k\  S r   r,   r   s     r   r-   r-   I   r0   r   >c                 0    t        |       t        |      kD  S r   r,   r   s     r   r-   r-   J   r5   r   s!=s<s<=s==s>s>=<all-in><in>c                 
    || v S r   r	   r   s     r   r-   r-   T   s
    a r   <or>c                 ,     t         fd|D              S )Nc              3   (   K   | ]	  }|k(    y wr   r	   )r
   ar   s     r   r   z<lambda>.<locals>.<genexpr>U   s     0a1f0s   )anyr   s   ` r   r-   r-   U   s    #0a00 r   
<range-in>c                     t        j                  d      t        j                  d      z  t        j                  d      z  t        j                  d      z  t        j                  d      z  t        j                  d      z  t        j                  d      z  t        j                  d      z  t        j                  d	      z  t        j                  d
      z  t        j                  d      z  t        j                  d      z  t        j                  d      z  t        j                  d      z  } t        j                  d      }t        j                  d      }t        j                  d      }| |z  |z  |z   t        j                  d      z   }| |z   }||z   |z   |z   |z   }|t        j                  |      z   }t        j                  ||z         }|j	                  d        ||z  |z  |z  |z  }	|	S )a  Creates the grammar to be used by a spec matcher.

The grammar created supports the following operations.

Numerical values:
  * ``=  :`` equal to or greater than. This is equivalent to ``>=`` and is
    supported for `legacy reasons
    <http://docs.openstack.org/developer/nova/filter_scheduler.html#ComputeCapabilitiesFilter>`_
  * ``!= :`` Float/integer value not equal
  * ``<= :`` Float/integer value less than or equal
  * ``<  :`` Float/integer value less than
  * ``== :`` Float/integer value equal
  * ``>= :`` Float/integer value greater than or equal
  * ``>  :`` Float/integer value greater

String operations:
  * ``s!= :`` Not equal
  * ``s<  :`` Less than
  * ``s<= :`` Less than or equal
  * ``s== :`` Equal
  * ``s>  :`` Greater than
  * ``s>= :`` Greater than or equal

Other operations:
  * ``<all-in>  :`` All items 'in' value
  * ``<in>      :`` Item 'in' value, like a substring in a string.
  * ``<or>      :`` Logical 'or'
  * ``<range-in>:`` Range tester with customizable boundary conditions, tests
                    whether value is in the range, boundary condition could be
                    inclusve '[' or exclusive '('.

If no operator is specified the default is ``s==`` (string equality comparison)

Example operations:
 * ``">= 60"`` Is the numerical value greater than or equal to 60
 * ``"<or> spam <or> eggs"`` Does the value contain ``spam`` or ``eggs``
 * ``"s== 2.1.0"`` Is the string value equal to ``2.1.0``
 * ``"<in> gcc"`` Is the string ``gcc`` contained in the value string
 * ``"<all-in> aes mmx"`` Are both ``aes`` and ``mmx`` in the value
 * ``"<range-in> [ 10 20 ]"`` float(value) >= 10 and float(value) <= 20
 * ``"<range-in> ( 10 20 ]"`` float(value) > 10 and float(value) <= 20
 * ``"<range-in> ( 10 20 )"`` float(value) > 10 and float(value) < 20

:returns: A pyparsing.MatchFirst object. See
          https://pythonhosted.org/pyparsing/ for details on pyparsing.
    r6   r*   r.   rC   r8   r1   r:   r3   r?   r<   r>   r=   rA   r@   rB   rE   rJ   z\S+c                     dg|dd d   z   S )NrE   r   r   r	   )_s_lts      r   r-   zmake_grammar.<locals>.<lambda>   s    &AaddG1C r   )	pyparsingLiteralRegex	OneOrMoresetParseAction)
	unary_opsall_in_nary_opor_range_in_binary_opatomunaryrange_opnarydisjunctionexprs
             r   make_grammarr_   Z   s   j 	$)"3"3C"88$	 "+"3"3F";	<$	 "+"3"3D"9	: 	#	 "+!2!23!7	8 	% 		! $-#4#4U#;		< 	% 	! $-#4#4T#:	; 	% 	! $-#4#4T#:	;  &&z2N


F
#C"**<8 '#-0BBC D E!D(4/$6=HI//55D%%cDj1K CD(5047DKr   c                     t               }	 |j                  |      }t	        |      dk(  r|d   | k(  S t
        |d      } || g|dd  S # t        j                  $ r |g}Y Fw xY w)a  Match a given value to a given spec DSL.

    This uses the grammar defined by make_grammar()

    :param cmp_value: Value to be checked for match.
    :param spec: The comparison specification string, for example ``">= 70"``
                 or ``"s== string_value"``. See ``make_grammar()`` for examples
                 of a specification string.
    :returns: True if cmp_value is a match for spec. False otherwise.
    r   r   N)r_   parseStringrP   ParseExceptionr"   
op_methods)	cmp_valuespecr^   treecompare_funcs        r   matchrh      s     >D	 % 4yA~Aw)## d1g&L	-DH-- ## vs   A A$#A$)r   operatorrP   r   r)   neltleeqgtgerc   r_   rh   r	   r   r   <module>rp      s      &@ 	*	 	
+ 	
+ 	) 	
+ 	
+ 	) 
8;; 	(++  
8;;!" 
8;;#$ 	(++%& 
8;;'* +, -. 0/0 )1
8Pf.r   