
    JTh"                         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Jr  SSKJrJrJr  / SQ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Optional   )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       N/var/www/auris/envauris/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\\\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_module1   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[        UT5      u  pX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_infon   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)   r   ImportErrorKeyErrorAttributeErrorr   r   )r(   r+   r,   reducervorig_module_namer$   moduleobj2_r4   obj_module_nameobj_locationobj_importer_nameobj2_module_nameobj2_locationobj2_importer_namemsgs   ` `               r   get_nameImporter.get_name8   s   & <CH$5$5$9$9$s)$D$L S,5F!B!"c**! <35D<<<D++C6 /0	''4F#FD1GD ;$$	8  <H;L8'8>J4>P;);//@ A$$0> 2**:);;OP] _O !*<)=Q	@ 	 s##e ! " X~6 	"%)+av>	s   D "D 
DD*E 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   )r9   r#   copyitemsr   r?   )r(   r+   r,   r$   rC   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	   r
   tuplerM   r   r   r   r   r   r   r      s}    ( #z/""   O$C O$x} O$c3h O$b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      $ rU   )	importlibr)   r'   s     r   r)   _SysImporter.import_module   s    &&{33r   r+   r,   r%   c                     [        X5      $ rU   )_pickle_whichmodule)r(   r+   r,   s      r   r   _SysImporter.whichmodule   s    "3--r   r   N)
r   r   r   r   r   r;   r)   r	   r   r   r   r   r   rZ   rZ      s+    E4 4.s .# .# .r   rZ   c                   L    \ rS rSrSrS rS 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 rU   )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)r9   hasattrrm   )r(   rC   s     r   _is_torchpackage_dummy&OrderedImporter._is_torchpackage_dummy   sF     v2E::vz**vz**$&&r   r$   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.)rf   r:   r   	TypeErrorr)   ro   ModuleNotFoundError)r(   r$   last_errimporterrC   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r+   r,   c                 `    U R                    H  nUR                  X5      nUS:w  d  M  Us  $    g)NrP   )rf   r   )r(   r+   r,   ru   r$   s        r   r   OrderedImporter.whichmodule   s3    H"..s9Kj("" (
 r   )rf   N)r   r   r   r   r   rh   ro   r;   r   r)   r	   r   r   r   r   r   r   r      s>    
5'$3 3 3*s # # r   r   )r]   abcr   r   pickler   r   r   r`   typesr   typingr	   r
   	_manglingr   r   r   __all__r<   r   r   r   rZ   sys_importerr   r   r   r   <module>r      sw     # 
    > > RSy Shy hJs JZ.8 . ~6h 6r   