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__/url_policy_open.cpython-39.pyc
a

�*�^�/�@sdZddlmZddlZddlmZmZmZddlm	Z	ddl
mZmZddl
mZmZGd	d
�d
ej�ZGdd�dej�ZGd
d�dej�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Zdd�Ze��dS)z+Branch opening with URL-based restrictions.�)�absolute_importN�)�errors�trace�urlutils)�Branch)�
ControlDir�ControlDirFormat)�do_catching_redirections�
get_transportc@seZdZdZdS)�BadUrlz.Tried to access a branch from bad URL %(url)s.N��__name__�
__module__�__qualname__�_fmt�rr�8/usr/lib/python3/dist-packages/breezy/url_policy_open.pyr'src@seZdZdZdS)�BranchReferenceForbiddenzRTrying to mirror a branch reference and the branch type does not allow references.Nr
rrrrr,src@seZdZdZdZdS)�BranchLoopErrorz�Encountered a branch cycle.

    A URL may point to a branch reference or it may point to a stacked branch.
    In either case, it's possible for there to be a cycle in these references,
    and this exception is raised when we detect such a cycle.
    zEncountered a branch cycleN)rrr�__doc__rrrrrr2src@s(eZdZdZdd�Zdd�Zdd�ZdS)	�BranchOpenPolicyz�Policy on how to open branches.

    In particular, a policy determines which branches are okay to open by
    checking their URLs and deciding whether or not to follow branch
    references.
    cCst|j��dS)aWhether we traverse references when mirroring.

        Subclasses must override this method.

        If we encounter a branch reference and this returns false, an error is
        raised.

        :returns: A boolean to indicate whether to follow a branch reference.
        N)�NotImplementedError�should_follow_references��selfrrrrEs
z)BranchOpenPolicy.should_follow_referencescCst|j��dS)a�Validate, maybe modify, 'url' to be used as a stacked-on location.

        :param branch:  The branch that is being opened.
        :param url: The URL that the branch provides for its stacked-on
            location.
        :return: (new_url, check) where 'new_url' is the URL of the branch to
            actually open and 'check' is true if 'new_url' needs to be
            validated by check_and_follow_branch_reference.
        N)r�transform_fallback_location�r�branch�urlrrrrQs
z,BranchOpenPolicy.transform_fallback_locationcCst|j��dS)z�Check a URL.

        Subclasses must override this method.

        :param url: The source URL to check.
        :raise BadUrl: subclasses are expected to raise this or a subclass
            when it finds a URL it deems to be unacceptable.
        N)r�
check_one_url�rrrrrr ]s	zBranchOpenPolicy.check_one_urlN)rrrrrrr rrrrr=src@s2eZdZdZddd�Zdd�Zdd�Zd	d
�ZdS)�_BlacklistPolicyz�Branch policy that forbids certain URLs.

    This doesn't cope with various alternative spellings of URLs,
    with e.g. url encoding. It's mostly useful for tests.
    NcCs|durt�}||_||_dS�N)�set�	_bad_urls�_should_follow_references)rrZbad_urlsrrr�__init__psz_BlacklistPolicy.__init__cCs|jSr#�r&rrrrrvsz)_BlacklistPolicy.should_follow_referencescCs||jvrt|��dSr#)r%rr!rrrr ys
z_BlacklistPolicy.check_one_urlcCst�|j|�dfS)z�See `BranchOpenPolicy.transform_fallback_location`.

        This class is not used for testing our smarter stacking features so we
        just do the simplest thing: return the URL that would be used anyway
        and don't check it.
        F�r�join�baserrrrr}sz,_BlacklistPolicy.transform_fallback_location)N�rrrrr'rr rrrrrr"is

r"cs eZdZdZ�fdd�Z�ZS)�AcceptAnythingPolicyz(Accept anything, to make testing easier.cstt|��dt��dS�NT)�superr-r'r$r��	__class__rrr'�szAcceptAnythingPolicy.__init__)rrrrr'�
__classcell__rrr0rr-�sr-c@s2eZdZdZddd�Zdd�Zdd	�Zd
d�ZdS)
�WhitelistPolicyz,Branch policy that only allows certain URLs.NFcCs*|durg}tdd�|D��|_||_dS)Ncss|]}|�d�VqdS)�/N)�rstrip)�.0rrrr�	<genexpr>��z+WhitelistPolicy.__init__.<locals>.<genexpr>)r$�allowed_urls�check)rrr9r:rrrr'�szWhitelistPolicy.__init__cCs|jSr#r(rrrrr�sz(WhitelistPolicy.should_follow_referencescCs|�d�|jvrt|��dS)Nr4)r5r9rr!rrrr �szWhitelistPolicy.check_one_urlcCst�|j|�|jfS)z�See `BranchOpenPolicy.transform_fallback_location`.

        Here we return the URL that would be used anyway and optionally check
        it.
        )rr*r+r:rrrrr�sz+WhitelistPolicy.transform_fallback_location)NFr,rrrrr3�s�
