(arguments, stdout=sys.stdout, stderr=sys.stderr, stdin=sys.stdin)
| 232 | |
| 233 | |
| 234 | def run(arguments, stdout=sys.stdout, stderr=sys.stderr, stdin=sys.stdin): # noqa: D103 |
| 235 | outputter = _Outputter.from_arguments( |
| 236 | arguments=arguments, |
| 237 | stdout=stdout, |
| 238 | stderr=stderr, |
| 239 | ) |
| 240 | |
| 241 | try: |
| 242 | schema = outputter.load(arguments["schema"]) |
| 243 | except _CannotLoadFile: |
| 244 | return 1 |
| 245 | |
| 246 | Validator = arguments["validator"] |
| 247 | if Validator is None: |
| 248 | Validator = validator_for(schema) |
| 249 | |
| 250 | try: |
| 251 | Validator.check_schema(schema) |
| 252 | except SchemaError as error: |
| 253 | outputter.validation_error( |
| 254 | instance_path=arguments["schema"], |
| 255 | error=error, |
| 256 | ) |
| 257 | return 1 |
| 258 | |
| 259 | if arguments["instances"]: |
| 260 | load, instances = outputter.load, arguments["instances"] |
| 261 | else: |
| 262 | def load(_): |
| 263 | try: |
| 264 | return json.load(stdin) |
| 265 | except JSONDecodeError as error: |
| 266 | outputter.parsing_error( |
| 267 | path="<stdin>", exc_info=sys.exc_info(), |
| 268 | ) |
| 269 | raise _CannotLoadFile() from error |
| 270 | instances = ["<stdin>"] |
| 271 | |
| 272 | resolver = _RefResolver( |
| 273 | base_uri=arguments["base_uri"], |
| 274 | referrer=schema, |
| 275 | ) if arguments["base_uri"] is not None else None |
| 276 | |
| 277 | validator = Validator(schema, resolver=resolver) |
| 278 | exit_code = 0 |
| 279 | for each in instances: |
| 280 | try: |
| 281 | instance = load(each) |
| 282 | except _CannotLoadFile: |
| 283 | exit_code = 1 |
| 284 | else: |
| 285 | exit_code |= _validate_instance( |
| 286 | instance_path=each, |
| 287 | instance=instance, |
| 288 | validator=validator, |
| 289 | outputter=outputter, |
| 290 | ) |
| 291 |
no test coverage detected