
    3Ki(                        S SK r S SKrS SKrS SKJrJr  S SKJrJrJ	r
  S SKJr  S SKJr  SSKJrJrJr  / SQr\R(                  " \5      r " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r\" 5       r " S S\5      rg)    N)ABCabstractmethod)_getattribute_Picklerwhichmodule)
ModuleType)Any   )demangleget_mangle_prefix
is_mangled)ObjNotFoundErrorObjMismatchErrorImporterOrderedImporterc                       \ rS rSrSrSrg)r      zHRaised when an importer cannot find an object by searching for its name. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       X/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/torch/package/importer.pyr   r      s    Rr   r   c                       \ rS rSrSrSrg)r      z]Raised when an importer found a different object with the same name as the user-provided one.r   Nr   r   r   r   r   r      s    gr   r   c            	           \ rS rSr% Sr\\\4   \S'   \	S\S\4S j5       r
SS\S	\S-  S\\\4   4S
 jjrS\S	\S\4S jrSrg)r      a,  Represents an environment to import modules from.

By default, you can figure out what module an object belongs by checking
__module__ and importing the result using __import__ or importlib.import_module.

torch.package introduces module importers other than the default one.
Each PackageImporter introduces a new namespace. Potentially a single
name (e.g. 'foo.bar') is present in multiple namespaces.

It supports two main operations:
    import_module: module_name -> module object
    get_name: object -> (parent module name, name of obj within module)

The guarantee is that following round-trip will succeed or throw an ObjNotFoundError/ObjMisMatchError.
    module_name, obj_name = env.get_name(obj)
    module = env.import_module(module_name)
    obj2 = getattr(module, obj_name)
    assert obj1 is obj2
modulesmodule_namereturnc                     g)zfImport `module_name` from this environment.

