示例#1
0
		def validate(cls, document):

			for key in list(document.keys()):
				if key not in cls.schema or document[key] is None:
					del document[key]

				try:
					if cls.schema[key]['type'] == 'datetime':
						document[key] = parser.parse(document[key])

					elif cls.schema[key]['type'] == 'object_id':
						document[key] = ObjectId(document[key])

				except KeyError:
					pass


			validator = Validator(
				schema=cls.schema
			)

			if not validator.validate(document):
				(document, errors) = cls._remove_unknown(document, validator.errors)
				if len(errors):
					from core.helpers.raise_error import raise_error
					raise_error('validation', 'fields_invalid', code=400, fields=errors)

			return document
示例#2
0
文件: rea_math.py 项目: speker/core
 def exponentiation(number, exponent):
     if Validator.number_control([number, exponent])[0]:
         number = Validator.number_control([number, exponent])[1][0]
         exponent = Validator.number_control([number, exponent])[1][1]
         return number**exponent
     else:
         return False
示例#3
0
文件: rea_math.py 项目: speker/core
 def summation_list(number_list):
     total = 0
     if Validator.number_control(number_list)[0]:
         number_list = Validator.number_control(number_list)[1]
         for number in number_list:
             total += number
         return total, type(total)
示例#4
0
文件: rea_math.py 项目: speker/core
 def percent(number, ratio):
     if Validator.number_control([number, ratio])[0]:
         number = Validator.number_control([number, ratio])[1][0]
         ratio = Validator.number_control(([number, ratio]))[1][1]
         return (number * ratio) / 100
     else:
         return False
示例#5
0
文件: rea_math.py 项目: speker/core
 def remainder(first_number, second_number):
     if Validator.number_control([first_number, second_number])[0]:
         first_number = Validator.number_control(
             [first_number, second_number])[1][0]
         second_number = Validator.number_control(
             [first_number, second_number])[1][1]
         return first_number % second_number
     else:
         return False
示例#6
0
文件: rea_math.py 项目: speker/core
 def summation(first_number, second_number):
     if Validator.number_control([first_number, second_number])[0]:
         first_number = Validator.number_control(
             [first_number, second_number])[1][0]
         second_number = Validator.number_control(
             [first_number, second_number])[1][1]
         return first_number + second_number
     else:
         return False
示例#7
0
文件: rea_math.py 项目: speker/core
 def multiplication_list(multiplier_list):
     multiply = 1
     if Validator.number_control(multiplier_list)[0]:
         multiplier_list = Validator.number_control(multiplier_list)[1]
         for number in multiplier_list:
             multiply *= number
         return multiply
     else:
         return False
示例#8
0
文件: rea_math.py 项目: speker/core
 def multiplication(multiplicand, multiplier):
     if Validator.number_control([multiplicand, multiplier])[0]:
         multiplicand = Validator.number_control([multiplicand,
                                                  multiplier])[1][0]
         multiplier = Validator.number_control([multiplicand,
                                                multiplier])[1][1]
         return multiplicand * multiplier
     else:
         return False
示例#9
0
文件: rea_math.py 项目: speker/core
 def rea_abs(number):
     if Validator.number_control([number])[0]:
         number = Validator.number_control([number])[1][0]
         if number > 0:
             return number
         else:
             return -number
     else:
         return False
示例#10
0
文件: rea_math.py 项目: speker/core
 def rea_sqrt(number, expo, boolean):
     if Validator.number_control([number, expo])[0]:
         number = Validator.number_control([number])[1][0]
         expo = Validator.number_control([number, expo])[1][1]
         if number > 0 and expo >= 0:
             sqrt_number: Union[float, Any] = number**(1 / expo)
             return ReaMath.call_sqrt(sqrt_number, boolean)
         else:
             return False
     else:
         return False
示例#11
0
文件: rea_math.py 项目: speker/core
 def extraction(first_number, second_number):
     if Validator.number_control([first_number, second_number])[0]:
         first_number = Validator.number_control(
             [first_number, second_number])[1][0]
         second_number = Validator.number_control(
             [first_number, second_number])[1][1]
         if first_number < second_number:
             return second_number - first_number
         else:
             return first_number - second_number
     else:
         return False
示例#12
0
文件: rea_math.py 项目: speker/core
 def division_floor(divided, divisor):
     if Validator.number_control([divided, divisor])[0]:
         divided = Validator.number_control([divided, divisor])[1][0]
         divisor = Validator.number_control([divided, divisor])[1][1]
         if divided != 0 and divisor != 0:
             if divided > divisor:
                 return divided // divisor
             else:
                 return divisor // divided
         else:
             return False
     else:
         return False
示例#13
0
文件: rea_math.py 项目: speker/core
 def different_percent(first_number, second_number, boolean):
     if Validator.number_control([first_number, second_number])[0]:
         first_number = Validator.number_control(
             [first_number, second_number])[1][0]
         second_number = Validator.number_control(
             [first_number, second_number])[1][1]
         if boolean:
             if first_number < second_number:
                 return (first_number / second_number) * 100
             else:
                 return (second_number / first_number) * 100
         else:
             if first_number > second_number:
                 return (first_number / second_number) * 100
             else:
                 return (second_number / first_number) * 100
     else:
         return False
示例#14
0
		def validate(cls, document):

			for key in list(document.keys()):
				if key not in cls.schema:
					del document[key]

				try:
					if cls.schema[key]['type'] == 'datetime':
						document[key] = parser.parse(document[key])

				except KeyError:
					pass


			validator = Validator(
				schema=cls.schema
			)

			if not validator.validate(document):
				print(validator.errors)
				abort(400)

			return document
示例#15
0
 def validator():
     return Validator()
示例#16
0
文件: rea_math.py 项目: speker/core
 def average(number_list):
     if Validator.number_control(number_list)[0]:
         number_list = Validator.number_control(number_list)[1]
         return ReaMath.summation_list(number_list) / len(number_list)
     else:
         return False