mirror of
https://github.com/EDCD/EDDN.git
synced 2025-06-09 11:52:16 +03:00
Make Validator its own class, because it's going to want state soon.
This commit is contained in:
parent
2d406f9e25
commit
fdeea2f7c2
@ -11,7 +11,7 @@ import zlib
|
|||||||
import zmq.green as zmq
|
import zmq.green as zmq
|
||||||
from eddn import __version__ as EDDN_VERSION
|
from eddn import __version__ as EDDN_VERSION
|
||||||
from eddn.conf import Settings
|
from eddn.conf import Settings
|
||||||
from eddn.Validator import validate, ValidationSeverity
|
from eddn.Validator import Validator, ValidationSeverity
|
||||||
|
|
||||||
from gevent import monkey
|
from gevent import monkey
|
||||||
monkey.patch_all()
|
monkey.patch_all()
|
||||||
@ -28,6 +28,8 @@ sender = context.socket(zmq.PUB)
|
|||||||
for binding in Settings.GATEWAY_SENDER_BINDINGS:
|
for binding in Settings.GATEWAY_SENDER_BINDINGS:
|
||||||
sender.bind(binding)
|
sender.bind(binding)
|
||||||
|
|
||||||
|
validator = Validator()
|
||||||
|
|
||||||
|
|
||||||
def push_message(string_message):
|
def push_message(string_message):
|
||||||
"""
|
"""
|
||||||
@ -110,7 +112,7 @@ def parse_and_error_handle(data):
|
|||||||
logger.error("Error to %s: %s" % (get_remote_address(), exc.message))
|
logger.error("Error to %s: %s" % (get_remote_address(), exc.message))
|
||||||
return exc.message
|
return exc.message
|
||||||
|
|
||||||
validationResults = validate(parsed_message)
|
validationResults = validator.validate(parsed_message)
|
||||||
|
|
||||||
if validationResults.severity <= ValidationSeverity.WARN:
|
if validationResults.severity <= ValidationSeverity.WARN:
|
||||||
|
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
|
|
||||||
|
|
||||||
def validate(json_object):
|
class Validator(object):
|
||||||
results = ValidationResults()
|
|
||||||
|
|
||||||
if "$schemaRef" not in json_object:
|
def validate(self, json_object):
|
||||||
results.add(ValidationSeverity.FATAL, JsonValidationException("No $schemaRef found, unable to validate."))
|
results = ValidationResults()
|
||||||
|
|
||||||
return results
|
if "$schemaRef" not in json_object:
|
||||||
|
results.add(ValidationSeverity.FATAL, JsonValidationException("No $schemaRef found, unable to validate."))
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
class ValidationSeverity(IntEnum):
|
class ValidationSeverity(IntEnum):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user