Ë
    ùÿæiÿ'  ã                   ó  — d dl Z d dlZd dlZd dlmZmZ d dlmZmZm	Z
 d dlmZ d dlmZ ddlmZmZmZ g d¢Z ej(                  e«      Z G d	„ d
e«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z e«       Z G d„ de«      Zy)é    N)ÚABCÚabstractmethod)Ú_getattributeÚ_PicklerÚwhichmodule)Ú
ModuleType)ÚAnyé   )ÚdemangleÚget_mangle_prefixÚ
is_mangled)ÚObjNotFoundErrorÚObjMismatchErrorÚImporterÚOrderedImporterc                   ó   — e Zd ZdZy)r   zHRaised when an importer cannot find an object by searching for its name.N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úk/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/torch/package/importer.pyr   r      s   „ ÚRr   r   c                   ó   — e Zd ZdZy)r   z]Raised when an importer found a different object with the same name as the user-provided one.Nr   r   r   r   r   r      s   „ Úgr   r   c            	       óz   — e Zd ZU dZeeef   ed<   ededefd„«       Z	dde
dedz  deeef   fd	„Zde
dedefd
„Zy)r   ad  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                  ó   — y)zvImport `module_name` from this environment.

        The contract is the same as for importlib.import_module.
        Nr   ©Úselfr   s     r   Úimport_modulezImporter.import_module3   s   � r   NÚobjÚnamec                 óÆ  ‡ ‡— ‰€S|rQt         j                  j                  t        |«      «      €)t	        |dd«      }|�	  |«       }t        |t        «      r|Š‰€t	        |dd«      Š‰€|j                  Š‰ j                  |‰«      }t        |«      }	 ‰ j                  |«      }t        j                  dk\  rt        |‰j                  d«      «      }nt        |‰«      \  }}	||u r|‰fS ˆˆ fd„}
 |
|«      \  }}} |
|«      \  }}}d|› d	|› d
|› d|› d|› d|› d�}t)        |«      ‚# t        $ r Y ŒÛw xY w# t         t"        t$        f$ r t'        |› d|› d‰› �«      d‚w xY w)ai  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        d«      ‚‰j                  | ‰«      }t        |«      }|rt        |«      nd}|rdt        |«      › �nd}|||fS )Nzname must not be Nonezthe current Python environmentzthe importer for z'sys_importer')ÚAssertionErrorr   r   r   )r$   r   Úis_mangled_ÚlocationÚimporter_namer%   r"   s        €€r   Úget_obj_infoz'Importer.get_name.<locals>.get_obj_infou   sv   ø€ Øˆ|Ü$Ð%<Ó=Ð=Ø×*Ñ*¨3°Ó5ˆKÜ$ [Ó1ˆKñ ô " +Ô.à5ð ñ ð $Ô$5°kÓ$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Ú_r0   Úobj_module_nameÚobj_locationÚobj_importer_nameÚobj2_module_nameÚobj2_locationÚobj2_importer_nameÚmsgs   ` `               r   Úget_namezImporter.get_name:   sÊ  ù€ ð& ˆ<™C¤H×$5Ñ$5×$9Ñ$9¼$¸s»)Ó$DÐ$Lô ˜S ,°Ó5ˆFØÐ!ðÙ›�BÜ! "¤cÔ*Ø!˜ð ˆ<Ü˜3 °Ó5ˆDØˆ<Ø—<‘<ˆDà×+Ñ+¨C°Ó6Ðô Ð/Ó0ˆð	Ø×'Ñ'¨Ó4ˆFÜ×Ñ 7Ò*ô % V¨T¯Z©Z¸«_Ó=‘ä'¨°Ó5‘��að �$‰;Ø Ð$Ð$õ	8ñ" <HÈÓ;LÑ8ˆ˜Ð'8Ù>JÈ4Ó>PÑ;Ð˜-Ð);à/°Ð/@ð A$Ø$0 >ð 2*Ø*:Ð);Ð;OÐP]Èð _Oà Ð! Ð*<Ð)=¸Qð	@ð 	ô ˜sÓ#Ð#øôq !ò Ùðûô, œX¤~Ð6ò 	Ü"Ø�%Ð)¨+¨°a¸°vÐ>óàðð	ús   ¿D( ÂAD7 Ä(	D4Ä3D4Ä7)E c                 óê   — t        |dd«      }|�|S | j                  j                  «       j                  «       D ](  \  }}|dk(  s|dk(  s|€Œ	 t	        ||«      d   |u r|c S Œ* y# t
        $ r Y Œ7w xY w)a  Find 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   )r4   r   ÚcopyÚitemsr   r=   )r"   r$   r%   r   rA   s        r   r   zImporter.whichmodule‘   sš   € ô ˜c <°Ó6ˆØÐ"ØÐð $(§<¡<×#4Ñ#4Ó#6×#<Ñ#<Ö#>ÑˆK˜à˜zÒ)Ø -Ò/Ø�>àðÜ  ¨Ó.¨qÑ1°SÑ8Ø&Ò&ð 9ð $?ð øô "ò Ùðús   ÁA&Á&	A2Á1A2©N)r   r   r   r   Údictr6   r   Ú__annotations__r   r#   r	   ÚtuplerK   r   r   r   r   r   r      s}   … ñð( �#�z�/Ñ"Ó"àð¨ð °ò ó ðñU$˜Cð U$ s¨T¡zð U$¸UÀ3ÈÀ8¹_ó U$ðn˜sð ¨#ð °#ô r   r   c                   ó0   — e Zd ZdZdefd„Zdededefd„Zy)	Ú_SysImporterz;An importer that implements the default behavior of Python.r   c                 ó,   — t        j                  |«      S rQ   )Ú	importlibr#   r!   s     r   r#   z_SysImporter.import_module²   s   € Ü×&Ñ& {Ó3Ð3r   r$   r%   r   c                 ó<   — t        |dd «      }|�|S t        ||«      S )Nr   )r4   Ú_pickle_whichmodule)r"   r$   r%   r   s       r   r   z_SysImporter.whichmoduleµ   s+   € ô ˜c <°Ó6ˆØÐ"ØÐÜ" 3¨Ó-Ð-r   N)r   r   r   r   r6   r#   r	   r   r   r   r   rV   rV   ¯   s+   „ ÙEð4¨ó 4ð.˜sð .¨#ð .°#ô .r   rV   c            	       óf   — e Zd ZdZd„ Zd„ Zddededz  deeef   fd„Z	d	ede
fd
„Zdededefd„Zy)r   z—A 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                 ó$   — t        |«      | _        y rQ   )ÚlistÚ
_importers)r"   Úargss     r   Ú__init__zOrderedImporter.__init__È   s   € Ü*.¨t«*ˆ�r   c                 ón   — t        |dd«      syt        |d«      syt        |d«      sy|j                  du S )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)r4   Úhasattrrd   )r"   rA   s     r   Ú_is_torchpackage_dummyz&OrderedImporter._is_torchpackage_dummyË   s=   € ô �vÐ2°EÔ:ØÜ�v˜zÔ*ØÜ�v˜zÔ*ØØ�‰ $Ð&Ð&r   Nr$   r%   r   c           
      ó  — | j                   D ]  }	 |j                  ||«      c S  t        d|› d|› d| j                   › �«      ‚# t        t        f$ r-}d|› d|› d|› d|› �}t        j                  |«       Y d }~Œnd }~ww xY w)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 )r^   rK   r   r   ÚlogÚwarning)r"   r$   r%   ÚimporterÚeÚwarning_messages         r   rK   zOrderedImporter.get_nameÝ   s§   € ØŸœˆHð-Ø×(Ñ(¨¨dÓ3Ò3ð (ô Ø! #  j°°Ð6OÐPT×P_ÑP_ÐO`Ðaó
