§
    cÌcjC  ã                   óÐ   — d Z ddlmZmZ  G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d	„ d
¦  «        Zd„ Ze	Z
 G d„ de¦  «        Z G d„ d¦  «        Zdd„ZdS )ai  Functionality to create lazy evaluation objects.

This includes waiting to import a module until it is actually used.

Most commonly, the 'lazy_import' function is used to import other modules
in an on-demand fashion. Typically use looks like::

    from .lazy_import import lazy_import
    lazy_import(globals(), '''
    from breezy import (
        errors,
        osutils,
        branch,
        )
    import breezy.branch
    ''')

Then 'errors, osutils, branch' and 'breezy' will exist as lazy-loaded
objects which will be replaced with a real object on first use.

In general, it is best to only load modules in this way. This is because
it isn't safe to pass these variables to other functions before they
have been replaced. This is especially true for constants, sometimes
true for classes or functions (when used as a factory, or you want
to inherit from them).
é   )ÚBzrErrorÚInternalBzrErrorc                   ó   — e Zd ZdZd„ ZdS )ÚImportNameCollisionzJTried to import an object to the same name as an existing object. %(name)sc                 ó<   — t          j        | ¦  «         || _        d S ©N)r   Ú__init__Úname)Úselfr
   s     ú4/usr/lib/python3/dist-packages/breezy/lazy_import.pyr	   zImportNameCollision.__init__4   s   € ÝÔ˜$ÑÔÐØˆŒ	ˆ	ˆ	ó    N©Ú__name__Ú
__module__Ú__qualname__Ú_fmtr	   © r   r   r   r   /   s*   € € € € € ð,€Dðð ð ð ð r   r   c                   ó   — e Zd ZdZdd„ZdS )ÚIllegalUseOfScopeReplacerzDScopeReplacer object %(name)r was used incorrectly: %(msg)s%(extra)sNc                 óŽ   — t          j        | ¦  «         || _        || _        |rdt	          |¦  «        z   | _        d S d| _        d S )Nz: Ú )r   r	   r
   ÚmsgÚstrÚextra)r   r
   r   r   s       r   r	   z"IllegalUseOfScopeReplacer.__init__>   sJ   € ÝÔ˜$ÑÔÐØˆŒ	ØˆŒØð 	Ø¥ E¡
