class ErrorResponseValidator(object): def __init__(self): self.validator = JSONValidator(errorResponse_schema) def validate(self, data): self.validator.validate(data) if not data['errorResponse']['errorID'] in ERROR_LIST: raise JSONValidationError('Invalid errorID "%s"'%data['errorResponse']['errorID'])
def __init__(self): self.validator = JSONValidator(errorResponse_schema)
'errorResponse': { 'errorID': string, 'additionalInfo': [string, None] } } ERROR_LIST = [ "_UnknownNode", "_UnknownUser", "_UnknownEmailAddress", "_MissingPOSTParameter", "_IllegalPath", "_NotAuthenticated", "_PermissionDenied", "_DisabledAccount", "_UsernameNotAvailable", "_EmailAddressNotAvailable", "_InvalidUsername", "_InvalidLogin", "_InvalidEmailAddress", "_InvalidActivationKey", "_InvalidURL", "_InvalidMircobloggingOptions", "_ServerError" ] validators = {name: JSONValidator(s) for name, s in schema.items()} # ############################################################################# class ErrorResponseValidator(object): def __init__(self): self.validator = validators['errorResponse'] def validate(self, data): self.validator.validate(data) if not data['errorResponse']['errorID'] in ERROR_LIST: raise JSONValidationError('Invalid errorID "%s"' % data['errorResponse']['errorID']) errorResponseValidator = ErrorResponseValidator()