
    h	                     2    d dl mZ ddlmZ  G d de      Zy)   )FieldHandler   )resolve_missing_textc                       e Zd Zd Zy)AttributeHandlerc                    |j                  d      }|st        |      S |j                  |      }|st        |      S |j                  d      xs d}	|j                  |	      }
|
t        |      S t        |
      j	                         }|j	                         j	                  d      }|j                  d      }|j                  d      }|r_|]|j                  |      D cg c]  }|j	                          }}	 dt        |      cxk  rt        |      k  rn n|t        |         nd}||d	k(  rt        |      S |j                  d
      xs d	j                         j	                         }|rM	 |dk(  r$t        t        |j                  dd                  S |dk(  rt        |j                  dd            S 	 |S |S c c}w # t        $ r d}Y w xY w# t        $ r t        |      cY S w xY w)a  
        Extracts an attribute value from the first element matching `selector`.
        Supports optional splitting via `splitBy` and `splitIndex`.

        Config keys:
        - selector: CSS selector (required)
        - attribute: attribute name to read (default: "value")
        - splitBy: optional delimiter to split the raw attribute value
        - splitIndex: index to pick after splitting
        - ifMissing/defaultValue: handled via resolve_missing_text
        - cast: optional ("int"|"float") to cast final value
        selector	attributevalueNz[]()splitBy
splitIndex     castint,.float)getr   
select_onestrstripsplitr   len	Exceptionlowerr   replace)self
field_nameconfigsoupmain_values	selectors	extractedselel	attr_namerawval	val_cleansplit_bysplit_indexppartsr   s                     @/var/www/extractly/manual_agregator/parser/handlers/attribute.pyparsezAttributeHandler.parse   s    jj$'//__S!'//JJ{+6w	ffY;'// #hnnIIK%%f-	::i(jj./(1(AB(A1QWWY(AEB!78C<L7YsSXz7YE#k"23_c	 	R'// 

6"(b//177945=uY%6%6sC%@ABB7? !2!23!<== # y+ C  ! 	!  4+F334s0   !F?;0G 1(G G GGG,+G,N)__name__
__module____qualname__r0        r/   r   r      s    7r5   r   N)baser   utilsr   r   r4   r5   r/   <module>r8      s     (8| 8r5   