def performLookup(self, requester_id, lookup, branch_name_only=False): branch = None if branch_name_only and lookup['type'] != 'branch_name': return if lookup['type'] == 'control_name': return self._serializeControlDirectory(requester_id, lookup) elif lookup['type'] == 'id': branch = self._branch_set.get(lookup['branch_id']) if branch is None: return None trailing = lookup['trailing'] elif lookup['type'] == 'alias': result = get_first_path_result(lookup['lp_path'], lambda l: self.performLookup(requester_id, l, branch_name_only=True), None) if result is not None: return result product_name = lookup['lp_path'].split('/', 2)[0] product = self._product_set.getByName(product_name) if product is None: return None branch = product.development_focus.branch trailing = lookup['lp_path'][len(product_name):] elif lookup['type'] == 'branch_name': branch = self._branch_set._find( unique_name=lookup['unique_name']) trailing = escape(lookup['trailing']) else: return None if branch is not None: serialized = self._serializeBranch(requester_id, branch, trailing.lstrip('/'), lookup['type'] == 'id') if serialized is not None: return serialized
def translatePath(self, requester_id, path): if not path.startswith('/'): return faults.InvalidPath(path) result = get_first_path_result(unescape(path.strip('/')), lambda l: self.performLookup(requester_id, l), None) if result is not None: return result else: return faults.PathTranslationError(path)
def translate_path(requester): if not path.startswith('/'): return faults.InvalidPath(path) stripped_path = unescape(path.strip('/')) lookup = lambda l: self.performLookup(requester_id, path, l) result = get_first_path_result(stripped_path, lookup, None) if result is None: raise faults.PathTranslationError(path) return result
def getByHostingPath(self, path): return get_first_path_result(path, self.performLookup, (None, ''))