¤
Ñ*ˆDŒJˆJˆJàˆDŒJˆJˆJr   r   r   r   r   r   r   r   9   s/   € € € € € ð €Dðð ð ð ð ð r   r   c                   ó   — e Zd ZdZd„ ZdS )ÚInvalidImportLinez-Not a valid import statement: %(msg)
%(text)sc                 óJ   — t          j        | ¦  «         || _        || _        d S r   )r   r	   Útextr   )r   r   r   s      r   r	   zInvalidImportLine.__init__L   s%   € ÝÔ˜$ÑÔÐØˆŒ	ØˆŒˆˆr   Nr   r   r   r   r   r   H   s(   € € € € € à;€Dðð ð ð ð r   r   c                   ó8   — e Zd ZdZdZdZd„ Zd„ Zd„ Zd„ Z	d„ Z
d	S )
ÚScopeReplacerz�A lazy object that will replace itself in the appropriate scope.

    This object sits, ready to create the real object the first time it is
    needed.
    )Ú_scopeÚ_factoryÚ_nameÚ	_real_objTc                 óð   — t                                | d|¦  «         t                                | d|¦  «         t                                | d|¦  «         t                                | dd¦  «         | ||<   dS )ag  Create a temporary object in the specified scope.
        Once used, a real object will be placed in the scope.

        :param scope: The scope the object should appear in
        :param factory: A callable that will create the real object.
            It will be passed (self, scope, name)
        :param name: The variable name in the given scope.
        r!   r"   r#   r$   N)ÚobjectÚ__setattr__)r   ÚscopeÚfactoryr
   s       r   r	   zScopeReplacer.__init__a   sq   € õ 	×Ò˜4 ¨5Ñ1Ô1Ð1Ý×Ò˜4 ¨WÑ5Ô5Ð5Ý×Ò˜4 ¨$Ñ/Ô/Ð/Ý×Ò˜4 ¨dÑ3Ô3Ð3Øˆˆd‰ˆˆr   c                 óà  — t                                | d¦  «        }t                                | d¦  «        }|€˜t                                | d¦  «        }t                                | d¦  «        } || ||¦  «        }|| u rt          |d¬¦  «        ‚t                                | d¦  «        }|€#t                                | d|¦  «         |||<   |S t          j        st          |d¬¦  «        ‚|S )	z6Return the real object for which this is a placeholderr#   r$   Nr"   r!   zCObject tried to replace itself, check it's not using its own scope.)r   z?Object already replaced, did you assign it to another variable?)r&   Ú__getattribute__r   r'   r    Ú_should_proxy)r   r
   Úreal_objr)   r(   Úobjs         r   Ú_resolvezScopeReplacer._resolvep   s  € å×&Ò& t¨WÑ5Ô5ˆÝ×*Ò*¨4°Ñ=Ô=ˆØÐå×-Ò-¨d°JÑ?Ô?ˆGÝ×+Ò+¨D°(Ñ;Ô;ˆEØ�'˜$  tÑ,Ô,ˆCØ�dˆ{ˆ{Ý/Øð NðOñ Oô Oð Oõ
 ×.Ò.¨t°[ÑAÔAˆHØÐõ ×"Ò" 4¨°cÑ:Ô:Ð:Ø!��d‘Ø�
õ Ô*ð 	3Ý+Øð 2ð3ñ 3ô 3ð 3ð ˆr   c                 óf   — t                               | d¦  «        ¦   «         }t          ||¦  «        S ©Nr/   )r&   r+   Úgetattr)r   Úattrr.   s      r   r+   zScopeReplacer.__getattribute__�   s-   € Ý×%Ò% d¨JÑ7Ô7Ñ9Ô9ˆÝ�s˜DÑ!Ô!Ð!r   c                 óh   — t                               | d¦  «        ¦   «         }t          |||¦  «        S r1   )r&   r+   Úsetattr)r   r3   Úvaluer.   s       r   r'   zScopeReplacer.__setattr__“   s/   € Ý×%Ò% d¨JÑ7Ô7Ñ9Ô9ˆÝ�s˜D %Ñ(Ô(Ð(r   c                 óV   — t                               | d¦  «        ¦   «         } ||i |¤ŽS r1   )r&   r+   )r   ÚargsÚkwargsr.   s       r   Ú__call__zScopeReplacer.__call__—   s2   € Ý×%Ò% d¨JÑ7Ô7Ñ9Ô9ˆØˆs�DÐ#˜FÐ#Ð#Ð#r   N)r   r   r   Ú__doc__Ú	__slots__r,   r	   r/   r+   r'   r:   r   r   r   r    r    R   sw   € € € € € ðð ð =€Ið €Mðð ð ðð ð ð>"ð "ð "ð)ð )ð )ð$ð $ð $ð $ð $r   r    c                  ó   — dt           _        dS )aL  Disallow lazily imported modules to be used as proxies.

    Calling this function might cause problems with concurrent imports
    in multithreaded environments, but will help detecting wasteful
    indirection, so it should be called when executing unit tests.

    Only lazy imports that happen after this call are affected.
    FN)r    r,   r   r   r   Údisallow_proxyingr>   œ   s   € ð #(…MÔÐÐr   c                   ó(   — e Zd ZdZdZdi fd„Zd„ ZdS )ÚImportReplacerzîThis is designed to replace only a portion of an import list.

    It will replace itself with a module, and then make children
    entries also ImportReplacer objects.

    At present, this only supports 'import foo.bar.baz' syntax.
    )Ú_import_replacer_childrenÚ_memberÚ_module_pathNc                 óP  — |�|rt          d¦  «        ‚t                               | d|¦  «         t                               | d|¦  «         t                               | d|¦  «         t                               | d¦  «        }t                               | |||j        ¬¦  «         dS )at  Upon request import 'module_path' as the name 'module_name'.
        When imported, prepare children to also be imported.

        :param scope: The scope that objects should be imported into.
            Typically this is globals()
        :param name: The variable name. Often this is the same as the
            module_path. 'breezy'
        :param module_path: A list for the fully specified module path
            ['breezy', 'foo', 'bar']
        :param member: The member inside the module to import, often this is
            None, indicating the module is being imported.
        :param children: Children entries to be imported later.
            This should be a map of children specifications.
            ::

                {'foo':(['breezy', 'foo'], None,
                    {'bar':(['breezy', 'foo', 'bar'], None {})})
                }

        Examples::

            import foo => name='foo' module_path='foo',
                          member=None, children={}
            import foo.bar => name='foo' module_path='foo', member=None,
                              children={'bar':(['foo', 'bar'], None, {}}
            from foo import bar => name='bar' module_path='foo', member='bar'
                                   children={}
            from foo import bar, baz would get translated into 2 import
            requests. On for 'name=bar' and one for 'name=baz'
        Nz(Cannot supply both a member and childrenrA   rB   rC   Ú	__class__)r(   r
   r)   )Ú
