mirror of
https://github.com/yweber/lodel2.git
synced 2025-11-27 15:56:53 +01:00
Moved new class exceptions in exceptions.py
This commit is contained in:
parent
120a8028d8
commit
67bd4087a9
5 changed files with 40 additions and 10 deletions
|
|
@ -30,3 +30,15 @@ class LodelExceptions(LodelException):
|
|||
#@note Designed to be raised in dramatic case
|
||||
class LodelFatalError(Exception):
|
||||
pass
|
||||
|
||||
##@brief Designed to be a catched exception.
|
||||
#
|
||||
#@note Designed to be raised in DataHandler
|
||||
class DataNoneValid(Exception):
|
||||
pass
|
||||
|
||||
##@brief Designed to be a catched exception.
|
||||
#
|
||||
#@note Designed to be raised in DataHandler
|
||||
class FieldValidationError(Exception):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -11,11 +11,6 @@ import warnings
|
|||
from lodel.exceptions import *
|
||||
from lodel import logger
|
||||
|
||||
class DataNoneValid(Exception):
|
||||
pass
|
||||
|
||||
class FieldValidationError(Exception):
|
||||
pass
|
||||
|
||||
##@brief Base class for all data handlers
|
||||
#@ingroup lodel2_datahandlers
|
||||
|
|
@ -378,7 +373,7 @@ class MultipleRef(Reference):
|
|||
#@param value *
|
||||
#@throw FieldValidationError if value is unappropriate or can not be cast
|
||||
#@return value
|
||||
#@TODO checkig one by one and put error in a list
|
||||
#@TODO Writing test error for errors when stored multiple references in one field
|
||||
def _check_data_value(self, value):
|
||||
value = super()._check_data_value(value)
|
||||
if not hasattr(value, '__iter__'):
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
import warnings
|
||||
import inspect
|
||||
from lodel.leapi.datahandlers.datas_base import *
|
||||
from lodel.leapi.datahandlers.base_classes import FieldValidationError
|
||||
from lodel.exceptions import *
|
||||
import re
|
||||
|
||||
##@brief Data field designed to handle formated strings
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ import datetime
|
|||
import time
|
||||
import os
|
||||
|
||||
from lodel.leapi.datahandlers.base_classes import DataField, FieldValidationError
|
||||
from lodel.leapi.datahandlers.base_classes import DataField
|
||||
from lodel.exceptions import *
|
||||
|
||||
|
||||
##@brief Data field designed to handle boolean values
|
||||
class Boolean(DataField):
|
||||
|
|
@ -18,6 +20,10 @@ class Boolean(DataField):
|
|||
# kwargs['check_data_value'] = self._check_data_value
|
||||
super().__init__(ftype='bool', **kwargs)
|
||||
|
||||
##@brief Check and cast value in appropriate type
|
||||
#@param value *
|
||||
#@throw FieldValidationError if value is unappropriate or can not be cast
|
||||
#@return value
|
||||
def _check_data_value(self, value):
|
||||
value = super()._check_data_value(value)
|
||||
if not isinstance(value, bool):
|
||||
|
|
@ -34,6 +40,10 @@ class Integer(DataField):
|
|||
def __init__(self, **kwargs):
|
||||
super().__init__( **kwargs)
|
||||
|
||||
##@brief Check and cast value in appropriate type
|
||||
#@param value *
|
||||
#@throw FieldValidationError if value is unappropriate or can not be cast
|
||||
#@return value
|
||||
def _check_data_value(self, value, strict = False):
|
||||
value = super()._check_data_value(value)
|
||||
if (strict and isinstance(value, int)):
|
||||
|
|
@ -68,6 +78,10 @@ class Varchar(DataField):
|
|||
return False
|
||||
return True
|
||||
|
||||
##@brief Check and cast value in appropriate type
|
||||
#@param value *
|
||||
#@throw FieldValidationError if value is unappropriate or can not be cast
|
||||
#@return value
|
||||
def _check_data_value(self, value):
|
||||
value = super()._check_data_value(value)
|
||||
if not isinstance(value, str):
|
||||
|
|
@ -75,6 +89,7 @@ class Varchar(DataField):
|
|||
if len(value) > self.max_length:
|
||||
raise FieldValidationError("The value '%s' is longer than the maximum length of this field (%s)" % (value, self.max_length))
|
||||
return value
|
||||
|
||||
##@brief Data field designed to handle date & time
|
||||
class DateTime(DataField):
|
||||
|
||||
|
|
@ -91,6 +106,10 @@ class DateTime(DataField):
|
|||
self.datetime_format = '%Y-%m-%d' if 'format' not in kwargs else kwargs['format']
|
||||
super().__init__(**kwargs)
|
||||
|
||||
##@brief Check and cast value in appropriate type
|
||||
#@param value *
|
||||
#@throw FieldValidationError if value is unappropriate or can not be cast
|
||||
#@return value
|
||||
def _check_data_value(self, value):
|
||||
value = super()._check_data_value(value)
|
||||
if isinstance(value,str):
|
||||
|
|
@ -116,6 +135,10 @@ class Text(DataField):
|
|||
def __init__(self, **kwargs):
|
||||
super(self.__class__, self).__init__(ftype='text', **kwargs)
|
||||
|
||||
##@brief Check and cast value in appropriate type
|
||||
#@param value *
|
||||
#@throw FieldValidationError if value is unappropriate or can not be cast
|
||||
#@return value
|
||||
def _check_data_value(self, value):
|
||||
value = super()._check_data_value(value)
|
||||
if not isinstance(value, str):
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from lodel.leapi.datahandlers.base_classes import Reference, MultipleRef, SingleRef, FieldValidationError, DataNoneValid
|
||||
|
||||
from lodel.leapi.datahandlers.base_classes import Reference, MultipleRef, SingleRef
|
||||
from lodel.exceptions import *
|
||||
from lodel import logger
|
||||
|
||||
class Link(SingleRef):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue