2525
2626import aiofiles
2727import boto3
28- import jsonschema .validators
2928import lib .core as constants
30- from jsonschema import Draft7Validator
31- from jsonschema import ValidationError
29+ import superannotate_schemas
3230from lib .core .conditions import Condition
3331from lib .core .conditions import CONDITION_EQ as EQ
3432from lib .core .entities import BaseItemEntity
@@ -309,7 +307,7 @@ def __init__(
309307
310308 def validate_project_type (self ):
311309 if self ._project .type == constants .ProjectType .PIXEL .value :
312- raise ValidationError ("Unsupported project type." )
310+ raise AppException ("Unsupported project type." )
313311
314312 def _validate_json (self , json_data : dict ) -> list :
315313 if self ._project .type >= constants .ProjectType .PIXEL .value :
@@ -1227,7 +1225,7 @@ def execute(self):
12271225
12281226class ValidateAnnotationUseCase (BaseReportableUseCase ):
12291227 DEFAULT_VERSION = "V1.00"
1230- SCHEMAS : Dict [str , Draft7Validator ] = {}
1228+ SCHEMAS : Dict [str , superannotate_schemas . Draft7Validator ] = {}
12311229 PATTERN_MAP = {
12321230 "\\ d{4}-[01]\\ d-[0-3]\\ dT[0-2]\\ d:[0-5]\\ d:[0-5]\\ d(?:\\ .\\ d{3})Z" : "does not match YYYY-MM-DDTHH:MM:SS.fffZ" ,
12331231 "^(?=.{1,254}$)(?=.{1,64}@)[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\ .[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\ .[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$" : "invalid email" ,
@@ -1278,15 +1276,17 @@ def oneOf(validator, oneOf, instance, schema): # noqa
12781276 const_key , instance
12791277 )
12801278 if not instance_type :
1281- yield ValidationError ("type required" )
1279+ yield superannotate_schemas . ValidationError ("type required" )
12821280 return
12831281 if const_key and instance_type == _type :
12841282 errs = list (
12851283 validator .descend (instance , sub_schema , schema_path = index )
12861284 )
12871285 if not errs :
12881286 return
1289- yield ValidationError ("invalid instance" , context = errs )
1287+ yield superannotate_schemas .ValidationError (
1288+ "invalid instance" , context = errs
1289+ )
12901290 return
12911291 else :
12921292 subschemas = enumerate (oneOf )
@@ -1299,24 +1299,25 @@ def oneOf(validator, oneOf, instance, schema): # noqa
12991299 break
13001300 all_errors .extend (errs )
13011301 else :
1302- yield ValidationError (
1302+ yield superannotate_schemas . ValidationError (
13031303 f"{ instance !r} is not valid under any of the given schemas" ,
13041304 context = all_errors [:1 ],
13051305 )
1306- # yield from jsonschema._validators.oneOf( # noqa
1307- # validator, oneOf, instance, schema
1308- # )
13091306 if const_key :
1310- yield ValidationError (f"invalid { '.' .join (const_key )} " )
1307+ yield superannotate_schemas .ValidationError (
1308+ f"invalid { '.' .join (const_key )} "
1309+ )
13111310
13121311 @staticmethod
13131312 def _pattern (validator , patrn , instance , schema ):
13141313 if validator .is_type (instance , "string" ) and not re .search (patrn , instance ):
13151314 _patrn = ValidateAnnotationUseCase .PATTERN_MAP .get (patrn )
13161315 if _patrn :
1317- yield ValidationError (f"{ instance } { _patrn } " )
1316+ yield superannotate_schemas . ValidationError (f"{ instance } { _patrn } " )
13181317 else :
1319- yield ValidationError (f"{ instance } does not match { patrn } " )
1318+ yield superannotate_schemas .ValidationError (
1319+ f"{ instance } does not match { patrn } "
1320+ )
13201321
13211322 @staticmethod
13221323 def iter_errors (self , instance , _schema = None ):
@@ -1325,7 +1326,7 @@ def iter_errors(self, instance, _schema=None):
13251326 if _schema is True :
13261327 return
13271328 elif _schema is False :
1328- yield jsonschema . exceptions .ValidationError (
1329+ yield superannotate_schemas .ValidationError (
13291330 f"False schema does not allow { instance !r} " ,
13301331 validator = None ,
13311332 validator_value = None ,
@@ -1334,7 +1335,7 @@ def iter_errors(self, instance, _schema=None):
13341335 )
13351336 return
13361337
1337- scope = jsonschema .validators ._id_of (_schema ) # noqa
1338+ scope = superannotate_schemas .validators ._id_of (_schema ) # noqa
13381339 _schema = copy .copy (_schema )
13391340 if scope :
13401341 self .resolver .push_scope (scope )
@@ -1344,7 +1345,7 @@ def iter_errors(self, instance, _schema=None):
13441345 ref = _schema .pop ("$ref" )
13451346 validators .append (("$ref" , ref ))
13461347
1347- validators .extend (jsonschema .validators .iteritems (_schema ))
1348+ validators .extend (superannotate_schemas .validators .iteritems (_schema ))
13481349
13491350 for k , v in validators :
13501351 validator = self .VALIDATORS .get (k )
@@ -1381,7 +1382,7 @@ def extract_path(path):
13811382 real_path .append (item )
13821383 return real_path
13831384
1384- def _get_validator (self , version : str ) -> Draft7Validator :
1385+ def _get_validator (self , version : str ) -> superannotate_schemas . Draft7Validator :
13851386 key = f"{ self ._project_type } __{ version } "
13861387 validator = ValidateAnnotationUseCase .SCHEMAS .get (key )
13871388 if not validator :
@@ -1393,7 +1394,7 @@ def _get_validator(self, version: str) -> Draft7Validator:
13931394 if not schema_response .data :
13941395 ValidateAnnotationUseCase .SCHEMAS [key ] = lambda x : x
13951396 return ValidateAnnotationUseCase .SCHEMAS [key ]
1396- validator = jsonschema .Draft7Validator (schema_response .data )
1397+ validator = superannotate_schemas .Draft7Validator (schema_response .data )
13971398 from functools import partial
13981399
13991400 iter_errors = partial (self .iter_errors , validator )
0 commit comments