This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
glasnost/shared/common/faults.py

534 lines
14 KiB
Python

# -*- coding: iso-8859-15 -*-
# Glasnost
# By: Odile Bénassy <obenassy@entrouvert.com>
# Romain Chantereau <rchantereau@entrouvert.com>
# Nicolas Clapiès <nclapies@easter-eggs.org>
# Pierre-Antoine Dejace <padejace@entrouvert.be>
# Thierry Dulieu <tdulieu@easter-eggs.com>
# Florent Monnier <monnier@codelutin.com>
# Cédric Musso <cmusso@easter-eggs.org>
# Frédéric Péters <fpeters@entrouvert.be>
# Benjamin Poussin <poussin@codelutin.com>
# Emmanuel Raviart <eraviart@entrouvert.com>
# Sébastien Régnier <regnier@codelutin.com>
# Emmanuel Saracco <esaracco@easter-eggs.com>
#
# Copyright (C) 2000, 2001 Easter-eggs & Emmanuel Raviart
# Copyright (C) 2002 Odile Bénassy, Code Lutin, Thierry Dulieu, Easter-eggs,
# Entr'ouvert, Frédéric Péters, Benjamin Poussin, Emmanuel Raviart,
# Emmanuel Saracco & Théridion
# Copyright (C) 2003 Odile Bénassy, Romain Chantereau, Nicolas Clapiès,
# Code Lutin, Pierre-Antoine Dejace, Thierry Dulieu, Easter-eggs,
# Entr'ouvert, Florent Monnier, Cédric Musso, Ouvaton, Frédéric Péters,
# Benjamin Poussin, Rodolphe Quiédeville, Emmanuel Raviart, Sébastien
# Régnier, Emmanuel Saracco, Théridion & Vecam
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
__doc__ = """Glasnost XMLRPC Faults"""
__version__ = '$Revision$'[11:-2]
import types
import xmlrpclib
faultCodeUnknownServerException = 0
faultCodeUnknownApplicationToken = 1
faultCodeUnknownServerId = 2
faultCodeConnectionRefused = 3
faultCodeUnknownUserToken = 4
faultCodeUserAccessDenied = 5
faultCodeMissingItem = 6
faultCodeUnknownSessionToken = 7
faultCodeApplicationAccessDenied = 8
faultCodeReadOnlyObject = 9
faultCodeMissingMainRubric = 10
faultCodeBadEmailAddress = 11
faultCodeSmtpError = 12
faultCodeNonExistentFilePath = 13
faultCodeNotAFile = 14
faultCodeFileAccessDenied = 15
faultCodeWrongLogin = 16
faultCodeWrongPassword = 17
faultCodeUnknownStringDigest = 18
faultCodeWrongVersion = 19
faultCodeIncompatibleKinds = 20
faultCodeServerRegistrationDenied = 21
faultCodeNoneValue = 22
faultCodeMissingId = 23
faultCodeDuplicateValue = 24
faultCodeInconsistentPrototypeHierarchy = 25
faultCodeNonExistentSlotPath = 26
faultCodeBadValue = 27
faultCodeInvalidSessionToken = 28
faultCodeMissingSlotValue = 29
faultCodeBadSlotValue = 30
faultCodeKindsIncompatibility = 31
faultCodeInvalidSearchRequest = 32
faultCodeUnknownDispatcherInId = 33
faultCodeUnregisteredServer = 34
faultCodeUnknownAuthenticationMethod = 35
faultCodeUncountableGroup = 36
faultCodeNotAGroupUnion = 37
faultCodeIllegalRecursiveGroup = 38
faultCodeUnknownVoteToken = 1000
faultCodeUnknownVoterToken = 1001
faultCodeUnknownElectionToken = 1002
faultCodeDuplicateLogin = 2000
faultCodeDuplicateFullName = 2001
faultCodeDuplicateEmail = 2002
faultCodeDuplicateFingerprint = 2003
faultCodeDuplicateHostName = 3000
# Accounting
faultCodeMissingParent = 4000
faultCodeDuplicateNumber = 4001
# Dataflow.
faultCodeUnknownHolder = 5001
faultCodeUnknownResultConnector = 5002
faultCodeInstructionNotImplementable = 5003
faultCodeDeactivatedInstruction = 5004
Fault = xmlrpclib.Fault
class BaseFault(Fault):
"""Base class for errors in Glasnost XML-RPC.
This class extend the xmlrpclib.Fault constructor with Glasnost faultCode.
Attribute:
==========
*faultCode*:
The error fault code. It must be **set in subclasses**.
"""
def __init__(self, *arguments):
Fault.__init__(self, self.faultCode,
self.makeFaultString(*arguments))
def makeFaultString(self, *arguments):
return 'Unknown fault (arguments = %s)' % str(arguments)
class UnknownServerException(BaseFault):
faultCode = faultCodeUnknownServerException
def makeFaultString(self):
return 'Unknown server exception'
class UnknownApplicationToken(BaseFault):
faultCode = faultCodeUnknownApplicationToken
def makeFaultString(self, applicationToken):
return 'Unknown application token = %s' % applicationToken
class UnknownServerId(BaseFault):
faultCode = faultCodeUnknownServerId
def makeFaultString(self, serverId):
return 'Unknown server id = %s' % serverId
class ConnectionRefused(BaseFault):
faultCode = faultCodeConnectionRefused
def makeFaultString(self, serverHostName, serverPort, functionName,
arguments):
return 'Connection refused by server %s:%s while calling' \
' %s(*%s)' % (serverHostName, serverPort, functionName,
arguments)
class UnknownUserToken(BaseFault):
faultCode = faultCodeUnknownUserToken
def makeFaultString(self, userToken):
return 'Unknown user token = %s' % userToken
class UserAccessDenied(BaseFault):
faultCode = faultCodeUserAccessDenied
def makeFaultString(self):
return 'Access denied to user'
class MissingItem(BaseFault):
faultCode = faultCodeMissingItem
def makeFaultString(self, itemId):
return 'Missing item = %s' % itemId
class UnknownSessionToken(BaseFault):
faultCode = faultCodeUnknownSessionToken
def makeFaultString(self, sessionToken):
return 'Unknown session token = %s' % sessionToken
class ApplicationAccessDenied(BaseFault):
faultCode = faultCodeApplicationAccessDenied
def makeFaultString(self, virtualServerId):
return 'Access denied to application = %s' % virtualServerId
class ReadOnlyObject(BaseFault):
faultCode = faultCodeReadOnlyObject
def makeFaultString(self):
return 'Object is read only'
class MissingMainRubric(BaseFault):
faultCode = faultCodeMissingMainRubric
def makeFaultString(self):
return 'Main rubric is missing'
class BadEmailAddress(BaseFault):
faultCode = faultCodeBadEmailAddress
def makeFaultString(self, email):
return 'Bad email address = %s' % email
class SmtpError(BaseFault):
faultCode = faultCodeSmtpError
def makeFaultString(self):
return 'A SMTP error occurred'
class NonExistentFilePath(BaseFault):
faultCode = faultCodeNonExistentFilePath
def makeFaultString(self, filePath):
return 'Non existent file path = %s' % filePath
class NotAFile(BaseFault):
faultCode = faultCodeNotAFile
def makeFaultString(self, filePath):
return 'Not a file = %s' % filePath
class FileAccessDenied(BaseFault):
faultCode = faultCodeFileAccessDenied
def makeFaultString(self, filePath):
return 'File access denied = %s' % filePath
class WrongLogin(BaseFault):
faultCode = faultCodeWrongLogin
def makeFaultString(self, login):
return 'Unknown login = "%s"' % login
class WrongPassword(BaseFault):
faultCode = faultCodeWrongPassword
def makeFaultString(self, password):
return 'Unknown password = "%s"' % password
class UnknownStringDigest(BaseFault):
faultCode = faultCodeUnknownStringDigest
def makeFaultString(self, digest):
return 'Unknown string digest = "%s"' % digest
class WrongVersion(BaseFault):
faultCode = faultCodeWrongVersion
def makeFaultString(self):
return 'Wrong version'
class IncompatibleKinds(BaseFault):
faultCode = faultCodeIncompatibleKinds
def makeFaultString(self, kind1, kind2):
return 'Incompatible kinds : %s(%s) and %s(%s)' % (
kind1, kind1.__dict__, kind2, kind2.__dict__)
class ServerRegistrationDenied(BaseFault):
faultCode = faultCodeServerRegistrationDenied
def makeFaultString(self, hostName, port):
return 'Registration denied to host name = %s, port = %s' % (
hostName, port)
class NoneValue(BaseFault):
faultCode = faultCodeNoneValue
def makeFaultString(self):
return 'Wrong value: None'
class MissingId(BaseFault):
faultCode = faultCodeMissingId
def makeFaultString(self):
return 'Missing ID'
class DuplicateValue(BaseFault):
faultCode = faultCodeDuplicateValue
def makeFaultString(self, name, value):
return 'Duplicate value for %s = %s' % (name, value)
class InconsistentPrototypeHierarchy(BaseFault):
faultCode = faultCodeInconsistentPrototypeHierarchy
def makeFaultString(self, implementation):
return 'Inconsistent prototype hierarchy for implementation %s' \
% implementation
class NonExistentSlotPath(BaseFault):
faultCode = faultCodeNonExistentSlotPath
def makeFaultString(self, slotPath):
return 'Non existent slot path = %s' % slotPath
class BadValue(BaseFault):
faultCode = faultCodeBadValue
def makeFaultString(self):
return 'Bad value for object'
class InvalidSessionToken(BaseFault):
faultCode = faultCodeInvalidSessionToken
def makeFaultString(self, sessionToken):
return 'Invalid session token = %s' % sessionToken
class MissingSlotValue(BaseFault):
faultCode = faultCodeMissingSlotValue
def makeFaultString(self, slot):
return 'Missing slot = %s' % (slot)
class BadSlotValue(BaseFault):
faultCode = faultCodeBadSlotValue
def makeFaultString(self, slot, value):
return 'Bad value (= %s) for slot "%s"' % (value, slot)
class KindsIncompatibility(BaseFault):
faultCode = faultCodeKindsIncompatibility
def makeFaultString(self, theoricalKind, realKind):
return 'Kind %s doesn\'t accept kind %s' % (theoricalKind, realKind)
class InvalidSearchRequest(BaseFault):
faultCode = faultCodeInvalidSearchRequest
def makeFaultString(self, searchKeyword, searchValue):
return 'Invalid search request (%s = %s)' % (
searchKeyword, searchValue)
class UnknownDispatcherInId(BaseFault):
faultCode = faultCodeUnknownDispatcherInId
def makeFaultString(self, id):
import tools_new as commonTools
return 'Unknown dispatcher (= %s) in id (= %s)' % (
commonTools.extractDispatcherId(id), id)
class UnregisteredServer(BaseFault):
faultCode = faultCodeUnregisteredServer
def makeFaultString(self, hostName, port):
return 'Unregistered server: host name = %s, port = %s' % (
hostName, port)
class UnknownAuthenticationMethod(BaseFault):
faultCode = faultCodeUnknownAuthenticationMethod
def makeFaultString(self, authenticationMethod):
return 'Unknown authentication method: %s' % authenticationMethod
class UncountableGroup(BaseFault):
faultCode = faultCodeUncountableGroup
def makeFaultString(self, group):
return 'Uncountable group: %s' % group
class NotAGroupUnion(BaseFault):
faultCode = faultCodeNotAGroupUnion
def makeFaultString(self, group):
return 'Group %s is not an union' % group
class IllegalRecursiveGroup(BaseFault):
faultCode = faultCodeIllegalRecursiveGroup
def makeFaultString(self, groupId):
return 'Illegal recursive group %s' % groupId
# Vote
class UnknownVoteToken(BaseFault):
faultCode = faultCodeUnknownVoteToken
def makeFaultString(self, voteToken):
return 'Unknown vote token = %s' % voteToken
class UnknownVoterToken(BaseFault):
faultCode = faultCodeUnknownVoterToken
def makeFaultString(self, voterToken):
return 'Unknown voter token = %s' % voterToken
class UnknownElectionToken(BaseFault):
faultCode = faultCodeUnknownElectionToken
def makeFaultString(self, electionToken):
return 'Unknown election token = %s' % electionToken
#
class DuplicateLogin(BaseFault):
faultCode = faultCodeDuplicateLogin
def makeFaultString(self, login):
return 'Duplicate login = %s' % login
class DuplicateFullName(BaseFault):
faultCode = faultCodeDuplicateFullName
def makeFaultString(self, fullName):
return 'Duplicate fullName = %s' % fullName
class DuplicateEmail(BaseFault):
faultCode = faultCodeDuplicateEmail
def makeFaultString(self, email):
return 'Duplicate email address = %s' % email
class DuplicateFingerprint(BaseFault):
faultCode = faultCodeDuplicateFingerprint
def makeFaultString(self, fingerprint):
return 'Duplicate fingerprint = %s' % fingerprint
class DuplicateHostName(BaseFault):
faultCode = faultCodeDuplicateHostName
def makeFaultString(self, hostName):
return 'Duplicate host name = %s' % hostName
class DuplicateNumber(BaseFault):
faultCode = faultCodeDuplicateNumber
def makeFaultString(self, number):
return 'Duplicate number = %s' % number
class MissingParent(BaseFault):
faultCode = faultCodeMissingParent
def makeFaultString(self, objectId):
return 'Missing parent for %s' % objectId
# Dataflow.
class UnknownHolder(BaseFault):
faultCode = faultCodeUnknownHolder
def makeFaultString(self, instruction, holderName):
return 'Unknown value holder (= %s) in instruction %s' % (
holderName, instruction)
class UnknownResultConnector(BaseFault):
faultCode = faultCodeUnknownResultConnector
def makeFaultString(self, instruction, pinNumber, connector):
return 'Unknown result connector (= %s) in pin %s of instruction %s' \
% (connector, pinNumber, instruction)
class InstructionNotImplementable(BaseFault):
faultCode = faultCodeInstructionNotImplementable
def makeFaultString(self, instruction):
return 'Instruction %s can not be implemented' % instruction
class DeactivatedInstruction(BaseFault):
faultCode = faultCodeDeactivatedInstruction
def makeFaultString(self, instruction):
return 'Instruction %s is deactivated' % instruction
faults = {}
for value in locals().values():
if type(value) == types.ClassType and not value in (Fault, BaseFault):
faults[value.faultCode] = value