
    Ngr                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZmZmZ ddlmZ erdd	lmZmZ dd
lmZ  G d deeef         Z G d de      Z G d deeef   ee      Zy)z8
Scrapy Item

See documentation in docs/topics/item.rst
    )annotations)ABCMeta)MutableMappingdeepcopy)pformat)TYPE_CHECKINGAnyNoReturn)
object_ref)IteratorKeysView)Selfc                      e Zd ZdZy)FieldzContainer of field metadataN)__name__
__module____qualname____doc__     +lib/python3.12/site-packages/scrapy/item.pyr   r      s    %r   r   c                  4     e Zd ZdZ	 	 	 	 	 	 	 	 d fdZ xZS )ItemMetaz~Metaclass_ of :class:`Item` that handles field definitions.

    .. _metaclass: https://realpython.com/python-metaclasses
    c                X   |j                  dd       }t        d |D              }t        |   | d|z   ||      }t	        |di       }i }t        |      D ]1  }	t	        ||	      }
t        |
t              r|
||	<   %|	|v s*||	   ||	<   3 ||d<   ||d<   |||d<   t        |   | |||      S )N__classcell__c              3  N   K   | ]  }t        |d       s|j                    yw)_classN)hasattrr   ).0bases     r   	<genexpr>z#ItemMeta.__new__.<locals>.<genexpr>&   s     S%$74;R$++%s   %%x_fieldsr   )poptuplesuper__new__getattrdir
isinstancer   )mcs
class_namebasesattrs	classcell	new_basesr   r$   	new_attrsnv	__class__s              r   r(   zItemMeta.__new__"   s     IIot4	S%SS	dZ&7EJ2.	VA"A!U#q	e$Qx	!  %	($	( )2Io&wsJyAAr   )r-   strr.   ztuple[type, ...]r/   zdict[str, Any]returnr   )r   r   r   r   r(   r   r5   s   @r   r   r      s8    
BB%5B>LB	B Br   r   c                       e Zd ZU dZded<   ddZddZddZddZddZ	d fd	Z
dd
ZddZej                  ZddZddZddZddZ xZS )Itema  Base class for scraped items.

    In Scrapy, an object is considered an ``item`` if it's supported by the
    `itemadapter`_ library. For example, when the output of a spider callback
    is evaluated, only such objects are passed to :ref:`item pipelines
    <topics-item-pipeline>`. :class:`Item` is one of the classes supported by
    `itemadapter`_ by default.

    Items must declare :class:`Field` attributes, which are processed and stored
    in the ``fields`` attribute. This restricts the set of allowed field names
    and prevents typos, raising ``KeyError`` when referring to undefined fields.
    Additionally, fields can be used to define metadata and control the way
    data is processed internally. Please refer to the :ref:`documentation
    about fields <topics-items-fields>` for additional information.

    Unlike instances of :class:`dict`, instances of :class:`Item` may be
    :ref:`tracked <topics-leaks-trackrefs>` to debug memory leaks.

    .. _itemadapter: https://github.com/scrapy/itemadapter
    zdict[str, Field]r$   c                h    i | _         |s|r't        |i |j                         D ]
  \  }}|| |<    y y N)_valuesdictitems)selfargskwargskr4   s        r   __init__zItem.__init__U   s=    ')6d-f-3351Q 6 r   c                     | j                   |   S r<   r=   r@   keys     r   __getitem__zItem.__getitem__[   s    ||C  r   c                    || j                   v r|| j                  |<   y t        | j                  j                   d|       )Nz does not support field: )r$   r=   KeyErrorr5   r   )r@   rH   values      r   __setitem__zItem.__setitem__^   s?    $++ %DLLdnn5566OPSuUVVr   c                    | j                   |= y r<   rF   rG   s     r   __delitem__zItem.__delitem__d   s    LLr   c                R    || j                   v rt        d|d      t        |      )N	Use item[z] to get field value)r$   AttributeError)r@   names     r   __getattr__zItem.__getattr__g   s.    4;; 9TH4H!IJJT""r   c                l    |j                  d      st        d|d|d      t        |   ||       y )N_rQ   z] = z to set field value)
startswithrR   r'   __setattr__)r@   rS   rL   r5   s      r   rX   zItem.__setattr__l   s9    s# 9THD	AT!UVVD%(r   c                ,    t        | j                        S r<   )lenr=   r@   s    r   __len__zItem.__len__q   s    4<<  r   c                ,    t        | j                        S r<   )iterr=   r[   s    r   __iter__zItem.__iter__t   s    DLL!!r   c                6    | j                   j                         S r<   )r=   keysr[   s    r   ra   z	Item.keysy   s    ||  ""r   c                *    t        t        |             S r<   )r   r>   r[   s    r   __repr__zItem.__repr__|   s    tDz""r   c                $    | j                  |       S r<   r8   r[   s    r   copyz	Item.copy   s    ~~d##r   c                    t        |       S )z-Return a :func:`~copy.deepcopy` of this item.r   r[   s    r   r   zItem.deepcopy   s    ~r   )rA   r
   rB   r
   )rH   r6   r7   r
   )rH   r6   rL   r
   r7   None)rH   r6   r7   rg   )rS   r6   r7   r   )rS   r6   rL   r
   r7   rg   )r7   int)r7   zIterator[str])r7   zKeysView[str])r7   r6   )r7   r   )r   r   r   r   __annotations__rD   rI   rM   rO   rT   rX   r\   r_   r   __hash__ra   rc   re   r   r   r8   s   @r   r:   r:   9   sZ    2 !W#
)
!" ""H##$r   r:   )	metaclassN)r   
__future__r   abcr   collections.abcr   re   r   pprintr   typingr	   r
   r   scrapy.utils.trackrefr   r   r   typing_extensionsr   r>   r6   r   r   r:   r   r   r   <module>rs      sl    #  *   / / ,2 '&DcN &Bw B:K>#s(#Z8 Kr   