205
205
cls.transformFallbackLocationHook,
206
206
'SafeBranchOpener.transformFallbackLocationHook')
208
def checkAndFollowBranchReference(self, url):
208
def checkAndFollowBranchReference(self, url, open_dir=None):
209
209
"""Check URL (and possibly the referenced URL) for safety.
211
211
This method checks that `url` passes the policy's `checkOneURL`
244
244
new_url, check = opener.policy.transformFallbackLocation(branch, url)
246
return opener.checkAndFollowBranchReference(new_url)
246
return opener.checkAndFollowBranchReference(new_url,
247
getattr(cls._threading_data, "open_dir"))
250
def runWithTransformFallbackLocationHookInstalled(
251
self, callable, *args, **kw):
251
def _runWithTransformFallbackLocationHookInstalled(
252
self, open_dir, callable, *args, **kw):
252
253
assert (self.transformFallbackLocationHook in
253
254
Branch.hooks['transform_fallback_location'])
254
255
self._threading_data.opener = self
256
self._threading_data.open_dir = open_dir
256
258
return callable(*args, **kw)
260
del self._threading_data.open_dir
258
261
del self._threading_data.opener
259
262
# We reset _seen_urls here to avoid multiple calls to open giving
260
263
# spurious loop exceptions.
261
264
self._seen_urls = set()
263
def followReference(self, url):
266
def followReference(self, url, open_dir=None):
264
267
"""Get the branch-reference value at the specified url.
266
269
This exists as a separate method only to be overriden in unit tests.
268
bzrdir = BzrDir.open(url)
272
open_dir = BzrDir.open
273
bzrdir = open_dir(url)
269
274
return bzrdir.get_branch_reference()
276
def open(self, url, open_dir=None):
272
277
"""Open the Bazaar branch at url, first checking for safety.
274
279
What safety means is defined by a subclasses `followReference` and
275
280
`checkOneURL` methods.
277
url = self.checkAndFollowBranchReference(url)
278
return self.runWithTransformFallbackLocationHookInstalled(
282
url = self.checkAndFollowBranchReference(url, open_dir=open_dir)
284
open_dir = BzrDir.open
285
def open_branch(url):
287
return dir.open_branch()
288
return self._runWithTransformFallbackLocationHookInstalled(
289
open_dir, open_branch, url)
282
292
def safe_open(allowed_scheme, url):