ó
;t/Uc           @   sÌ  d  d l  Z  d  d l Z d d l m Z m Z m Z m Z d d l m Z e j	 d ƒ e j	 d ƒ d f e j	 d ƒ e j	 d ƒ d f e j	 d	 ƒ e j	 d	 ƒ d
 f e j	 d ƒ e j	 d ƒ d f e j	 d ƒ e j	 d ƒ d f e j	 d ƒ e j	 d ƒ d f e j	 d ƒ e j	 d ƒ d f e j	 d ƒ e j	 d ƒ d f e j	 d ƒ e j	 d ƒ d f e j	 d ƒ e j	 d ƒ d f e j	 d ƒ e j	 d ƒ d f e j	 d ƒ e j	 d ƒ d f e j	 d ƒ e j	 d ƒ d f g Z
 e
 d  „ Z d! „  Z d" „  Z d d# „ Z d$ „  Z d% „  Z d& „  Z d' „  Z d( „  Z d) „  Z d* „  Z d+ „  Z d, „  Z d- „  Z d. e f d/ „  ƒ  YZ d0 e f d1 „  ƒ  YZ d2 „  Z d3 d4 „ Z d5 „  Z d6 „  Z  d7 „  Z! d8 „  Z" d9 „  Z# d S(:   iÿÿÿÿNi   (   t   REGEX_NOPASSWDt   REGEX_UNPACKt   REGEX_CONST_STRINGt   REGEX_W(   t   SQLCustomTypes   child$t   childrens   oot$t   eets   ooth$t   eeths   l[eo]af$s
   l([eo])af$s   l\1avess   sis$t   sess   man$t   mens   ife$t   ivess   eau$t   eauxs   lf$t   lvess   [sxz]$t   $t   ess   [^aeioudgkprt]h$s   (qu|[^aeiou])y$s   y$t   iest   sc         C   sO   xH | D]@ } | \ } } } | j  |  ƒ o: | j | |  ƒ } | r | Sq Wd  S(   N(   t   searcht   sub(   t   singulart   rulest   linet	   re_searcht   re_subt   replacet   plural(    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt	   pluralize   s
    ! c         C   sB   t  |  t t f ƒ r2 g  |  D] } t | ƒ ^ q St j d |  ƒ S(   Ns   ******(   t
   isinstancet   listt   tuplet   hide_passwordR    R   (   t   urit   item(    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyR       s    c         C   s   |  S(   sL   
    Validates that the given text is clean: only contains [0-9a-zA-Z_]
    (    (   t   text(    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   cleanup&   s    c         C   s   d j  d „  |  p g  Dƒ ƒ S(   Ns   , c         s   s   |  ] } t  | ƒ Vq d  S(   N(   t   str(   t   .0t   v(    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pys	   <genexpr>0   s    (   t   join(   t   valuest   row(    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   list_represent/   s    c         C   s7   |  s
 d  S|  d } x |  d D] } | | B} q W| S(   Ni    i   (   t   None(   t   orderbyt   orderby2R    (    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   xorify3   s    
c         C   s   |  o t  |  d ƒ o |  j S(   Nt   ignore_common_filters(   t   hasattrR.   (   t   query(    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   use_common_filters<   s    c         C   s   t  |  ƒ j d d ƒ S(   Nt   |s   ||(   R#   R   (   R    (    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt
   bar_escapeA   s    c         C   s   d d j  d „  |  Dƒ ƒ S(   Ns   |%s|R2   c         s   s-   |  ]# } t  | ƒ j ƒ  r t | ƒ Vq d  S(   N(   R#   t   stripR3   (   R$   R    (    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pys	   <genexpr>F   s    (   R&   (   t   items(    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt
   bar_encodeE   s    c         C   s`   t  |  d ƒ r. t  |  d ƒ r. |  j ƒ  }  n  g  |  j d ƒ D] } | j ƒ  r> t | ƒ ^ q> S(   Nt   splitt   readR2   (   R/   R8   R7   R4   t   long(   t   valuet   x(    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   bar_decode_integerI   s    c         C   s?   g  t  j |  d d !ƒ D]$ } | j ƒ  r | j d d ƒ ^ q S(   Ni   iÿÿÿÿs   ||R2   (   R   R7   R4   R   (   R:   R;   (    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   bar_decode_stringO   s    c   	      C   s®   |  j  j j |  j ƒ } t | ƒ d k r9 t d ƒ ‚ n  xn |  j ƒ  D]` } | j | ƒ } xH | j ƒ  D]: \ } } | | | k rh | j	 | | <| j
 |   Pqh qh WqF Wt S(   Ni   s   cannot update join(   t   dbt   _adaptert   tablesR0   t   lent   RuntimeErrort   selectt   _filter_fieldst	   iteritemst   idt   insertt   False(	   t   qsett   fst   archive_tablet   current_recordt
   tablenamesR(   t   fieldst   kR%   (    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   archive_recordT   s    c      !   C   s#  d d l  m } m } t |  t t f ƒ s7 |  g }  n  g  } xi |  D]a } t | | ƒ ri | j | ƒ qD t | | ƒ r™ x* | D] } | j | ƒ q WqD t d ƒ ‚ qD W| }  i  } xa |  D]Y } | j j	 ƒ  } | | k rê | | | <n  t
 | ƒ j	 ƒ  } | | k r¼ | | | <q¼ q¼ Wi  }	 d }
 xp t r—t j | ƒ } | sGPn  | | j ƒ   d |
 | | j ƒ  } | j ƒ  d d !|	 t
 |
 ƒ <|
 d 7}
 q(Wt j d d	 | ƒ j	 ƒ  } x· dC dD dE dF dG dH dI dJ dK dL dM dN dO dP dQ dR dS dT dU dV dW dX dY dZ d[ d\ d] d^ d_ d` da db g  D]O \ } } | d d	 k rS| j d2 | d3 | ƒ } n  | j | d3 | ƒ } qWt j d d	 | ƒ j	 ƒ  } t j d4 d5 | ƒ } d  } } } } } xi| j ƒ  D][} | d  k r2| d k rçt } q| r
| r
| dc k r
| } q| | k r#| | } qt d6 ƒ ‚ qÀ| d  k	 rS| d  k rS| } qÀ| d  k	 rÀ| j d7 ƒ rž| d |	 k rt d6 ƒ ‚ n  |	 | d } n- | } | j dd k rË| d k rËd; } qËn  | d k ræ| | k } nÉ| d k r| | k  } n®| d k r| | k } n“| d k r7| | k } nx| d k rR| | k } n]| d k rm| | k } nB| d0 k r”| j | j d< ƒ ƒ } n| d. k r¼| j | j d< ƒ ƒ } nó | j de k rR| d= k ré| j | ƒ } q¯| d; k r| j | ƒ } q¯| d* k r%| j | ƒ } q¯| d, k rC| j | ƒ } q¯t d> ƒ ‚ n] | j j j d? k r£| j df k r£| d= k r”| j | ƒ } q¯t d> ƒ ‚ n t d> ƒ ‚ | r¿| } n  | d  k rÔ| } n2 | d k rí| | M} n | d k r| | O} n  d  } } } } qÀqÀW| S(g   Ni   (   t   Fieldt   Tables   fields must be a list of fieldsi    s   #%ii   iÿÿÿÿs   \s+t    t   &t   andR2   t   ort   ~t   nots   ==t   =t   <t   >s   <=s   >=s   <>s   !=s   =<s   =>s    less or equal than s    greater or equal than s    equal or less than s    equal or greater than s    less or equal s    greater or equal s    equal or less s    equal or greater s    not equal to s    not equal s
    equal to s    equal s    equals s    less than s    greater than s    starts with t
   startswiths    ends with t   endswiths    not in t
   notbelongss    in t   belongss    is s    iss    %s s%   (?P<a>[\<\>\!\=])\s+(?P<b>[\<\>\!\=])s
   \g<a>\g<b>s   Invalid syntaxt   #R!   t   stringt   jsont   liket   ,t   containss   Invalid operations   google:datastores   list:integers   list:strings   list:reference(   RT   s   and(   R2   s   or(   RW   s   not(   s   ==RY   (   RZ   RZ   (   R[   R[   (   s   <=s   <=(   s   >=s   >=(   s   <>s   !=(   s   =<s   <=(   s   =>s   >=(   RY   RY   (   s    less or equal than s   <=(   s    greater or equal than s   >=(   s    equal or less than s   <=(   s    equal or greater than s   >=(   s    less or equal s   <=(   s    greater or equal s   >=(   s    equal or less s   <=(   s    equal or greater s   >=(   s    not equal to s   !=(   s    not equal s   !=(   s
    equal to RY   (   s    equal RY   (   s    equals RY   (   s    less than RZ   (   s    greater than R[   (   s    starts with s
   startswith(   s    ends with s   endswith(   s    not in R^   (   s    in s   belongs(   s    is RY   (   s   ands   or(   s   texts   strings   json(   s   texts   strings   json(   s   list:integers   list:strings   list:reference(   t   objectsRQ   RR   R   R   R   t   appendRB   t   namet   lowerR#   t   TrueR   R   t   startt   endt   groupt   reR   R   R*   R7   R\   t   typeR_   Re   t   ilikeR]   t   _dbR?   t   dbengine(   RN   R!   RQ   RR   t
   new_fieldst   fieldt   ofieldt	   field_mapt   nt	   constantst   it   mt   at   bR0   t   negt   opt   logicR    R:   t	   new_query(    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   smart_queryb   s   	 &			               
	c         C   sÍ   |  j  } |  j } t | t ƒ rC t | d ƒ r7 | j S| j } n t | t ƒ sV g  St | j ƒ rr | j |  ƒ S| j	 s t | j	 t
 ƒ r“ g  S| j	 j | g  ƒ } t | t t f ƒ sÉ | g } n  | S(   Nt	   validator(   R>   Ro   R   R   R/   R‚   R#   t   callablet   validators_methodt
   validatorst   dictt   getR   R   (   Rt   R>   t
   field_typet   field_validators(    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   auto_validatorsÚ   s     		c         C   s   |  | ƒ } | s t  | ƒ St |  d ƒ rH t |  j t  ƒ rH |  j | St |  d ƒ rs t |  j ƒ rs |  j | ƒ St  | ƒ Sd  S(   Nt   _format(   R#   R/   R   R‹   Rƒ   (   t   rRF   R(   (    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   _fieldformatñ   s    
!t	   _repr_refc           B   s    e  Z d d  „ Z d d „ Z RS(   c         C   s   | |  _  d  S(   N(   t   ref(   t   selfR   (    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   __init__þ   s    c         C   s   t  |  j | ƒ S(   N(   R   R(   (   R   R:   R(   (    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   __call__  s    N(   t   __name__t
   __module__R*   R‘   R’   (    (    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyRŽ   ý   s   t   _repr_ref_listc           B   s   e  Z d d  „ Z RS(   c      	      sõ   | s
 d  Sd d l m } d  } ˆ j j ˆ j j ‰  ‰ t ˆ  j | ƒ r® ‡  ‡ f d †  } t d t	 | ƒ d ƒ } t
 d „  g  | D] } | | | | d !ƒ ^ q… ƒ } n ˆ  ˆ j | ƒ ƒ j ˆ ƒ } | rñ d j ‡ f d †  | Dƒ ƒ pô d	 S(
   Ni   (   t   GoogleDatastoreAdapterc            s   ˆ  ˆ j  |  ƒ ƒ j ˆ ƒ S(   N(   R_   RC   (   R'   (   R>   RF   (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   count  s    i    i   c         S   s   |  | @S(   N(    (   R{   R|   (    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   <lambda>  s    s   , c         3   s$   |  ] } t  ˆ  j | j ƒ Vq d  S(   N(   R   R   RF   (   R$   R;   (   R   (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pys	   <genexpr>  s    t    (   R*   t   adaptersR–   R   Rq   t   _idR   R?   t   rangeRA   t   reduceR_   RC   R&   (   R   R:   R(   R–   t   refsR—   t   rxRy   (    (   R>   RF   R   sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyR’     s    -N(   R“   R”   R*   R’   (    (    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyR•     s   c      	   C   së   |  j  r |  j  S|  j rz |  j j d ƒ rz |  j j d ƒ d k  rz |  j d |  j j k rz |  j |  j d } t | ƒ S|  j rä |  j j d ƒ rä |  j j d ƒ d k  rä |  j d |  j j k rä |  j |  j d } t | ƒ S|  j  S(   Nt	   referencet   .i    i
   s   list:referencei   (   t	   representR>   Ro   R\   t   findR@   RŽ   R•   (   Rt   t
   referenced(    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   auto_represent  s    	1
1
s   %sc         C   s   t  j |  ƒ r |  S| |  S(   N(   R   t   match(   Rh   t   quotestr(    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   varquote_aux&  s    c         C   s   t  j |  ƒ j S(   N(   t   uuidt   UUIDt   int(   t   uuidv(    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   uuid2int*  s    c         C   s   t  t j d |  ƒ ƒ S(   NR«   (   R#   R©   Rª   (   Rw   (    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   int2uuid.  s    c         C   s   d |  | f S(   Ns   POINT (%f %f)(    (   R;   t   y(    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   geoPoint3  s    c          G   s   d d j  d „  |  Dƒ ƒ S(   Ns   LINESTRING (%s)Rd   c         s   s   |  ] } d  | Vq d S(   s   %f %fN(    (   R$   R    (    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pys	   <genexpr>8  s    (   R&   (   R   (    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   geoLine7  s    c          G   s   d d j  d „  |  Dƒ ƒ S(   Ns   POLYGON ((%s))Rd   c         s   s   |  ] } d  | Vq d S(   s   %f %fN(    (   R$   R    (    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pys	   <genexpr><  s    (   R&   (   R   (    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt
   geoPolygon;  s    ($   R©   Rn   t   regexR    R   R   R   t   classesR   t   compilet   PLURALIZE_RULESR   R   R"   R*   R)   R-   R1   R3   R6   R<   R=   RP   R   RŠ   R   t   objectRŽ   R•   R¥   R¨   R­   R®   R°   R±   R²   (    (    (    sR   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/packages/dal/pydal/helpers/methods.pyt   <module>   sN   "$												x							