
    hP                     d   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJ	r	  SSK
JrJr  SSKJrJr  SSKJr  SSKJr  \" \R,                  " S5      5      rS	 rS3S
 jrS4S jrS5S jrS rS r\rS3S jr " S S\ 5      r! " S S\"5      r# " S S\#5      r$ " S S\#5      r%S r&S r'S r(S\\)   S\*4S jr+S r,S r-S \\R\                  \\*   4   S!\)S\*4S" jr/S# r0S!\)S\*4S$ jr1 " S% S&5      r2S' r3S( r4S3S) jr5S3S* jr6S+ r7S, r8S- r9S. r:S/ r;\8SSSSS4S0 jr</ S1Qr=\=R}                  S25        g)6zt
Standardized versions of various cool and/or strange things that you can do
with Python's reflection capabilities.
    N)deque)IOBaseStringIO)TypeUnion)nativeString)_fullyQualifiedName c                 P    0 n[        XU5        [        UR                  5       5      $ )a  
Given a class object C{classObj}, returns a list of method names that match
the string C{prefix}.

@param classObj: A class object from which to collect method names.

@param prefix: A native string giving a prefix.  Each method with a name
    which begins with this prefix will be returned.
@type prefix: L{str}

@return: A list of the names of matching methods of C{classObj} (and base
    classes of C{classObj}).
@rtype: L{list} of L{str}
)addMethodNamesToDictlistkeys)classObjprefixdcts      ]/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/python/reflect.pyprefixedMethodNamesr      s$     C/
    c                 Z   U R                    H  n[        XAX#5        M     Ub  X0R                   ;   az  U R                  R                  5        H[  u  pVU[	        U5      S n[        U5      [        R                  L d  M1  US[	        U5       U:X  d  ME  [	        U5      (       d  MW  SX'   M]     gg)a  
This goes through C{classObj} (and its bases) and puts method names
starting with 'prefix' in 'dict' with a value of 1. if baseClass isn't
None, methods will only be added if classObj is-a baseClass

If the class in question has the methods 'prefix_methodname' and
'prefix_methodname2', the resulting dict should look something like:
{"methodname": 1, "methodname2": 1}.

@param classObj: A class object from which to collect method names.

@param dict: A L{dict} which will be updated with the results of the
    accumulation.  Items are added to this dictionary, with method names as
    keys and C{1} as values.
@type dict: L{dict}

@param prefix: A native string giving a prefix.  Each method of C{classObj}
    (and base classes of C{classObj}) with a name which begins with this
    prefix will be returned.
@type prefix: L{str}

@param baseClass: A class object at which to stop searching upwards for new
    methods.  To collect all method names, do not pass a value for this
    parameter.

@return: L{None}
N   )	__bases__r   __dict__itemslentypetypesFunctionType)r   dictr   	baseClassbasenamemethodoptNames           r   r   r   0   s    8 ""T; # I););;$--335LD3v;=)Gf!3!33-CK(F2\\ ! 6 <r   c                 P    0 n[        XU5        [        UR                  5       5      $ )ay  
Given an object C{obj}, returns a list of method objects that match the
string C{prefix}.

@param obj: An arbitrary object from which to collect methods.

@param prefix: A native string giving a prefix.  Each method of C{obj} with
    a name which begins with this prefix will be returned.
@type prefix: L{str}

