l.c.s.SafeBranchOpener(object) : class documentation

Part of lp.codehosting.safe_open View In Hierarchy

Known subclasses: lp.codehosting.tests.test_safe_open.TestSafeBranchOpenerCheckAndFollowBranchReference.StubbedSafeBranchOpener

Safe branch opener.

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: * checkOneURL * shouldFollowReferences * transformFallbackLocation

Method __init__ Create a new SafeBranchOpener.
Class Method install_hook Install the transformFallbackLocation hook.
Method checkAndFollowBranchReference Check URL (and possibly the referenced URL) for safety.
Class Method transformFallbackLocationHook Installed as the 'transform_fallback_location' Branch hook.
Method runWithTransformFallbackLocationHookInstalled Undocumented
Method followReference Get the branch-reference value at the specified url.
Method open Open the Bazaar branch at url, first checking for safety.
Method _open_dir Simple BzrDir.open clone that only uses specific probers.
def __init__(self, policy, probers=None):
Create a new SafeBranchOpener.
ParameterspolicyThe opener policy to use.
probersOptional list of probers to allow. Defaults to local and remote bzr probers.
@classmethod
def install_hook(cls):
Install the transformFallbackLocation hook.

This is done at module import time, but transformFallbackLocationHook 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 SafeBranchOpener as bzrlib.tests.TestCase.setUp clears hooks.

def checkAndFollowBranchReference(self, url):
Check URL (and possibly the referenced URL) for safety.

This method checks that url passes the policy's checkOneURL 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.

ParametersurlURL to check
RaisesBranchLoopErrorIf the branch references form a loop.
BranchReferenceForbiddenIf this opener forbids branch references.
@classmethod
def transformFallbackLocationHook(cls, branch, url):
Installed as the 'transform_fallback_location' Branch hook.

This method calls transformFallbackLocation on the policy object and either returns the url it provides or passes it back to checkAndFollowBranchReference.

def runWithTransformFallbackLocationHookInstalled(self, callable, *args, **kw):
Undocumented
def followReference(self, url):
Get the branch-reference value at the specified url.

This exists as a separate method only to be overridden in unit tests.

def _open_dir(self, url):
Simple BzrDir.open clone that only uses specific probers.
ParametersurlURL to open
ReturnsControlDir instance
def open(self, url, ignore_fallbacks=False):
Open the Bazaar branch at url, first checking for safety.

What safety means is defined by a subclasses followReference and checkOneURL methods.

API Documentation for Launchpad, generated by pydoctor at 2018-08-21 00:00:07.