ValueErrorr&   r'   r+   r    r	   Ú_import)r   r(   r
   Úmodule_pathÚmemberÚchildrenÚclss          r   r	   zImportReplacer.__init__½   s°   € ð> Ð HÐÝÐGÑHÔHÐHå×Ò˜4Ð!<¸hÑGÔGÐGÝ×Ò˜4 ¨FÑ3Ô3Ð3Ý×Ò˜4 °Ñ=Ô=Ð=õ ×%Ò% d¨KÑ8Ô8ˆÝ×Ò˜t¨5°tØ'*¤{ð 	ñ 	4ô 	4ð 	4ð 	4ð 	4r   c                 ó  — t                                | d¦  «        }t                                | d¦  «        }t                                | d¦  «        }d                     |¦  «        }|�%t          ||||gd¬¦  «        }t	          ||¦  «        S t          |||g d¬¦  «        }|dd …         D ]}t	          ||¦  «        }Œ|                     ¦   «         D ]9\  }\  }	}
}t                                | d¦  «        } ||j        ||	|
|¬	¦  «         Œ:|S )
NrA   rB   rC   ú.é    )Úlevelr   rE   ©r
   rH   rI   rJ   )r&   r+   ÚjoinÚ_builtin_importr2   ÚitemsÚ__dict__)r   r(   r
   rJ   rI   rH   ÚmoduleÚpathÚ
child_nameÚ
child_pathÚchild_memberÚgrandchildrenrK   s                r   rG   zImportReplacer._importé   s4  € Ý×*Ò*¨4Ð1LÑMÔMˆÝ×(Ò(¨¨yÑ9Ô9ˆÝ×-Ò-¨d°NÑCÔCˆØ�xŠx˜Ñ$Ô$ˆØÐÝ$ T¨5°%¸&¸ÈÐKÑKÔKˆFÝ˜6 6Ñ*Ô*Ð*å$ T¨5°%¸À1ÐEÑEÔEˆFØ# A B Bœð /ð /�Ý  ¨Ñ.Ô.��ð —’Ñ Ô ð	(ð 	(ÑAˆJÑA˜ \°=õ ×)Ò)¨$°Ñ<Ô<ˆCØˆC�” jØ&¨|Ø&ð(ñ (ô (ð (ð (ð ˆr   )r   r   r   r;   r<   r	   rG   r   r   r   r@   r@   «   sO   € € € € € ðð ð I€Ià8<Àrð *4ð *4ð *4ð *4ðXð ð ð ð r   r@   c                   óF   — e Zd ZdZddgZdd„Zd„ Zd„ Zd„ Zd	„ Z	d
„ Z
d„ ZdS )ÚImportProcessorz7Convert text that users input into lazy import requestsÚimportsÚ_lazy_import_classNc                 óB   — i | _         |€t          | _        d S || _        d S r   )r]   r@   r^   )r   Úlazy_import_classs     r   r	   zImportProcessor.__init__  s+   € ØˆŒØÐ$Ý&4ˆDÔ#Ð#Ð#à&7ˆDÔ#Ð#Ð#r   c                 óZ   — |                       |¦  «         |                      |¦  «         dS )z§Convert the given text into a bunch of lazy import objects.

        This takes a text string, which should be similar to normal python
        import markup.
        N)Ú
