Part of lp.codehosting.safe_open View In Hierarchy
Known subclasses: lp.codehosting.tests.test_safe_open.TestSafeBranchOpenerCheckAndFollowBranchReference.StubbedSafeBranchOpener
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. |
Parameters | policy | The opener policy to use. |
probers | Optional list of probers to allow. Defaults to local and remote bzr probers. |
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.
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.
Parameters | url | URL to check |
Raises | BranchLoopError | If the branch references form a loop. |
BranchReferenceForbidden | If this opener forbids branch references. |
This method calls transformFallbackLocation
on the policy object and
either returns the url it provides or passes it back to
checkAndFollowBranchReference.
This exists as a separate method only to be overridden in unit tests.
Parameters | url | URL to open |
Returns | ControlDir instance |
What safety means is defined by a subclasses followReference
and
checkOneURL
methods.