Пример #1
0
 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)
Пример #2
0
 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
Пример #3
0
 def createBranch(self, requester_id, branch_path):
     if not branch_path.startswith('/'):
         return faults.InvalidPath(branch_path)
     escaped_path = unescape(branch_path.strip('/'))
     registrant = self._person_set.get(requester_id)
     try:
         return self._createBranch(registrant, escaped_path)
     except LaunchpadFault as e:
         return e
     except LaunchpadValidationError as e:
         return faults.PermissionDenied(six.ensure_binary(e.args[0]))
Пример #4
0
 def createBranch(self, requester_id, branch_path):
     if not branch_path.startswith('/'):
         return faults.InvalidPath(branch_path)
     escaped_path = unescape(branch_path.strip('/'))
     registrant = self._person_set.get(requester_id)
     try:
         return self._createBranch(registrant, escaped_path)
     except LaunchpadFault as e:
         return e
     except LaunchpadValidationError as e:
         msg = e.args[0]
         if isinstance(msg, unicode):
             msg = msg.encode('utf-8')
         return faults.PermissionDenied(msg)
Пример #5
0
        def create_branch(requester):
            if not branch_path.startswith('/'):
                return faults.InvalidPath(branch_path)
            escaped_path = unescape(branch_path.strip('/'))
            try:
                namespace, branch_name, link_func, path = (
                    self._getBranchNamespaceExtras(escaped_path, requester))
            except ValueError:
                return faults.PermissionDenied("Cannot create branch at '%s'" %
                                               branch_path)
            except InvalidNamespace:
                return faults.PermissionDenied("Cannot create branch at '%s'" %
                                               branch_path)
            except NoSuchPerson as e:
                return faults.NotFound("User/team '%s' does not exist." %
                                       e.name)
            except NoSuchProduct as e:
                return faults.NotFound("Project '%s' does not exist." % e.name)
            except InvalidProductName as e:
                return faults.InvalidProductName(escape(e.name))
            except NoSuchSourcePackageName as e:
                try:
                    getUtility(ISourcePackageNameSet).new(e.name)
                except InvalidName:
                    return faults.InvalidSourcePackageName(e.name)
                return self.createBranch(login_id, branch_path)
            except NameLookupFailed as e:
                return faults.NotFound(str(e))
            try:
                branch = namespace.createBranch(BranchType.HOSTED, branch_name,
                                                requester)
            except LaunchpadValidationError as e:
                msg = e.args[0]
                if isinstance(msg, unicode):
                    msg = msg.encode('utf-8')
                return faults.PermissionDenied(msg)
            except BranchCreationException as e:
                return faults.PermissionDenied(str(e))

            if link_func:
                try:
                    link_func(branch)
                except Unauthorized:
                    # We don't want to keep the branch we created.
                    transaction.abort()
                    return faults.PermissionDenied(
                        "Cannot create linked branch at '%s'." % path)

            return branch.id