_build_mapÚ_convert_imports)r   r(   r   s      r   Úlazy_importzImportProcessor.lazy_import  s0   € ð 	�Š˜ÑÔÐØ×Ò˜eÑ$Ô$Ð$Ð$Ð$r   c           	      óœ   — | j                              ¦   «         D ]1\  }}|                      |||d         |d         |d         ¬¦  «         Œ2d S )NrN   r   é   rP   )r]   rS   r^   )r   r(   r
   Úinfos       r   rc   z ImportProcessor._convert_imports  sn   € àœ,×,Ò,Ñ.Ô.ð 	Fð 	F‰JˆD�$Ø×#Ò# E°À$ÀqÄ'Ø+/°¬7¸TÀ!¼Wð $ñ Fô Fð Fð Fð	Fð 	Fr   c                 ó   — |                       |¦  «        D ]g}|                     d¦  «        r|                      |¦  «         Œ-|                     d¦  «        r|                      |¦  «         ŒXt	          |d¦  «        ‚dS )z?Take a string describing imports, and build up the internal mapúimport úfrom z'doesn't start with 'import ' or 'from 'N)Ú_canonicalize_import_textÚ
startswithÚ_convert_import_strÚ_convert_from_strr   )r   r   Úlines      r   rb   zImportProcessor._build_map#  s    € à×2Ò2°4Ñ8Ô8ð 	Eð 	EˆDØ�Š˜yÑ)Ô)ð EØ×(Ò(¨Ñ.Ô.Ð.Ð.Ø—’ Ñ)Ô)ð EØ×&Ò& tÑ,Ô,Ð,Ð,å'ØÐCñEô Eð Eð	Eð 	Er   c                 óº  — |                      d¦  «        s"t          d                     |¦  «        ¦  «        ‚|t          d¦  «        d…         }|                     d¦  «        D �]u}|                     ¦   «         }|sŒ|                     d¦  «        }t          |¦  «        dk    r„|d                              ¦   «         }|d                              ¦   «                              d	¦  «        }|| j        v rt          |¦  «        ‚|d         st          |¦  «        ‚|di f| j        |<   ŒÆ|                     d	¦  «        }|d         }|st          |¦  «        ‚|| j        vr|gdi f}|| j        |<   n| j        |         }|g}|d         }|dd…         D ]D}	| 	                    |	¦  «         |	|v r||	         d         }Œ*|dd…         di f}
|
||	<   |
d         }ŒE�ŒwdS )
z½This converts a import string into an import map.

        This only understands 'import foo, foo.bar, foo.bar.baz as bing'

        :param import_str: The import string to process
        ri   zbad import string {!r}Nú,ú as rf   r   rN   rM   )
rl   rF   ÚformatÚlenÚsplitÚstripr]   r   ÚImportErrorÚappend)r   Ú
import_strrV   Úas_hunksr
   rH   Ú
module_defÚcur_pathÚcurÚchildÚnexts              r   rm   z#ImportProcessor._convert_import_str.  s  € ð ×$Ò$ YÑ/Ô/ð 	JÝÐ5×<Ò<¸ZÑHÔHÑIÔIÐIØ¥ I¡¤  Ô0ˆ
à×$Ò$ SÑ)Ô)ð '	&ñ '	&ˆDØ—:’:‘<”<ˆDØð ØØ—z’z &Ñ)Ô)ˆHÝ�8‰}Œ} Ò!Ð!ð   ”{×(Ò(Ñ*Ô*�Ø& qœk×/Ò/Ñ1Ô1×7Ò7¸Ñ<Ô<�Ø˜4œ<Ð'Ð'Ý-¨dÑ3Ô3Ð3Ø" 1”~ð ,Ý% dÑ+Ô+Ð+à&1°4¸Ð%<�”˜TÑ"Ð"ð #Ÿjšj¨™oœo�Ø" 1”~�Øð ,Ý% dÑ+Ô+Ð+Ø˜tœ|Ð+Ð+à#' &¨$°Ð!3�JØ)3�D”L Ñ&Ð&à!%¤¨dÔ!3�Jà ˜6�Ø  ”m�Ø(¨¨¨œ_ð &ð &�EØ—O’O EÑ*Ô*Ð*Ø �|�|Ø! %œj¨œm˜˜à (¨¨¨¤¨T°2Ð6˜Ø%)˜˜E™
Ø" 1œg˜˜ñ&ðA'	&ð '	&r   c                 ót  — |                      d¦  «        st          d|z  ¦  «        ‚|t          d¦  «        d…         }|                     d¦  «        \  }}|                     d¦  «        }|d         st	          |¦  «        ‚|                     d¦  «        D ]Ÿ}|                     ¦   «         }|sŒ|                     d¦  «        }t          |¦  «        d	k    r5|d
                              ¦   «         }|d                              ¦   «         }n|x}}|| j        v rt          |¦  «        ‚||i f| j        |<   Œ dS )z€This converts a 'from foo import bar' string into an import map.

        :param from_str: The import string to process
        rj   zbad from/import %rNz import rM   rN   rq   rr   rf   r   )rl   rF   rt   ru   rw   rv   r]   r   )	r   Úfrom_strÚfrom_moduleÚimport_listÚfrom_module_pathrV   rz   r
   rU   s	            r   rn   z!ImportProcessor._convert_from_strb  sU  € ð
 ×"Ò" 7Ñ+Ô+ð 	>ÝÐ1°HÑ<Ñ=Ô=Ð=Ø�C ™LœL˜M˜MÔ*ˆà#+§>¢>°*Ñ#=Ô#=Ñ ˆ�[à&×,Ò,¨SÑ1Ô1Ðà Ô"ð 	+Ý˜kÑ*Ô*Ð*à×%Ò% cÑ*Ô*ð 	@ð 	@ˆDØ—:’:‘<”<ˆDØð ØØ—z’z &Ñ)Ô)ˆHÝ�8‰}Œ} Ò!Ð!ð   ”{×(Ò(Ñ*Ô*�Ø! !œ×*Ò*Ñ,Ô,��à $Ð$��vØ�t”|Ð#Ð#Ý)¨$Ñ/Ô/Ð/Ø"2°F¸BÐ!?ˆDŒL˜ÑÐð	@ð 	@r   c                 óB  — g }d}|                      d¦  «        D ]ò}|                     ¦   «         }|                     d¦  «        }|dk    r|d|…                              ¦   «         }|sŒP|�D|                     d¦  «        r&|                     |dz   |dd…         z   ¦  «         d}Œ�|d|z   z  }Œ–d|v rd|vr|                     dd¦  «        }Œµ|                     |                     dd¦  «                             dd¦  «        ¦  «         Œó|�t          |d	¦  «        ‚|S )
