def test_returns_fault_if_code_matches_one_of_set(self): # trap_fault returns the Fault inside the Failure if the fault code # matches even one of the given fault codes. failure = self.makeFailure(TestFaultOne) fault = trap_fault(failure, TestFaultOne, TestFaultTwo) self.assertEqual(TestFaultOne.error_code, fault.faultCode) self.assertEqual(TestFaultOne.msg_template, fault.faultString)
def test_returns_fault_if_code_matches(self): # trap_fault returns the Fault inside the Failure if the fault code # matches what's given. failure = self.makeFailure(TestFaultOne) fault = trap_fault(failure, TestFaultOne) self.assertEqual(TestFaultOne.error_code, fault.faultCode) self.assertEqual(TestFaultOne.msg_template, fault.faultString)
def translate_fault(fail): # We turn faults.NotFound into a PermissionDenied, even # though one might think that it would make sense to raise # NoSuchFile. Sadly, raising that makes the client do "clever" # things like say "Parent directory of # bzr+ssh://bazaar.launchpad.dev/~noone/firefox/branch does not # exist. You may supply --create-prefix to create all leading # parent directories", which is just misleading. fault = trap_fault(fail, faults.NotFound, faults.PermissionDenied, faults.InvalidSourcePackageName, faults.InvalidProductName) faultString = six.ensure_binary(fault.faultString) return failure.Failure( PermissionDenied(virtual_url_fragment, faultString))
def translate_fault(fail): # We turn faults.NotFound into a PermissionDenied, even # though one might think that it would make sense to raise # NoSuchFile. Sadly, raising that makes the client do "clever" # things like say "Parent directory of # bzr+ssh://bazaar.launchpad.dev/~noone/firefox/branch does not # exist. You may supply --create-prefix to create all leading # parent directories", which is just misleading. fault = trap_fault( fail, faults.NotFound, faults.PermissionDenied, faults.InvalidSourcePackageName, faults.InvalidProductName, ) faultString = fault.faultString if isinstance(faultString, unicode): faultString = faultString.encode("utf-8") return failure.Failure(PermissionDenied(virtual_url_fragment, faultString))
def _reportNoSuchUser(self, failure, credentials): """Report the user named in the credentials not existing nicely.""" trap_fault(failure, faults.NoSuchPersonWithName) raise UserDisplayedUnauthorizedLogin("No such Launchpad account: %s" % credentials.username)
def path_not_translated(fail): trap_fault(fail, faults.PathTranslationError, faults.PermissionDenied) return failure.Failure(NoSuchFile(virtual_url_fragment))