@return: A list of the matching method objects.
@rtype: L{list}
)accumulateMethodsr   values)objr   r   s      r   prefixedMethodsr(   Z   s$     Cc'

r   c                    U(       d  U R                   nUR                   H  nU[        Ld  M  [        XX$5        M     UR                  R                  5        Hd  u  pVU[        U5      S n[        U5      [        R                  L d  M1  US[        U5       U:X  d  ME  [        U5      (       d  MW  [        X5      X'   Mf     g)a  
Given an object C{obj}, add all methods that begin with C{prefix}.

@param obj: An arbitrary object to collect methods from.

@param dict: A L{dict} which will be updated with the results of the
    accumulation.  Items are added to this dictionary, with method names as
    keys and corresponding instance method objects as values.
@type dict: L{dict}

@param prefix: A native string giving a prefix.  Each method of C{obj} with
    a name which begins with this prefix will be returned.
@type prefix: L{str}

@param curClass: The class in the inheritance hierarchy at which to start
    collecting methods.  Collection proceeds up.  To collect all methods
    from C{obj}, do not pass a value for this parameter.

@return: L{None}
N)	__class__r   objectr%   r   r   r   r   r   r   getattr)r'   r   r   curClassr    r!   r"   r#   s           r   r%   r%   m   s    * =="" vc6 # !))//1s6{}%&\U///mF$.W#C.DM 2r   c                 p    [        U 5      nU R                  S5      SS nUnU H  n[        X45      nM     U$ )z!
Return a module given its name.
.r   N)
__import__splitr,   )r!   topLevelpackagesmps        r   namedModuler6      s?     $Hzz#qr"HAAM Hr   c                 z    U R                  S5      n[        SR                  USS 5      5      n[        X!S   5      $ )z)
Get a fully named module-global object.
r/   N)r1   r6   joinr,   )r!   
classSplitmodules      r   namedObjectr<      s9     CJ*Sb/23F6b>**r   c                 >     [        U 5      $ ! [         a    Us $ f = f)aK  
Try to import a module given its name, returning C{default} value if
C{ImportError} is raised during import.

@param name: Module name as it would have been passed to C{import}.
@type name: C{str}.

@param default: Value returned in case C{ImportError} is raised while
    importing the module.

@return: Module or default value.
)r6   ImportError)r!   defaults     r   requireModuler@      s&    4   s   
 c                       \ rS rSrSrSrg)_NoModuleFound   z*
No module was found because none exists.
 N__name__
__module____qualname____firstlineno____doc____static_attributes__rD   r   r   rB   rB          r   rB   c                       \ rS rSrSrSrg)InvalidName   z?
The given name is not a dot-separated list of Python objects.
rD   NrE   rD   r   r   rN   rN      rL   r   rN   c                       \ rS rSrSrSrg)ModuleNotFound   zS
The module associated with the given name doesn't exist and it can't be
imported.
rD   NrE   rD   r   r   rQ   rQ          r   rQ   c                       \ rS rSrSrSrg)ObjectNotFound   zS
The object associated with the given name doesn't exist and it can't be
imported.
rD   NrE   rD   r   r   rU   rU      rS   r   rU   c                     [        U 5      $ ! [         an    [        R                  " 5       u  pnU(       aD  UR                  R
                  S   nX@:X  a  UR                  U5      eUR                  nU(       a  MD  [        5       ef = f)a  
Import the given name as a module, then walk the stack to determine whether
the failure was the module not existing, or some code in the module (for
example a dependent import) failing.  This can be helpful to determine
whether any actual application code was run.  For example, to distiguish
administrative error (entering the wrong module name), from programmer
error (writing buggy code in a module that fails to import).

@param importName: The name of the module to import.
@type importName: C{str}
@raise Exception: if something bad happens.  This can be any type of
    exception, since nobody knows what loading some arbitrary code might
    do.
@raise _NoModuleFound: if no module was found.
rF   )	r0   r>   sysexc_infotb_frame	f_globalswith_tracebacktb_nextrB   )
importNameexcTypeexcValueexcTracebackexecNames        r   _importAndCheckStackrc      s~     	*%% *-,,.'<#,,66zBH%--l;;'//L	 l
 s   
 A+B:Bc                    U (       d  [        S5      eU R                  S5      nSU;   a  [        SU < 35      eSnUSS nU(       d[  U(       a  SR                  U5      n [        U5      nO-[        U5      S:X  a  [        SU < 35      e[        U < S35      eU(       d  M[  UnUSS  H  n[        XV5      nM     U$ ! [         a    UR                  5          N@f = f)	a_  
Retrieve a Python object by its fully qualified name from the global Python
module namespace.  The first part of the name, that describes a module,
will be discovered and imported.  Each subsequent part of the name is
treated as the name of an attribute of the object specified by all of the
name which came before it.  For example, the fully-qualified name of this
object is 'twisted.python.reflect.namedAny'.

@type name: L{str}
@param name: The name of the object to return.

@raise InvalidName: If the name is an empty string, starts or ends with
    a '.', or is otherwise syntactically incorrect.

@raise ModuleNotFound: If the name is syntactically correct but the
    module it specifies cannot be imported because it does not appear to
    exist.

@raise ObjectNotFound: If the name is syntactically correct, includes at
    least one '.', but the module it specifies cannot be imported because
    it does not appear to exist.

@raise AttributeError: If an attribute of an object along the way cannot be
    accessed, or a module along the way is not found.

@return: the Python object identified by 'name'.
zEmpty module namer/   r
   zMname must be a string giving a '.'-separated list of Python identifiers, not Nr   zNo module named z does not name an object)
rN   r1   r9   rc   rB   popr   rQ   rU   r,   )r!   namestopLevelPackagemoduleNames	trialnamer'   ns          r   namedAnyrk      s    8 -..JJsOE
 
U{%),
 	

 O(K-I""6y"A 5zQ$'7x%@AA$x/G%HII o C12Yco  J " "!"s    B= =CCc                    [        U [        5      (       a  SnOSn[        R                  R	                  U 5      n[        R                  R                  U 5      nU(       d"  [        R                  R                  U SS 5      n[        [        R                  R                  U5      S   5      n [        R                  R                  U5      n[        R                  R                  [        R                  R                  X!5      5      (       aB  SR                  [        [        R                  R                  U5      5      [        U5      5      nO U$ M  )a-  
Convert a name in the filesystem to the name of the Python module it is.

This is aggressive about getting a module name back from a file; it will
always return a string.  Aggressive means 'sometimes wrong'; it won't look
at the Python path or try to do any error checking: don't use this method
unless you already know that the filename you're talking about is a Python
module.

@param fn: A filesystem path to a module or package; C{bytes} on Python 2,
    C{bytes} or C{unicode} on Python 3.

@return: A hopefully importable module name.
@rtype: C{str}
s   __init__.pyz__init__.pyNr8   r   z{}.{})
isinstancebytesospathabspathbasenamer   splitextdirnameexistsr9   format)fninitPyfullNamer    modNames        r   filenameToModuleNamer{   9  s      "ewwr"H77BDww3B(277++D1!45G
77??8,77>>"'',,x899nnRWW--h78W%G
 N r   clazzreturnc                 :    U R                   S-   U R                  -   $ )z%
Return full import path of a class.
r/   )rG   rF   )r|   s    r   qualr   _  s     c!ENN22r   c                 R     U R                   $ ! [         a    [        U 5      s $ f = fN)r*   BaseExceptionr   )xs    r   _determineClassr   f  s)    {{ Aws    &&c                     [        U 5      n UR                  $ ! [         a/     [        U5      s $ ! [         a    S[	        U5      -  s s $ f = ff = f)Nz<BROKEN CLASS AT 0x%x>)r   rF   r   strid)r   cs     r   _determineClassNamer   m  sV    A4zz 4	4q6M 	4+be33	44s)    
A
1AA	AAA	formatteroc                     [        5       n[        R                  " US9  [        U5      nUR	                  5       nSR                  U[        U5      U R                  U5      $ )aU  
Helper function for L{safe_repr} and L{safe_str}.

Called when C{repr} or C{str} fail. Returns a string containing info about
C{o} and the latest exception.

@param formatter: C{str} or C{repr}.
@type formatter: C{type}
@param o: Any object.

@rtype: C{str}
@return: A string containing information about C{o} and the raised
    exception.
)filez*<{} instance at 0x{:x} with {} error:
 {}>)r   	traceback	print_excr   getvaluerv   r   rF   )r   r   io	classNametbValues        r   _safeFormatr   x  sW     
BR #A&IkkmG8??
1	 r   c                 Z     [        U 5      $ ! [         a    [        [         U 5      s $ f = f)z
Returns a string representation of an object, or a string containing a
traceback, if that object's __repr__ raised an exception.

@param o: Any object.

@rtype: C{str}
)reprr   r   r   s    r   	safe_reprr     s,    $Aw $4##$s   
 **c                     [        U [        5      (       a   U R                  S5      $  [	        U 5      $ ! [         a     Nf = f! [         a    [        [        U 5      s $ f = f)z
Returns a string representation of an object, or a string containing a
traceback, if that object's __str__ raised an exception.

@param o: Any object.
zutf-8)rm   rn   decoder   r   r   r   s    r   safe_strr     sd     !U	88G$$#1v  		  #3""#s    4 
A 
A AA! A!c                   $    \ rS rSrSrS rS rSrg)QueueMethodi  z.
I represent a method that doesn't exist yet.
c                     Xl         X l        g r   )r!   calls)selfr!   r   s      r   __init__QueueMethod.__init__  s    	
r   c                 R    U R                   R                  U R                  U45        g r   )r   appendr!   )r   argss     r   __call__QueueMethod.__call__  s    

499d+,r   )r   r!   N)rF   rG   rH   rI   rJ   r   r   rK   rD   r   r   r   r     s    -r   r   c                     [        [        R                  " X R                  5      5      S-   U R                  -   n[	        U5      U La  [        SU  SU S35      eU$ )Nr/   zCouldn't find z as )r   picklewhichmodulerF   r<   	Exception)funcqualNames     r   fullFuncNamer     sU    6%%dMM:;cADMMQH8D(.d8*A>??Or   c                     [        U 5      $ )z+
Return the class or type of object 'obj'.
r   )r'   s    r   getClassr     s     9r   c                     U R                    H  n[        XAU5        M     Ub  X0R                   ;   a,  UR                  U R                  R	                  U0 5      5        gg)a  
Accumulate all attributes of a given name in a class hierarchy into a single dictionary.

Assuming all class attributes of this name are dictionaries.
If any of the dictionaries being accumulated have the same key, the
one highest in the class hierarchy wins.
(XXX: If "highest" means "closest to the starting class".)

Ex::

  class Soy:
    properties = {"taste": "bland"}

  class Plant:
    properties = {"colour": "green"}

  class Seaweed(Plant):
    pass

  class Lunch(Soy, Seaweed):
    properties = {"vegan": 1 }

  dct = {}

  accumulateClassDict(Lunch, "properties", dct)

  print(dct)

{"taste": "bland", "colour": "green", "vegan": 1}
N)r   accumulateClassDictupdater   get)r   attradictr   r    s        r   r   r     sS    > ""D. #I););;X&&**445 <r   c                     U R                    H  n[        XAU5        M     Ub  X0R                   ;   a,  UR                  U R                  R	                  U/ 5      5        gg)z
Accumulate all attributes of a given name in a class hierarchy into a single list.

Assuming all class attributes of this name are lists.
N)r   accumulateClassListextendr   r   )r   r   listObjr   r    s        r   r   r     sS     ""D0 #I););;x((,,T267 <r   c                     XL $ r   rD   abs     r   isSamer     s	    6Mr   c                 
    X:H  $ r   rD   r   s     r   isLiker     s	    6Mr   c                 B    [        [        R                  U [        S5      $ )Nzsys.modules)objgreprX   modulesr   )goals    r   modgrepr   
  s    3;;fm<<r   c                     [        U 5      UL $ r   r   )startr   s     r   isOfTyper     s    ;$r   c                 "    [        X[        5      $ r   )r   r   )r   ts     r   findInstancesr     s    5X&&r   c                 r   Uc  / nUc  0 nU" X5      (       a  UR                  U5        [        U 5      U;   a  U[        U 5         U L a  gUb  US:X  a  gUS-  nX[        U 5      '   XEXg4n[        U [        5      (       aY  U R	                  5        HC  u  p[        XX#S-   [        U
5      -   S-   /UQ76   [        XX#S-   [        U	5      -   S-   /UQ76   ME     U$ [        U [        [        [        45      (       a8  [        U 5       H'  u  p[        X   XUS-   [        U5      -   S-   /UQ76   M)     U$ [        U [        R                  5      (       a]  [        U R                  XUS-   /UQ76   [        U R                  XUS	-   /UQ76   [        U R                  R                   XUS
-   /UQ76   U$ [#        U S5      (       a8  U R$                  R	                  5        H  u  p[        XX#S-   U	-   /UQ76   M     U$ [        U [&        R(                  5      (       a  [        U " 5       XUS-   /UQ76   U$ [        U [        [*        [        R,                  [        R.                  [0        [2        [5        S5      [6        45      (       d  [5        U 5      R8                  S;   a   U$ U(       a  [;        S[5        U 5      U 5        U$ )a.  
L{objgrep} finds paths between C{start} and C{goal}.

Starting at the python object C{start}, we will loop over every reachable
reference, tring to find the python object C{goal} (i.e. every object
C{candidate} for whom C{eq(candidate, goal)} is truthy), and return a
L{list} of L{str}, where each L{str} is Python syntax for a path between
C{start} and C{goal}.

Since this can be slightly difficult to visualize, here's an example::

    >>> class Holder:
    ...     def __init__(self, x):
    ...         self.x = x
    ...
    >>> start = Holder({"irrelevant": "ignore",
    ...                 "relevant": [7, 1, 3, 5, 7]})
    >>> for path in objgrep(start, 7):
    ...     print("start" + path)
    start.x['relevant'][0]
    start.x['relevant'][4]

This can be useful, for example, when debugging stateful graphs of objects
attached to a socket, trying to figure out where a particular connection is
attached.

@param start: The object to start looking at.

@param goal: The object to search for.

@param eq: A 2-argument predicate which takes an object found by traversing
    references starting at C{start}, as well as C{goal}, and returns a
    boolean.

@param path: The prefix of the path to include in every return value; empty
    by default.

@param paths: The result object to append values to; a list of strings.

@param seen: A dictionary mapping ints (object IDs) to objects already
    seen.

@param showUnknowns: if true, print a message to C{stdout} when
    encountering objects that C{objgrep} does not know how to traverse.

@param maxDepth: The maximum number of object references to attempt
    traversing before giving up.  If an integer, limit to that many links,
    if C{None}, unlimited.

@return: A list of strings representing python object paths starting at
    C{start} and terminating at C{goal}.
Nr   r   {}[]z	.__self__z	.__func__z.__self__.__class__r   r/   z())wrapper_descriptormethod_descriptormember_descriptorgetset_descriptorzunknown type)r   r   rm   r   r   r   r   r   tupler   	enumerater   r   
MethodType__self____func__r*   hasattrr   weakrefReferenceTypeintr   BuiltinMethodType	RegexTypefloatr   r   rF   print)r   r   eqrp   pathsseenshowUnknownsmaxDepthr   kvidx_elems                r   r   r     s   | }|	%T	%yD5	?e#q=AEO 0D%KKMDAARd1g!5!;CdCARd1g!5!;CdC "H LC 
ED%/	0	0#E*JCEJ$*s3x*?#*EMM +@ L= 
E5++	,	,$*<DtD$*<DtD(($D;P4PXSWX6 L5 

	#	#NN((*DAARa7$7 +2 L/ 
E700	1	14$;66, L+ 
##J		

 
 
e		 " 
 	 L 
nd5k51Lr   )rN   rQ   rU   r   r6   r<   
namedClassrk   r@   r   r   r   r   r(   r%   r   r   r   r   r   r   r   r   r   r   r   r{   fullyQualifiedNamer   r   )r
   )r
   N)?rJ   ro   r   rerX   r   r   r   collectionsr   r   r   r   typingr   r   twisted.python.compatr   twisted.python.deprecater	   r   r   compiler   r   r   r(   r%   r6   r<   r   r@   r   rB   
ValueErrorrN   rQ   rU   rc   rk   r{   r+   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __all__removerD   r   r   <module>r      s  
 
  	 
       . NB 	('"T&(/V	+ 
&Y * [ [ 8=@#L3V 3 345!3!3T#Y!>? F s 6$# #3 #(
- 
-"6J	8=' 	
	tnB y r   