Make Validator its own class, because it's going to want state soon.

This commit is contained in:
James Muscat 2014-12-17 13:38:06 +00:00
parent 2d406f9e25
commit fdeea2f7c2
2 changed files with 11 additions and 7 deletions

View File

@ -11,7 +11,7 @@ import zlib
import zmq.green as zmq
from eddn import __version__ as EDDN_VERSION
from eddn.conf import Settings
from eddn.Validator import validate, ValidationSeverity
from eddn.Validator import Validator, ValidationSeverity
from gevent import monkey
monkey.patch_all()
@ -28,6 +28,8 @@ sender = context.socket(zmq.PUB)
for binding in Settings.GATEWAY_SENDER_BINDINGS:
sender.bind(binding)
validator = Validator()
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))
return exc.message
validationResults = validate(parsed_message)
validationResults = validator.validate(parsed_message)
if validationResults.severity <= ValidationSeverity.WARN:

View File

@ -1,7 +1,9 @@
from enum import IntEnum
def validate(json_object):
class Validator(object):
def validate(self, json_object):
results = ValidationResults()
if "$schemaRef" not in json_object: