
    3 d                         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  G d d	e          Z G d
 de          Z G d deee          ZdS )z8
Scrapy Item

See documentation in docs/topics/item.rst
    )ABCMeta)MutableMappingdeepcopy)pformat)Dict)
object_refc                       e Zd ZdZdS )FieldzContainer of field metadataN)__name__
__module____qualname____doc__     +lib/python3.11/site-packages/scrapy/item.pyr   r      s        %%%%r   r   c                   "     e Zd ZdZ fdZ xZS )ItemMetaz~Metaclass_ of :class:`Item` that handles field definitions.

    .. _metaclass: https://realpython.com/python-metaclasses
    c                    |                     dd           }t          d |D                       }t                                          | d|z   ||          }t	          |di           }i }t          |          D ]<}	t	          ||	          }
t          |
t                    r|
||	<   -|	|v r||	         ||	<   =||d<   ||d<   |||d<   t                                          | |||          S )N__classcell__c              3   D   K   | ]}t          |d           |j        V  dS )_classN)hasattrr   ).0bases     r   	<genexpr>z#ItemMeta.__new__.<locals>.<genexpr>   s3      SS$74;R;RS$+SSSSSSr   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4	SS%SSSSS	dZ&7EJJ2..	V 	( 	(A""A!U## (q		e ($Qx	!$	($	( 	3)2Io&wwsJyAAAr   )r   r   r   r   r"   r   r/   s   @r   r   r      sK         
B B B B B B B B Br   r   c                        e Zd ZU dZeeef         ed<   d Zd Z	d Z
d Zd Z fdZd	 Zd
 Zej        Zd Zd Zd Zd Z xZS )ItemaM  
    Base class for scraped items.

    In Scrapy, an object is considered an ``item`` if it is an instance of either
    :class:`Item` or :class:`dict`, or any subclass. For example, when the output of a
    spider callback is evaluated, only instances of :class:`Item` or
    :class:`dict` are passed to :ref:`item pipelines <topics-item-pipeline>`.

    If you need instances of a custom class to be considered items by Scrapy,
    you must inherit from either :class:`Item` or :class:`dict`.

    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.
    r   c                 r    i | _         |s|r)t          |i |                                D ]\  }}|| |<   d S d S N)_valuesdictitems)selfargskwargskr.   s        r   __init__zItem.__init__H   sc     	6 	d-f--3355  1Q	 	 r   c                     | j         |         S r4   r5   r8   keys     r   __getitem__zItem.__getitem__N   s    |C  r   c                 h    || j         v r|| j        |<   d S t          | j        j         d|           )Nz does not support field: )r   r5   KeyErrorr/   r   )r8   r@   values      r   __setitem__zItem.__setitem__Q   sF    $+ 	W %DLdn5UUPSUUVVVr   c                     | j         |= d S r4   r>   r?   s     r   __delitem__zItem.__delitem__W   s    Lr   c                 X    || j         v rt          d|d          t          |          )N	Use item[z] to get field value)r   AttributeError)r8   names     r   __getattr__zItem.__getattr__Z   s:    4; 	K !IT!I!I!IJJJT"""r   c                     |                     d          st          d|d|d          t                                          ||           d S )N_rI   z] = z to set field value)
startswithrJ   r!   __setattr__)r8   rK   rD   r/   s      r   rP   zItem.__setattr___   sZ    s## 	W !UT!U!U!U!U!UVVVD%(((((r   c                 *    t          | j                  S r4   )lenr5   r8   s    r   __len__zItem.__len__d   s    4<   r   c                 *    t          | j                  S r4   )iterr5   rS   s    r   __iter__zItem.__iter__g   s    DL!!!r   c                 4    | j                                         S r4   )r5   keysrS   s    r   rY   z	Item.keysl   s    |  """r   c                 :    t          t          |                     S r4   )r   r6   rS   s    r   __repr__zItem.__repr__o   s    tDzz"""r   c                 ,    |                      |           S r4   r0   rS   s    r   copyz	Item.copyr   s    ~~d###r   c                      t          |           S )z-Return a :func:`~copy.deepcopy` of this item.r   rS   s    r   r   zItem.deepcopyu   s    ~~r   )r   r   r   r   r   strr   __annotations__r<   rA   rE   rG   rL   rP   rT   rW   r	   __hash__rY   r[   r]   r   r   r0   s   @r   r2   r2   /   s         , e  ! ! !W W W  # # #
) ) ) ) )
! ! !" " " "H# # ## # #$ $ $      r   r2   )	metaclassN)r   abcr   collections.abcr   r]   r   pprintr   typingr   scrapy.utils.trackrefr	   r6   r   r   r2   r   r   r   <module>rh      s!          * * * * * *                   , , , , , ,& & & & &D & & &B B B B Bw B B B6H H H H H>: H H H H H Hr   