Ejemplo n.º 1
0
def get_schema():
    schema_path = PACKAGE_DIR / 'schema.yml'
    with schema_path.open('rb') as schema_file:
        schema = yaml.safe_load(schema_file)
        rx = pyrx.Factory({"register_core_types": True})
        schema = rx.make_schema(schema)

        return schema
Ejemplo n.º 2
0
 def setUp(self):
     rx = pyrx.Factory({"register_core_types": True})
     schema_src = {
         "type": "//rec",
         "required": {
             "a": "//str",
             "b": "//int",
         },
         "optional": {
             "c": "//bool",
         },
     }
     self.schema = rx.make_schema(schema_src)
Ejemplo n.º 3
0
def get_schema(name, schemata, trace=False):
    rx = pyrx.Factory({"register_core_types": True})

    if 'composedtype' in schemata:
        learnable = learn(rx, name, schemata['composedtype'])
        if not learnable:
            return

    schema = None
    try:
        schema = rx.make_schema(schemata['schema'], trace=trace)
    except pyrx.RxError:
        check('test_invalid_schema_{}'.format(name), 'assertTrue',
              schemata.get('invalid', False))
    else:
        if 'invalid' in schemata:
            check('test_valid_schema_{}'.format(name), 'assertFalse',
                  schema['invalid'])

    return schema
Ejemplo n.º 4
0
 def __init__(self):
     self.rx = pyrx.Factory({"register_core_types": True})
Ejemplo n.º 5
0
except ImportError:
    from urllib.request import urlopen, HTTPError  # Py3
import imp
import os
import zipfile
from pathlib import Path
import yaml
import json
import gzip
import random
from math import ceil, floor
from menpobench.schema import schema_error_report, schema_is_valid
from menpobench.exception import (ModuleNotFoundError, SchemaError,
                                  MissingMetadataError)
import pyrx
rx = pyrx.Factory({"register_core_types": True})


def checksum(filepath, blocksize=65536):
    r"""
    Report the SHA-1 checksum as a hex digest for a file at a path.
    """
    sha = hashlib.sha1()
    with open(str(filepath), 'rb') as f:
        buf = f.read(blocksize)
        while len(buf) > 0:
            sha.update(buf)
            buf = f.read(blocksize)
    return sha.hexdigest()

Ejemplo n.º 6
0
import click
import os
import io
import yaml
import pyrx
import jsonschema

from .schema import rx_schema, json_schema, s2_schema

rx = pyrx.Factory({'register_core_types': True})

schema = rx.make_schema(rx_schema)


@click.command()
@click.option('--inputdir',
              type=click.Path(exists=True,
                              file_okay=False,
                              readable=True,
                              resolve_path=True),
              help='Directory that contains Sigma yaml files.',
              required=True)
@click.option('--method',
              type=click.Choice(['rx', 'jsonschema', 's2'],
                                case_sensitive=False),
              default='rx',
              help='Validation method.')
def cli(inputdir, method):
    results = []

    filepaths = [