The contract is the same as for importlib.import_module.
Nr   selfr#   s     r   import_moduleImporter.import_module6   s    r   Nobjnamec                   ^ ^ Tc_  U(       aX  [         R                  R                  [        U5      5      c/  [	        USS5      nUb   U" 5       n[        U[        5      (       a  UmTc  [	        USS5      mTc  UR                  mT R                  UT5      n[        U5      n T R                  U5      n[        R                  S:  a  [        UTR                  S5      5      nO[        UT5      u  p XL a  UT4$ UU 4S jn
U
" U5      u  pnU
" U5      u  pnSU S	U S
U SU SU SU S3n[)        U5      e! [         a     Nf = f! [         ["        [$        4 a    ['        U SU ST 35      Sef = f)a  Given an object, return a name that can be used to retrieve the
object from this environment.

Args:
    obj: An object to get the module-environment-relative name for.
    name: If set, use this name instead of looking up __name__ or __qualname__ on `obj`.
        This is only here to match how Pickler handles __reduce__ functions that return a string,
        don't use otherwise.
Returns:
    A tuple (parent_module_name, attr_name) that can be used to retrieve `obj` from this environment.
    Use it like:
        mod = importer.import_module(parent_module_name)
        obj = getattr(mod, attr_name)

Raises:
    ObjNotFoundError: we couldn't retrieve `obj by name.
    ObjMisMatchError: we found a different object with the same name as `obj`.
N
__reduce__r   )      .z was not found as c                    > Tc   eTR                  U T5      n[        U5      nU(       a  [        U5      OSnU(       a  S[        U5       3OSnXU4$ )Nzthe current Python environmentzthe importer for z'sys_importer')r   r   r   )r*   r#   is_mangled_locationimporter_namer+   r'   s        r   get_obj_info'Importer.get_name.<locals>.get_obj_infox   so    ###**35K$[1K  "+.5   $$5k$B#CD% 
 -77r   z

The object provided is from 'z', which is coming from z.
However, when we import 'z', it's coming from z@.
To fix this, make sure this 'PackageExporter's importer lists z before )r   dispatchgettypegetattr
isinstancestr	Exceptionr   r   r   r(   sysversion_infor   splitImportErrorKeyErrorAttributeErrorr   r   )r'   r*   r+   reducervorig_module_namer#   moduleobj2_r5   obj_module_nameobj_locationobj_importer_nameobj2_module_nameobj2_locationobj2_importer_namemsgs   ` `               r   get_nameImporter.get_name=   s   & <CH$5$5$9$9$s)$D$L S,5F!B!"c**! <35D<<<D++C6 /0	''4F7* %VTZZ_='5a ;$$	8  <H;L8'8>J4>P;);//@ A$$0> 2**:);;OP] _O !*<)=Q	@ 	 s##o ! , X~6 	"%)+av>	s%   D7 "A E #E 7
EE*E1c                     [        USS5      nUb  U$ U R                  R                  5       R                  5        H,  u  p4US:X  d	  US:X  d  Uc  M   [	        XB5      S   UL a  Us  $ M.     g! [
         a     M>  f = f)zFind the module name an object belongs to.

This should be considered internal for end-users, but developers of
an importer can override it to customize the behavior.

Taken from pickle.py, but modified to exclude the search into sys.modules
r   N__main____mp_main__r   )r:   r"   copyitemsr   rC   )r'   r*   r+   r#   rG   s        r   r   Importer.whichmodule   s     c<6" $(<<#4#4#6#<#<#>Kz)-/> .q1S8&& 9 $?  " s   A,,
A:9A:r   N)r   r   r   r   r   dictr<   r   __annotations__r   r(   r	   tuplerQ   r   r   r   r   r   r   r      s}    ( #z/""   T$C T$sTz T$U38_ T$ls # # r   r   c                   <    \ rS rSrSrS\4S jrS\S\S\4S jrS	r	g
)_SysImporter   z;An importer that implements the default behavior of Python.r#   c                 .    [         R                  " U5      $ rY   )	importlibr(   r&   s     r   r(   _SysImporter.import_module   s    &&{33r   r*   r+   r$   c                 <    [        USS 5      nUb  U$ [        X5      $ )Nr   )r:   _pickle_whichmodule)r'   r*   r+   r#   s       r   r   _SysImporter.whichmodule   s)     c<6""3--r   r   N)
r   r   r   r   r   r<   r(   r	   r   r   r   r   r   r^   r^      s+    E4 4.s .# .# .r   r^   c            	       v    \ rS rSrSrS rS rSS\S\S-  S\	\\4   4S	 jjr
S
\S\4S jrS\S\S\4S jrSrg)r      zA compound importer that takes a list of importers and tries them one at a time.

The first importer in the list that returns a result "wins".
c                 $    [        U5      U l        g rY   )list
_importers)r'   argss     r   __init__OrderedImporter.__init__   s    *.t*r   c                     [        USS5      (       d  g[        US5      (       d  g[        US5      (       d  gUR                  SL $ )a  Returns true iff this module is an empty PackageNode in a torch.package.

If you intern `a.b` but never use `a` in your code, then `a` will be an
empty module with no source. This can break cases where we are trying to
re-package an object after adding a real dependency on `a`, since
OrderedImportere will resolve `a` to the dummy package and stop there.

See: https://github.com/pytorch/pytorch/pull/71520#issuecomment-1029603769
__torch_package__F__path____file__TN)r:   hasattrrq   )r'   rG   s     r   _is_torchpackage_dummy&OrderedImporter._is_torchpackage_dummy   sF     v2E::vz**vz**$&&r   Nr*   r+   r$   c           
      
   U R                    H  n UR                  X5      s  $    [        SU SU SU R                    35      e! [        [        4 a.  nSU SU SU SU 3n[        R                  U5         S nAMp  S nAff = f)Nz Tried to call get_name with obj z, and name z on z	 and got zCould not find obj z
 and name z in any of the importers )rj   rQ   r   r   logwarning)r'   r*   r+   importerewarning_messages         r   rQ   OrderedImporter.get_name   s    H-((33 ( !#j6OPTP_P_O`a
 	
 %&67 -6se <  $vT(9QCA   O,,-s   AB#A==Br#   c                    S nU R                    HR  n[        U[        5      (       d  [        U S35      e UR	                  U5      nU R                  U5      (       a  MP  Us  $    Ub  Ue[        U5      e! [         a  nUn S nAMx  S nAff = f)NzP is not a Importer. All importers in OrderedImporter must inherit from Importer.)rj   r;   r   	TypeErrorr(   rs   ModuleNotFoundError)r'   r#   last_errrx   rG   errs         r   r(   OrderedImporter.import_module   s    Hh11j !S S !//<..v66 ( N%k22 ' s   'A5A55
B?BBc                 `    U R                    H  nUR                  X5      nUS:w  d  M  Us  $    g)NrT   )rj   r   )r'   r*   r+   rx   r#   s        r   r   OrderedImporter.whichmodule  s3    H"..s9Kj("" (
 r   )rj   rY   )r   r   r   r   r   rl   rs   r	   r<   r\   rQ   r   r(   r   r   r   r   r   r   r      sd    
5'$
C 
sTz 
U38_ 
3 3 3*s # # r   r   )ra   loggingr>   abcr   r   pickler   r   r   rd   typesr   typingr	   	_manglingr   r   r   __all__	getLoggerr   rv   r=   r   r   r   r^   sys_importerr   r   r   r   <module>r      s      
 # 
   > > R!Sy Shy hOs Od.8 .  ~Dh Dr   