Ë
    >Éi  ã                  ó  — U d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ i Zd
ed<    ej,                  d«      Z ed¬«       G d„ d«      «       Zdd„Zdddeddœ	 	 	 	 	 	 	 	 	 	 	 dd„Zdd„Zy)zDField descriptor and extraction metadata for ExtractionModel fields.é    )ÚannotationsN)Ú	dataclass)ÚCallableÚOptionalÚUnionÚcast)ÚField)Ú	FieldInfo)ÚPydanticUndefined)ÚInvalidExtractionModelzdict[int, ExtractionMetadata]Ú_FIELD_METADATA_REGISTRYé   T)Úfrozenc                  óN   — e Zd ZU dZdZded<   dZded<   dZded<   ed	d„«       Z	y)
ÚExtractionMetadatazñImmutable extraction metadata attached to a pydantic field.

    Stored in a module-level registry by Field() and retrieved by
    ExtractionModel.get_extraction_fields() via the registry key stored
    in the field's json_schema_extra.
    NúOptional[str]ÚselectorÚ	attributeú?Optional[Callable[[str], Union[str, int, float, bool, object]]]Ú	transformc                ó   — | j                   duS )z/Whether this field has a CSS or XPath selector.N)r   )Úselfs    ú\/var/www/python/tenders/Scrapper/venv/lib/python3.12/site-packages/pydoll/extractor/field.pyÚhas_selectorzExtractionMetadata.has_selector#   s   € ð }‰} DÐ(Ð(ó    )ÚreturnÚbool)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   r   Úpropertyr   © r   r   r   r      s:   … ñð #€HˆmÓ"Ø#€Iˆ}Ó#ØQU€IÐNÓUàò)ó ñ)r   r   c                ó.   — t         j                  | d«      S )aa  Retrieve and remove ExtractionMetadata from the registry by key.

    Uses pop to prevent the registry from growing indefinitely.
    Each key is consumed exactly once during model class creation.

    Args:
        key: Registry key stored in json_schema_extra['_extraction_key'].

    Returns:
        ExtractionMetadata if found, None otherwise.
    N)r   Úpop)Úkeys    r   Úpop_field_metadatar(   )   s   € ô $×'Ñ'¨¨TÓ2Ð2r   )r   r   ÚdescriptionÚdefaultr   c           	     óŽ   — | €|€t        d«      ‚t        | ||¬«      }t        |«      }t        t        t        ||d|i¬«      «      S )aô  Define extraction metadata for a model field.

    Wraps pydantic.Field() and registers ExtractionMetadata for the engine.
    Auto-detects CSS vs XPath from selector syntax (same logic as Tab.query()).

    At least one of ``selector`` or ``description`` must be provided:
    - selector only: extracted via CSS/XPath.
    - description only: metadata for future LLM extraction.
    - both: CSS extraction with LLM fallback in future auto strategy.

    Args:
        selector: CSS or XPath selector (auto-detected, like Tab.query()).
        attribute: HTML attribute to extract (default: innerText).
        description: Semantic description of the field.
        default: Default value if extraction fails. PydanticUndefined means required.
        transform: Post-processing callable applied to raw extracted string.

    Returns:
        Pydantic FieldInfo with extraction registry key in json_schema_extra.

    Raises:
        InvalidExtractionModel: If neither selector nor description is provided.
    z4Field must have at least a selector or a description)r   r   r   Ú_extraction_key)r*   r)   Újson_schema_extra)r   r   Ú_register_metadatar   r
   ÚPydanticField)r   r   r)   r*   r   Úmetadatar'   s          r   r	   r	   8   s`   € ð> Ð˜KÐ/Ü$Ð%[Ó\Ð\ä!ØØØô€Hô ˜XÓ
&€CäÜÜØØ#Ø0°#Ð6ô	
óð r   c                ó6   — t        t        «      }| t        |<   |S )z6Register ExtractionMetadata and return its unique key.)ÚnextÚ_field_id_counterr   )r0   r'   s     r   r.   r.   l   s   € ä
Ô Ó
!€CØ$,Ô˜SÑ!Ø€Jr   )r'   Úintr   zOptional[ExtractionMetadata])r   r   r   r   r)   r   r*   Úobjectr   r   r   r
   )r0   r   r   r4   )r!   Ú
__future__r   Ú	itertoolsÚdataclassesr   Útypingr   r   r   r   Úpydanticr	   r/   Úpydantic.fieldsr
   Úpydantic_corer   Úpydoll.extractor.exceptionsr   r   r"   Úcountr3   r   r(   r.   r$   r   r   ú<module>r?      s¼   ðÚ Jå "ã Ý !ß 2Ó 2å +Ý %Ý +å >ð
 ;=Ð Ð7Ó <Ø#I—O‘O AÓ&Ð ñ $Ô÷)ð )ó ð)ó$3ð" #Ø#Ø!%Ø'ØQUñ1àð1ð ð1ð ð	1ð
 ð1ð Oð1ð ó1ôhr   