ð 	
øô %Ô&6Ð7ò -à6°s°eð < Ø $˜v T¨(¨°9¸Q¸CðAð  ô —‘˜O×,Ñ,ûð-ús   ‘AÁB Á#A;Á;B r   c                 ó   — d }| j                   D ]G  }t        |t        «      st        |› d�«      ‚	 |j	                  |«      }| j                  |«      rŒE|c S  |�|‚t        |«      ‚# t        $ r}|}Y d }~Œid }~ww xY w)NzP is not a Importer. All importers in OrderedImporter must inherit from Importer.)r^   r5   r   Ú	TypeErrorr#   rf   ÚModuleNotFoundError)r"   r   Úlast_errrj   rA   Úerrs         r   r#   zOrderedImporter.import_moduleë   s—   € ØˆØŸœˆHÜ˜h¬Ô1ÜØ�jð !Sð Sóð ðØ!×/Ñ/°Ó<�Ø×.Ñ.¨vÔ6ØØ’ð (ð ÐØˆNä% kÓ2Ð2øô 'ò Ø•ûðús   ±"A(ÁA(Á(	A=Á1A8Á8A=c                 ó\   — | j                   D ]  }|j                  ||«      }|dk7  sŒ|c S  y)NrM   )r^   r   )r"   r$   r%   rj   r   s        r   r   zOrderedImporter.whichmodule   s5   € ØŸœˆHØ"×.Ñ.¨s°DÓ9ˆKØ˜jÓ(Ø"Ò"ð (ð
 r   rQ   )r   r   r   r   r`   rf   r	   r6   rT   rK   r   r#   r   r   r   r   r   r   Â   sd   „ ñò
5ò'ñ$
˜Cð 
 s¨T¡zð 
¸UÀ3ÈÀ8¹_ó 
ð3¨ð 3°ó 3ð*˜sð ¨#ð °#ô r   r   )rX   Úloggingr8   Úabcr   r   Úpickler   r   r   rZ   Útypesr   Útypingr	   Ú	_manglingr   r   r   Ú__all__Ú	getLoggerr   rh   r7   r   r   r   rV   Úsys_importerr   r   r   r   Ú<module>r|      s‘   ðÛ Û Û 
ß #÷ñ õ
 Ý ç >Ñ >ò R€Ø€g×Ñ˜Ó!€ôS�yô Sôh�yô hôPˆsô Pôf.�8ô .ñ  ‹~€ôD�hõ Dr   