zÄTake a list of imports, and split it into regularized form.

        This is meant to take regular import text, and convert it to
        the forms that the rest of the converters prefer.
        Nú
ú#éÿÿÿÿú)ú ú(r   zUnmatched parenthesis)ru   rv   ÚfindÚendswithrx   Úreplacer   )r   r   Úoutr}   ro   Úlocs         r   rk   z)ImportProcessor._canonicalize_import_textƒ  s;  € ð ˆØˆà—J’J˜tÑ$Ô$ð 	Gð 	GˆDØ—:’:‘<”<ˆDØ—)’)˜C‘.”.ˆCØ�bŠyˆyØ˜D˜S˜D”z×'Ò'Ñ)Ô)�àð ØØˆØ—=’= Ñ%Ô%ð &Ø—J’J˜s S™y¨4°°°¬9Ñ4Ñ5Ô5Ð5Ø�C�Cà˜3 ™:Ñ%�C�Cà˜$�;�; 3¨d ? ?ØŸ,š, s¨BÑ/Ô/�C�Cà—J’J˜tŸ|š|¨C°Ñ4Ô4×<Ò<¸SÀ"ÑEÔEÑFÔFÐFÐFØˆ?Ý# CÐ)@ÑAÔAÐAØˆ
r   r   )r   r   r   r;   r<   r	   rd   rc   rb   rm   rn   rk   r   r   r   r\   r\     s    € € € € € ØAÐAð Ð0Ð1€Ið8ð 8ð 8ð 8ð%ð %ð %ðFð Fð Fð	Eð 	Eð 	Eð2&ð 2&ð 2&ðh@ð @ð @ðBð ð ð ð r   r\   Nc                 óN   — t          |¬¦  «        }|                     | |¦  «        S )aÒ  Create lazy imports for all of the imports in text.

    This is typically used as something like::

        from breezy.lazy_import import lazy_import
        lazy_import(globals(), '''
        from breezy import (
            foo,
            bar,
            baz,
            )
        import breezy.branch
        import breezy.transport
        ''')

    Then 'foo, bar, baz' and 'breezy' will exist as lazy-loaded
    objects which will be replaced with a real object on first use.

    In general, it is best to only load modules in this way. This is
    because other objects (functions/classes/variables) are frequently
    used without accessing a member, which means we cannot tell they
    have been used.
    )r`   )r\   rd   )r(   r   r`   Úprocs       r   rd   rd   ¤  s+   € õ2 Ð->Ð?Ñ?Ô?€DØ×Ò˜E 4Ñ(Ô(Ð(r   r   )r;   Úerrorsr   r   r   r   r   r    r>   Ú
__import__rR   r@   r\   rd   r   r   r   ú<module>r•      ss  ðð"ð ð6 /Ð .Ð .Ð .Ð .Ð .Ð .Ð .ðð ð ð ð Ð*ñ ô ð ðð ð ð ð Ð 0ñ ô ð ðð ð ð ð Ð(ñ ô ð ðG$ð G$ð G$ð G$ð G$ñ G$ô G$ð G$ðT	(ð 	(ð 	(ð €ðTð Tð Tð Tð T�]ñ Tô Tð Tðn_ð _ð _ð _ð _ñ _ô _ð _ðD)ð )ð )ð )ð )ð )r   