
    :j                         d Z ddlmZ ddlmZmZmZ e G d d             Ze G d de             Ze G d d	e             Z	e G d
 de             Z
e G d de             Ze G d d             Zy)z1
Segment types for regex pattern representation.
    )	dataclass)ListSetUnionc                   .    e Zd ZU dZdZeed<   dZeed<   y)Segmentz&Base class for regex pattern segments.r   positionprefix_lengthN)__name__
__module____qualname____doc__r	   int__annotations__r
        5/root/.openclaw/workspace/harvester/refine/segment.pyr   r      s    0HcM3r   r   c                   ,    e Zd ZU dZdZeed<   defdZy)FixedSegmentzFixed string segment. contentreturnc                 ,    t        | j                        S N)lenr   selfs    r   __len__zFixedSegment.__len__   s    4<<  r   N)	r   r   r   r   r   strr   r   r   r   r   r   r   r      s    GS! !r   r   c                       e Zd ZU dZdZee   ed<   dZe	ed<   dZ
ee	ef   ed<   dZeed<   dZeed	<   d
Zeed<   dZeed<   dZee   ed<   d Zede	fd       ZdefdZdefdZdefdZdefdZy)CharClassSegmentz)Character class segment with quantifiers.Ncharset   
min_length
max_lengthr   original_quantifieroriginal_charset_strFcase_sensitiveg        valueeffective_charsetc                 r    | j                   t               | _         | j                  t               | _        y y r   )r"   setr*   r   s    r   __post_init__zCharClassSegment.__post_init__*   s0    <<5DL!!)%(UD" *r   r   c                 X   | j                   t        d      k(  rt        d| j                  dz         }nt	        | j                         }d}t        | j                        }t        |d      }t        | j                  |dz         D ]  }||z  dkD  r|dz  } n
|||z  z  } t        |d      S )z&Calculate total possible combinations.inf2      r   
   r#   i@B )r%   floatminr$   r   r   r"   range)r   effective_maxtotalcharset_sizemax_calc_lengthlengths         r   combinationszCharClassSegment.combinations0   s     ??eEl*DOOb$89M0M4<<( mR0DOO_q-@A 	*FV#g- \6))E		* 5'""r   c                     | j                   sy| j                   j                  d      rU| j                   j                  d      r:| j                   dd }d|v xr% |j                  d      d   j	                         dk7  S y)z*Check if quantifier has range like {8,12}.F{}r#   ,r   r&   
startswithendswithsplitstripr   r   s     r   	has_rangezCharClassSegment.has_rangeG   sv    ''##..s38P8P8Y8YZ]8^..q4G'>IgmmC&8&;&A&A&Cr&IIr   c                    | j                   sy| j                   dk(  ry| j                   j                  d      rU| j                   j                  d      r:| j                   dd }d|v xr% |j                  d      d   j	                         d	k(  S y)
z/Check if quantifier has minimum like {8,} or +.F+Tr=   r>   r#   r?   r@   r   rA   rF   s     r   has_minzCharClassSegment.has_minP   s    ''##s*##..s38P8P8Y8YZ]8^..q4G'>IgmmC&8&;&A&A&Cr&IIr   c                     | j                   s$| j                  | j                  cxk(  xr dk(  S c S | j                   j                  d      r.| j                   j	                  d      r| j                   dd }d|vS y)z)Check if quantifier is specific like {8}.r#   r=   r>   r?   r@   F)r&   r$   r%   rB   rC   rF   s     r   is_specificzCharClassSegment.is_specific[   sq    ''??doo:::::##..s38P8P8Y8YZ]8^..q4Gg%%r   c                     | j                   sy| j                   j                  d      xr | j                   j                  d       S )z:Check if this is a positive character class (not negated).Tz[^])r'   rB   rC   r   s    r   is_positive_classz"CharClassSegment.is_positive_classd   s?    ((--88>j4C\C\CeCefiCjkkr   )r   r   r   r   r"   r   r   r   r$   r   r%   r   r3   r&   r'   r(   boolr)   r*   r-   propertyr;   rG   rJ   rL   rO   r   r   r   r!   r!      s    3GSXJ$%Jc5j!%!! "#" ND E5"&s3x&+ #c # #,4 	 	T l4 lr   r!   c                   D    e Zd ZU dZdZee   ed<   d Zdeee      fdZ	y)OptionalSegmentzOptional segment (?:...)?Nr   c                 ,    | j                   g | _         y y r   r   r   s    r   r-   zOptionalSegment.__post_init__q       <<DL  r   r   c                     g | j                   gS )z"Return empty and content variants.rU   r   s    r   variantszOptionalSegment.variantsu   s    DLL!!r   )
r   r   r   r   r   r   r   r   r-   rX   r   r   r   rS   rS   k   s-    #!GT']!"$tG}- "r   rS   c                   L    e Zd ZU dZdZee   ed<   dZe	ed<   d Z
dee   fdZy)	GroupSegmentzGroup segment (?:...) or (...)Nr   F	capturingc                 ,    | j                   g | _         y y r   rU   r   s    r   r-   zGroupSegment.__post_init__   rV   r   r   c                     | j                   S )zFlatten group content.rU   r   s    r   flattenzGroupSegment.flatten   s    ||r   )r   r   r   r   r   r   r   r   r[   rP   r-   r^   r   r   r   rZ   rZ   z   s2    (!GT']!Itg r   rZ   c                   F    e Zd ZU dZee   ed<   ee   ed<   eed<   e	ed<   y)EnumerationStrategyzStrategy for regex enumeration.segmentsoriginalr)   queriesN)
r   r   r   r   r   r!   r   r   r3   r   r   r   r   r`   r`      s%    )#$$7mLLr   r`   N)r   dataclassesr   typingr   r   r   r   r   r!   rS   rZ   r`   r   r   r   <module>rf      s    " # #    !7 ! ! Jlw Jl JlZ "g " " 7     r   