
    3 d                         U d Z ddlZddlZddlmZmZ ddlmZ ddZdeddddd	fd
Z	ddZ
g Zeeeef                  ed<   d Zd ZdS )z%Some helpers for deprecation messages    N)ListTuple)ScrapyDeprecationWarning0.12c                 t    | j         j        }t          j        | d| d| d| d| d
t          d           d S )N.zC attribute is deprecated and will be no longer supported in Scrapy z, use z attribute instead   
stacklevel)	__class____name__warningswarnr   )objoldattrnewattrversioncnames        6lib/python3.11/site-packages/scrapy/utils/deprecate.py	attributer   
   s    M"EM 	H 	H7 	H 	H	H 	H$)	H 	H,3	H 	H 	H 	         TzF{cls} inherits from deprecated class {old}, please inherit from {new}.z/{cls} is deprecated, instantiate {new} instead.c	           
      P    G fddj                    | f|pi           }		 t          j                    d         }
t          j        |
d                   }||j        |	_        n.# t          $ r!}t          j        d|           Y d}~nd}~ww xY w|	S )aL  
    Return a "deprecated" class that causes its subclasses to issue a warning.
    Subclasses of ``new_class`` are considered subclasses of this class.
    It also warns when the deprecated class is instantiated, but do not when
    its subclasses are instantiated.

    It can be used to rename a base class in a library. For example, if we
    have

        class OldName(SomeClass):
            # ...

    and we want to rename it to NewName, we can do the following::

        class NewName(SomeClass):
            # ...

        OldName = create_deprecated_class('OldName', NewName)

    Then, if user class inherits from OldName, warning is issued. Also, if
    some code uses ``issubclass(sub, OldName)`` or ``isinstance(sub(), OldName)``
    checks they'll still return True if sub is a subclass of NewName instead of
    OldName.
    c                   h     e Zd ZdZdZ fdZ fdZd Z fdZ fdZ	 xZ
S )0create_deprecated_class.<locals>.DeprecatedClassNFc                 l    t                                          | |||          }| j        || _        |S N)super__new__deprecated_class)metaclsnamebasesclsdict_clsr   s        r   r   z8create_deprecated_class.<locals>.DeprecatedClass.__new__=   s6    ''//'4AAC' /+.(Jr   c                 P   | j         }|j        }||v ror|j        sfd|_                            t	          |           t	          |
          t	          	                    }r|dz  }t          j        |d           t                                          |||           d S )NT)r$   oldnewz6 (warning only on first subclass, there may be others)   r
   )	r   r   warned_on_subclassformat_clspathr   r   r   __init__)r$   r!   r"   r#   metar&   msgr   	new_classnew_class_pathold_class_pathsubclass_warn_messagewarn_category	warn_onces          r   r,   z9create_deprecated_class.<locals>.DeprecatedClass.__init__C   s    =D'Ce| 	@Y 	@43J 	@*.'+22  n55 N;; 3  
  TSSCc=Q????GGT5(33333r   c                 b     t           fdt          |          |j        fD                       S )Nc              3   B   K   | ]}                     |          V  d S r   )__subclasscheck__).0cr$   s     r   	<genexpr>zUcreate_deprecated_class.<locals>.DeprecatedClass.__instancecheck__.<locals>.<genexpr>V   s1      VVAs,,Q//VVVVVVr   )anytyper   )r$   insts   ` r   __instancecheck__zBcreate_deprecated_class.<locals>.DeprecatedClass.__instancecheck__U   s3    VVVV$t**dn9UVVVVVVr   c                       j         ur!t                                          |          S t          j        |          st          d          t          |dd          }t           fd|D                       S )Nz"issubclass() arg 1 must be a class__mro__ c              3   $   K   | ]
}|hv V  d S r   rA   )r8   r9   r$   r/   s     r   r:   zUcreate_deprecated_class.<locals>.DeprecatedClass.__subclasscheck__.<locals>.<genexpr>d   s-      ::qS),,::::::r   )r   r   r7   inspectisclass	TypeErrorgetattrr;   )r$   submroDeprecatedClassr   r/   s   `  r   r7   zBcreate_deprecated_class.<locals>.DeprecatedClass.__subclasscheck__X   s    /:: 6
 ww00555?3'' F DEEE#y"--C:::::c::::::r   c                     j         }| |u rJ                    t          | 
          t          	                    }t          j        |d            t                      j        |i |S )N)r$   r'   r(   r
   )r   r*   r+   r   r   r   __call__)r$   argskwargsr&   r.   rI   r   instance_warn_messager/   r0   r1   r3   s        r   rK   z9create_deprecated_class.<locals>.DeprecatedClass.__call__f   s    !2Ccz @+22 n55 N;; 3   c=Q????#577#T4V444r   )r   
__module____qualname__r   r)   r   r,   r>   r7   rK   __classcell__)	r   rI   rN   r/   r0   r1   r2   r3   r4   s	   @r   rI   r   8   s        "	 	 	 	 		4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4$	W 	W 	W	; 	; 	; 	; 	; 	; 	;	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5r   rI      r   NzError detecting parent module: )	r   rC   stack	getmoduler   rO   	Exceptionr   r   )r!   r/   clsdictr3   r4   r1   r0   r2   rN   deprecated_clsfrmparent_moduleerI   s    ` ``````    @r   create_deprecated_classr[      s   H65 65 65 65 65 65 65 65 65 65 65 65 65 65)- 65 65 65p %_TI<BGGN
?mooa )#a&11 	?(5(>N% ? ? ?
 	===>>>>>>>>? s   AA8 8
B#BB#c                 ,    ||S | j          d| j         S )Nr   )rO   r   )r$   forceds     r   r+   r+      s'     n--s|---r   DEPRECATION_RULESc                     t           D ]k\  }}t          | t                    rQ|                     |          r<|                     ||d          }t          j        d|  d| dt                     |c S l| S )z=Update a deprecated path from an object with its new locationrR   `z` class is deprecated, use `z	` instead)r^   
isinstancestr
startswithreplacer   r   r   )pathprefixreplacementnew_paths       r   update_classpathri      s    0  dC   	T__V%<%< 	||FK;;HMIDIIhIII(   OOOKr   c                 ^    t          ||          }t          | |          }|j        |j        uS )a  
    Return True if a method named ``method_name`` of a ``base_class``
    is overridden in a ``subclass``.

    >>> class Base:
    ...     def foo(self):
    ...         pass
    >>> class Sub1(Base):
    ...     pass
    >>> class Sub2(Base):
    ...     def foo(self):
    ...         pass
    >>> class Sub3(Sub1):
    ...     def foo(self):
    ...         pass
    >>> class Sub4(Sub2):
    ...     pass
    >>> method_is_overridden(Sub1, Base, 'foo')
    False
    >>> method_is_overridden(Sub2, Base, 'foo')
    True
    >>> method_is_overridden(Sub3, Base, 'foo')
    True
    >>> method_is_overridden(Sub4, Base, 'foo')
    True
    )rF   __code__)subclass
base_classmethod_namebase_method
sub_methods        r   method_is_overriddenrq      s3    6 *k22K;//Jz':::r   )r   r   )__doc__rC   r   typingr   r   scrapy.exceptionsr   r   r[   r+   r^   rb   __annotations__ri   rq   rA   r   r   <module>rv      s    + + +           6 6 6 6 6 6    *bKj j j jZ. . . . ,. 4c3h( - - -
 
 
; ; ; ; ;r   