r3c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�SingleSchemePolicyz=Branch open policy that rejects URLs not on the given scheme.cCs
||_dSr#)�allowed_scheme)rr<rrrr'�szSingleSchemePolicy.__init__cCsdSr.rrrrrr�sz+SingleSchemePolicy.should_follow_referencescCst�|j|�dfSr.r)rrrrr�sz.SingleSchemePolicy.transform_fallback_locationcCs$tj�t|��j|jkr t|��dS)z!Check that `url` is okay to open.N)rZURLZfrom_string�strZschemer<rr!rrrr �sz SingleSchemePolicy.check_one_urlN)rrrrr'rrr rrrrr;�s
r;c@sdeZdZdZe��Zddd�Zedd��Z	dd�Z
ed	d
��Zdd�Zd
d�Z
dd�Zddd�ZdS)�BranchOpenera0Branch opener which uses a URL policy.

    All locations that are opened (stacked-on branches, references) are
    checked against a policy object.

    The policy object is expected to have the following methods:
    * check_one_url
    * should_follow_references
    * transform_fallback_location
    NcCs(||_t�|_|durt��}||_dS)z�Create a new BranchOpener.

        :param policy: The opener policy to use.
        :param probers: Optional list of probers to allow.
            Defaults to local and remote bzr probers.
        N)�policyr$�
_seen_urlsr	Zall_probers�probers)rr?rArrrr'�s
zBranchOpener.__init__cCstj�d|jd�dS)a�Install the ``transform_fallback_location`` hook.

        This is done at module import time, but transform_fallback_locationHook
        doesn't do anything unless the `_active_openers` threading.Local
        object has a 'opener' attribute in this thread.

        This is in a module-level function rather than performed at module
        level so that it can be called in setUp for testing `BranchOpener`
        as breezy.tests.TestCase.setUp clears hooks.
        r�,BranchOpener.transform_fallback_locationHookN)r�hooksZinstall_named_hook�transform_fallback_locationHook)�clsrrr�install_hook�s
�zBranchOpener.install_hookcCsZ||jvrt��|j�|�|j�|�|�|�}|dur>|S|}|j��st|��qdS)aCheck URL (and possibly the referenced URL).

        This method checks that `url` passes the policy's `check_one_url`
        method, and if `url` refers to a branch reference, it checks whether
        references are allowed and whether the reference's URL passes muster
        also -- recursively, until a real branch is found.

        :param url: URL to check
        :raise BranchLoopError: If the branch references form a loop.
        :raise BranchReferenceForbidden: If this opener forbids branch
            references.
        N)r@r�addr?r �follow_referencerr)rrZnext_urlrrr�!check_and_follow_branch_reference�s


z.BranchOpener.check_and_follow_branch_referencecCsPzt|jd�}Wnty&|YS0|j�||�\}}|rH|�|�S|SdS)aInstalled as the 'transform_fallback_location' Branch hook.

        This method calls `transform_fallback_location` on the policy object
        and either returns the url it provides or passes it back to
        check_and_follow_branch_reference.
        �openerN)�getattr�_threading_data�AttributeErrorr?rrI)rErrrJZnew_urlr:rrrrD�s

rBcOsT|jtjdvrtd��||j_z||i|��W|j`t�|_S|j`t�|_0dS)Nrzhook not installed)rDrrC�AssertionErrorrLrJr$r@)r�callable�args�kwrrr�3run_with_transform_fallback_location_hook_installeds���z@BranchOpener.run_with_transform_fallback_location_hook_installedcs:�fdd�}�fdd�}t|�}t|||�\}}|�|�S)z�Simple BzrDir.open clone that only uses specific probers.

        :param url: URL to open
        :return: ControlDir instance
        csL�j�|j�|�|j|j�}|dur2t�|j��t�d|j	|j
|j	�|S)Nz%s is%s redirected to %s)r?r �targetZ_redirected_to�sourcer�NotBranchErrorrZnoter+Zpermanently)�	transport�eZredirection_noticeZredirected_transportrrr�
redirected%s��z*BranchOpener._open_dir.<locals>.redirectedcsft�|j�}�jD]J}|�}z||�|�fWStjyZ}z|}WYd}~qd}~00q|�dSr#)rrUr+rAZprobe_transport)rVZ
last_errorZ
prober_klsZproberrWrrr�find_format0s
z+BranchOpener._open_dir.<locals>.find_format)rr
�open)rrrXrYrV�formatrrr�	_open_dirs
�zBranchOpener._open_dircCs|�|�}|��S)z�Get the branch-reference value at the specified url.

        This exists as a separate method only to be overriden in unit tests.
        )r\Zget_branch_reference)rr�
controldirrrrrH?s
zBranchOpener.follow_referenceFcs2t|t�st���|�}�fdd�}��|||�S)z�Open the Bazaar branch at url, first checking it.

        What is acceptable means is defined by the policy's `follow_reference`
        and `check_one_url` methods.
        cs��|�}|j|d�S)N)�ignore_fallbacks)r\�open_branch)rr^�dirrrrr_Rs
z&BranchOpener.open.<locals>.open_branch)�
isinstancer=�	TypeErrorrIrR)rrr^r_rrrrZGs

�zBranchOpener.open)N)F)rrrr�	threadingZlocalrLr'�classmethodrFrIrDrRr\rHrZrrrrr>�s



 r>cCstt|���|�S)z�Open the branch at `url`, only accessing URLs on `allowed_scheme`.

    :raises BadUrl: An attempt was made to open a URL that was not on
        `allowed_scheme`.
    )r>r;rZ)r<rrrr�open_only_schemeYsre)rZ
__future__rrc�rrrrrr]rr	rVr
rZBzrErrorrrr�objectrr"r-r3r;r>rerFrrrr�<module>s$,