HEX
Server: Apache
System: Linux infong-uk86 4.4.400-icpu-106 #2 SMP Mon Sep 15 08:23:40 UTC 2025 x86_64
User: u44115835 (4976590)
PHP: 8.4.17
Disabled: NONE
Upload Files
File: //kunden/lib/python3/dist-packages/breezy/__pycache__/lazy_import.cpython-39.pyc
a

�*�^�C�@s�dZddlmZddlmZmZGdd�de�ZGdd�de�ZGd	d
�d
e�ZGdd�de	�Z
d
d�ZeZ
Gdd�de
�ZGdd�de	�Zddd�ZdS)aiFunctionality 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).
�)�absolute_import�)�BzrError�InternalBzrErrorc@seZdZdZdd�ZdS)�ImportNameCollisionzJTried to import an object to the same name as an existing object. %(name)scCst�|�||_dS�N)r�__init__�name)�selfr	�r�4/usr/lib/python3/dist-packages/breezy/lazy_import.pyr6s
zImportNameCollision.__init__N��__name__�
__module__�__qualname__Z_fmtrrrrrr1src@seZdZdZddd�ZdS)�IllegalUseOfScopeReplacerzDScopeReplacer object %(name)r was used incorrectly: %(msg)s%(extra)sNcCs4t�|�||_||_|r*dt|�|_nd|_dS)Nz: �)rrr	�msg�str�extra)r
r	rrrrrr@s
z"IllegalUseOfScopeReplacer.__init__)Nr
rrrrr;src@seZdZdZdd�ZdS)�InvalidImportLinez-Not a valid import statement: %(msg)
%(text)scCst�|�||_||_dSr)rr�textr)r
rrrrrrNs
zInvalidImportLine.__init__Nr
rrrrrJsrc@s@eZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dS)�
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_objTcCsDt�|d|�t�|d|�t�|d|�t�|dd�|||<dS)agCreate 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.
        rrrrN)�object�__setattr__)r
�scope�factoryr	rrrrcs
	zScopeReplacer.__init__cCs�t�|d�}t�|d�}|dur�t�|d�}t�|d�}||||�}||urXt|dd��t�|d�}|dur�t�|d|�|||<|Stjs�t|dd��|S)	z6Return the real object for which this is a placeholderrrNrrzCObject tried to replace itself, check it's not using its own scope.)rz?Object already replaced, did you assign it to another variable?)r�__getattribute__rrr�
_should_proxy)r
r	Zreal_objr r�objrrr�_resolvers(��zScopeReplacer._resolvecCst�|d��}t||�S�Nr$)rr!�getattr)r
�attrr#rrrr!�szScopeReplacer.__getattribute__cCst�|d��}t|||�Sr%)rr!�setattr)r
r'�valuer#rrrr�szScopeReplacer.__setattr__cOst�|d��}||i|��Sr%)rr!)r
�args�kwargsr#rrr�__call__�szScopeReplacer.__call__N)rrr�__doc__�	__slots__r"rr$r!rr,rrrrrTsrcCs
dt_dS)aLDisallow 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)rr"rrrr�disallow_proxying�s	r/c@s*eZdZdZdZdifdd�Zdd�ZdS)�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_pathNcCsb|dur|rtd��t�|d|�t�|d|�t�|d|�t�|d�}tj||||jd�dS)atUpon 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 childrenr1r2r3�	__class__)rr	r )�
ValueErrorrrr!rr�_import)r
rr	�module_path�member�children�clsrrrr�s
�zImportReplacer.__init__c
Cs�t�|d�}t�|d�}t�|d�}d�|�}|durTt||||gdd�}t||�St|||gdd�}|dd�D]}t||�}qr|��D].\}\}	}
}t�|d�}||j||	|
|d	�q�|S)
Nr1r2r3�.r)�levelrr4�r	r7r8r9)rr!�join�_builtin_importr&�items�__dict__)
r
rr	r9r8r7�module�pathZ
child_nameZ
child_pathZchild_memberZ
grandchildrenr:rrrr6�s$

��zImportReplacer._import)rrrr-r.rr6rrrrr0�s,r0c@sReZdZdZddgZddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�ImportProcessorz7Convert text that users input into lazy import requests�imports�_lazy_import_classNcCs i|_|durt|_n||_dSr)rEr0rF)r
�lazy_import_classrrrrszImportProcessor.__init__cCs|�|�|�|�dS)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
rrrrr�lazy_imports
zImportProcessor.lazy_importcCs8|j��D](\}}|j|||d|d|dd�q
dS)Nrr�r=)rEr@rF)r
rr	�inforrrrIs�z ImportProcessor._convert_importscCsJ|�|�D]:}|�d�r$|�|�q
|�d�r:|�|�q
t|d��q
dS)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�linerrrrH%s

�zImportProcessor._build_mapcCsd|�d�std|f��|td�d�}|�d�D�]*}|��}|sFq2|�d�}t|�dkr�|d��}|d���d	�}||jvr�t|��|ds�t|��|dif|j|<q2|�d	�}|d}|s�t|��||jvr�|gdif}||j|<n
|j|}|g}|d}|dd�D]J}	|�|	�|	|v�r8||	d}n"|dd�dif}
|
||	<|
d}�qq2dS)
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
        rMzbad import string %rN�,� as rKrrr;)	rPr5�len�split�striprEr�ImportError�append)r
Z
import_strrC�as_hunksr	r7Z
module_defZcur_path�cur�child�nextrrrrQ0sB







z#ImportProcessor._convert_import_strc	Cs�|�d�std|��|td�d�}|�d�\}}|�d�}|dsNt|��|�d�D]l}|��}|sjqX|�d�}t|�d	kr�|d
��}|d��}n|}}||jvr�t|��||if|j|<qXdS)z�This converts a 'from foo import bar' string into an import map.

        :param from_str: The import string to process
        rNzbad from/import %rNz import r;rrTrUrKr)rPr5rVrWrYrXrEr)	r
Zfrom_strZfrom_moduleZimport_listZfrom_module_pathrCr[r	rBrrrrRds&



z!ImportProcessor._convert_from_strcCs�g}d}|�d�D]�}|��}|�d�}|dkr@|d|���}|sFq|dur�|�d�rx|�|d|dd��d}q�|d|7}qd|vr�d|vr�|�dd�}q|�|�dd��dd��q|dur�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�
�#����)� �(rzUnmatched parenthesis)rWrX�find�endswithrZ�replacer)r
r�outr\rSZlocrrrrO�s(


z)ImportProcessor._canonicalize_import_text)N)rrrr-r.rrJrIrHrQrRrOrrrrrDs
	4!rDNcCst|d�}|�||�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.
    )rG)rDrJ)rrrG�procrrrrJ�s
rJ)N)r-Z
__future__r�errorsrrrrrrrr/�
__import__r?r0rDrJrrrr�<module>s

JW#