Пример #1
0
def requirement_item_schema(idclass_tab):
    """
    Return the data specification schema for a requirement line-item.

    """
    item_id = idclass_tab['item']

    requirement_line_item = Schema([
        SUMMARY_TEXT,
        Optional({
            'notes': PARAGRAPH_TEXT,
            Extra: Reject
        }),
        Required({
            Required('type'): Any('guidance', 'mandate', 'information'),
            Extra: Reject
        }),
        Required({
            Required('state'): Any('draft'),
            Extra: Reject
        }),
        Optional({
            Required('ref'): [item_id],
            Extra: Reject
        }), {
            Extra: Reject
        }
    ])

    return requirement_line_item
Пример #2
0
 def test_nested_default_value(self):
     from good import Any, Default
     k_ = Konf(self._get_asset('1.yml'))
     cool_dict = k_('cool_dict', dict(
         khrum=str,
         dfght=int,
         foo=Any(str, Default('bar'))
     ))
     self.assertEqual(cool_dict['foo'], 'bar')
Пример #3
0
def get():
    """
    Return the data validation schema for the dependencies register.

    """
    common = da.check.schema.common
    api_iface_name = Any('include', 'lib_native', 'lib_javascript',
                         'lib_python2', 'lib_python3')
    api_config = Any({}, {api_iface_name: common.LOWERCASE_PATH})
    cli_config = Any({}, {common.LOWERCASE_NAME: common.LOWERCASE_PATH})
    gui_config = Any({}, {common.LOWERCASE_NAME: common.LOWERCASE_PATH})

    return Schema({
        'title': common.TITLE_TEXT,
        'introduction': common.PARAGRAPH_TEXT,
        'register': {
            common.LOWERCASE_NAME: {
                'desc': Any('TBD', common.SUMMARY_TEXT),
                'notes': Any('TBD', common.PARAGRAPH_TEXT),
                'dirname': common.LOWERCASE_NAME,
                'policy': common.LOWERCASE_NAME,
                'api': api_config,
                'cli': cli_config,
                'gui': gui_config,
                'config': {
                    'method':
                    Any('automatic', 'manual', 'n/a'),
                    'tool':
                    Any('bzr', 'git', 'hg', 'svn', 'darcs', 'ftp', 'manual',
                        'n/a', 'TBD'),
                    'url':
                    common.URL
                },
                'build': {
                    'method':
                    Any('automatic', 'manual', 'n/a'),
                    'tool':
                    Any('n/a', 'python_setuptools', 'python_distutils', 'make',
                        'n/a', 'TBD')
                }
            }
        },
        Extra: Reject
    })
Пример #4
0
def function_metadata_schema():
    """
    Return the data validation schema for python function metadata.

    """
    key_value_pair = Schema({da.check.schema.common.LOWERCASE_NAME: str})
    return Schema({
        'type':
        Any('constructor', 'context_manager', 'coroutine', 'function',
            'generator'),
        'args':
        key_value_pair,
        Optional('yields'):
        Any(key_value_pair, str),
        Optional('returns'):
        Any(key_value_pair, str),
        Optional('preconditions'): [str],
        Optional('side_effects'): [str],
    })
Пример #5
0
def function_scope_schema(idclass_tab):
    """
    Return the validation schema for data within python function scope.

    """
    return Schema(
        Any(
            Required(function_metadata_schema()),
            Optional(
                da.check.schema.common.requirement_set_schema(idclass_tab))))
Пример #6
0
def section_content():
    """
    Return the engineering document section content schema.

    """
    return Schema({
        Required('_num'): str,
        Required('_req'): str,
        Required('_txt'): Any(str, None),
        Extra: Reject
    })
Пример #7
0
def get():
    """
    Return data validation schema for the design document repository register.

    """
    common = da.check.schema.common

    return Schema({
        'title': common.TITLE_TEXT,
        'introduction': common.PARAGRAPH_TEXT,
        'register': {
            common.LOWERCASE_PATH: {
                'configuration': Any(None, common.LOWERCASE_HEX)
            }
        },
        Extra: Reject
    })
Пример #8
0
def get(idclass_tab):
    """
    Return the data validation schema for the dependencies register.

    """
    common = da.check.schema.common
    lifecycle_product_id = idclass_tab['lifecycle_product']
    lifecycle_product_class_id = idclass_tab['lifecycle_product_class']

    return Schema({
        'title': common.TITLE_TEXT,
        'introduction': common.PARAGRAPH_TEXT,
        'register': {
            lifecycle_product_id: {
                'name': common.SUMMARY_TEXT,
                'mnemonic': common.LOWERCASE_NAME,
                'class': lifecycle_product_class_id,
                'purpose': Any('TBD', common.PARAGRAPH_TEXT),
                'reference': [common.EXTERNAL_DOC_REF]
            }
        },
        Extra: Reject
    })
Пример #9
0
import os.path
from good import (Schema, All, Any, Range, Allow, Match, message, Msg,
                  Optional, Exclusive, Length, Entire)


@message('Must be a valid directory.')
def IsDir(d):
    d = os.path.expanduser(d)
    assert os.path.isdir(d)
    return d


seed_schema = Any(None, str, All(int, Range(min=0)))

target_subset_schema = Any('random', [All(int, Range(min=0))])

data_schema = Any(
    # generated from operator
    # Schema({
    #     'type':                     'generated',
    #     'operator':                 str,
    #     'bits':                     All(int, Range(min=1)),
    #     Optional('out_width'):      All(int, Range(min=1)),
    #     Optional('add_noise'):      Range(min=0.0),
    #     Optional('targets'):        target_subset_schema,
    #     }),
    # read from file
    Schema({
        'type': 'file',
        'filename': str,
        Optional('dir'): IsDir,
Пример #10
0

FramePair = namedtuple('FramePair', ('frame_1', 'frame_2'))


def _check_frame_pair(frame_pair):
    if (not isinstance(frame_pair, list) or
            len(frame_pair) != 2 or
            not all(isinstance(x, int) for x in frame_pair)):
        raise Invalid('Invalid initial frame pair format')
    return FramePair(*frame_pair)


DATASET_CONFIG_SCHEMA = Schema({
    'tests': {
        Any(str): {
            'camera': str,
            'ground_truth': str,
            'rgb': str,
            Optional('initial_frames'): Any(_check_frame_pair, Default(None))
        }
    }
})


TestInfo = namedtuple('TestInfo', (
    'camera',
    'ground_truth',
    'rgb',
    'initial_frames'
))
Пример #11
0
import data3d
import frameseq

FramePair = namedtuple('FramePair', ('frame_1', 'frame_2'))


def _check_frame_pair(frame_pair):
    if (not isinstance(frame_pair, list) or len(frame_pair) != 2
            or not all(isinstance(x, int) for x in frame_pair)):
        raise Invalid('Invalid initial frame pair format')
    return FramePair(*frame_pair)


DATASET_CONFIG_SCHEMA = Schema({
    'tests': {
        Any(str): {
            'camera': str,
            'ground_truth': str,
            'rgb': str,
            'initial_frames': Any(_check_frame_pair, Default(None))
        }
    }
})

TestInfo = namedtuple('TestInfo',
                      ('camera', 'ground_truth', 'rgb', 'initial_frames'))


def read_config(config_path):
    root = path.dirname(path.abspath(config_path))
    with open(config_path, 'r') as config_file:
Пример #12
0
def get_student_schema(schoolclass):
    def start_before_end():
        def validator(d):
            if 'start_date' not in d or 'end_date' not in d:
                assert False, "La date d'arrivée dans la classe ou la date de départ ne sont pas renseignées"
            if not isinstance(d['start_date'], date) or not isinstance(
                    d['end_date'], date):
                assert False
            assert d['start_date'] <= d[
                'end_date'], "La date d'arrivée dans la classe doit être antérieur à la date de départ"

            return d

        return validator

    schema = Schema(
        {
            'firstname':
            Msg(Length(min=1), "Le prénom doit être renseigné."),
            'lastname':
            Msg(Length(min=1), "Le nom doit être renseigné."),
            Optional('birth_date'):
            Any(
                '',
                Msg(Date('%d/%m/%Y'),
                    "La date de naissance doit être renseignée.")),
            'gender':
            Msg(Any('f', 'm'),
                "Vous devez sélectionner une valeur pour le sexe"),
            'grade':
            All(
                Coerce(int),
                Msg(
                    In([grade.id for grade in schoolclass.grades]),
                    "Le niveau choisi n'est pas disponible pour cette classe.")
            ),
            'start_date':
            All(
                Msg(Date('%d/%m/%Y'),
                    "La date d'arrivée dans la classe doit être renseignée."),
                Msg(
                    Range(schoolclass.schoolyear.start_date,
                          schoolclass.schoolyear.end_date),
                    "La date d'arrivée dans la classe doit être comprise entre le %s et le %s"
                    % (schoolclass.schoolyear.start_date.strftime("%d/%m/%Y"),
                       schoolclass.schoolyear.end_date.strftime("%d/%m/%Y")))),
            'end_date':
            All(
                Msg(Date('%d/%m/%Y'),
                    "La date de départ de la classe doit être renseignée."),
                Msg(
                    Range(schoolclass.schoolyear.start_date,
                          schoolclass.schoolyear.end_date),
                    "La date de départ de la classe doit être comprise entre le %s et le %s"
                    % (schoolclass.schoolyear.start_date.strftime("%d/%m/%Y"),
                       schoolclass.schoolyear.end_date.strftime("%d/%m/%Y")))),
            'ulis':
            Any(Msg(Boolean(), "Le champ ULIS doit être renseigné"),
                Default(False)),
            Entire:
            start_before_end()
        },
        default_keys=Required)

    return schema
Пример #13
0
def get(idclass_schema_tab):
    """
    Return the data validation schema for the codeword register.

    """
    common = da.check.schema.common

    # The quantifier is used to define the
    # relationship between the bounding box
    # and the target entity.
    #
    quantifier = Any(

        # The target object is present everywhere within the ROI.
        #
        # Any declarations falling within the ROI can be considered a true
        # positive. On the other hand, an absence of declarations should only
        # be considered as a missed detection if all detection criteria have
        # been met by the target.
        #
        # Used for probability-of-detection KPI metrics.
        #
        'all'

        # A target object may be present somewhere within the ROI.
        #
        # A declaration falling within the ROI cannot definitively be
        # classified as either a true positive or a false alarm. This
        # quantifier is intended to be used in conjunction with not_exist
        # labels in false alarm rate tests to screen off parts of the data
        # stream that might contain real targets and that should not
        # contribute to false alarm rate metrics.
        #
        'exist',

        # Unless otherwise specified, no target object is present in any part
        # of the ROI.
        #
        # If no other label matches, then a detection in the ROI is
        # definitely a false alarm. Used for false alarm rate tests to
        # identify parts of the data stream that do not contain real targets.
        #
        'not_exist',
    )
    # The bounding_box is used to define a region
    # of interest within the image. In conjunction
    # with the lo/hi byte offsets it may be used
    # to
    bounding_box = Schema({

        # Upper left column (inclusive).
        'ulc': int,

        # Upper left row (inclusive).
        'ulr': int,

        # Lower right column (exclusive).
        'lrc': int,

        # Lower right row (exclusive).
        'lrr': int,
    })

    line_segment = Schema({

        # Upper left column (inclusive).
        'ulc': int,

        # Upper left row (inclusive).
        'ulr': int,

        # Lower right column (exclusive).
        'lrc': int,

        # Lower right row (exclusive).
        'lrr': int,
    })

    compact_target_type = Any(Match('generic_target'))

    extended_target_type = Any(Match('generic_horizon'))

    compact_target_label = Schema({

        # Bounding box.
        "box": bounding_box,

        # Quantifier.
        'qua': quantifier,

        # Target type.
        'typ': compact_target_type
    })

    extended_target_label = Schema({

        # Line segment.
        'lin': line_segment,

        # Quantifier.
        'qua': quantifier,

        # Target type.
        'typ': extended_target_type
    })

    return Schema({

        # Label format type.
        'typ': common.LOWERCASE_NAME,

        # Label format version.
        'ver': int,

        # Unique identifier (GUID).
        'uid': common.LOWERCASE_HEX,

        # Trace to requirement.
        'req': [idclass_schema_tab['item']],

        # Trace to team member responsible.
        'rsp': [idclass_schema_tab['team_member']],

        # Start byte (inclusive) of byte range of interest.
        'lo': common.NUMERIC_STRING,

        # End byte (exclusive) of byte range of interest.
        'hi': common.NUMERIC_STRING,

        # Function specific label payload.
        'lbl': Any(compact_target_label, extended_target_label),
        Extra: Reject
    })
Пример #14
0
    Required('recaptcha'): ReCaptcha()
})

edit_schema = Schema({
    Optional('name'): All(unicode, Length(min=1, max=32)),
    Optional('starts_at'): int,
    Optional('ends_at'): int
})

team_join_schema = Schema({Required('team_id'): unicode})

problem_create_schema = Schema({
    Required('title'):
    All(unicode, Length(min=1, max=32)),
    Required('time_limit'):
    All(Any(float, int), Range(min=0.1, max=10.0)),
    Required('space_limit'):
    All(int, Range(min=16, max=256))
})

problem_edit_schema = Schema({
    Optional('title'):
    All(unicode, Length(min=1, max=32)),
    Optional('time_limit'):
    All(Any(float, int), Range(min=0.1, max=10.0)),
    Optional('space_limit'):
    All(int, Range(min=16, max=256))
})

problem_change_order_schema = Schema({Required('order'): [Schema(int)]})
Пример #15
0
CONNECTIVE_CORNERS_PER_FRAME_REQUIRED = 100
MEDIAN_TRACK_LENGTH_REQUIRED = 3

FramePair = namedtuple('FramePair', ('frame_1', 'frame_2'))


def _check_frame_pair(frame_pair):
    if (not isinstance(frame_pair, list) or len(frame_pair) != 2
            or not all(isinstance(x, int) for x in frame_pair)):
        raise Invalid('Invalid initial frame pair format')
    return FramePair(*frame_pair)


DATASET_CONFIG_SCHEMA = Schema({
    'tests': {
        Any(str): {
            'camera':
            str,
            'ground_truth':
            str,
            'rgb':
            str,
            Optional('initial_frames'):
            Any(_check_frame_pair, Default(None)),
            Optional('translation_error_allowed'):
            Any(Range(0.0, 1.0), Default(TRANSLATION_ERROR_ALLOWED)),
            Optional('rotation_deg_error_allowed'):
            Any(
                Range(0.0, 360.0),
                Default(ROTATION_DEG_ERROR_ALLOWED),
            )
Пример #16
0
# -*- coding: utf-8 -*-
__author__ = 'AminHP'

from good import Schema, All, Any, Required, Optional, Length, Match, Default

create_schema = Schema({
    Required('name'):
    All(unicode, Length(min=1, max=32)),
    Required('members'):
    Any(All([Schema(unicode)], Length(max=2)), Default([]))
})

edit_schema = Schema({
    Optional('name'): All(unicode, Length(min=1, max=32)),
    Optional('members'): All([Schema(unicode)], Length(max=2))
})
Пример #17
0
from konf import Konf
from good import Schema, Optional, Extra, Reject, Invalid, Any, Fallback
from collections import Counter
from webhooker import template_schema

#TODO: use messages to explain what's wrong in the config
is_valid_server_conf = Schema({
    'port': Any(int, Fallback(5000)),
    'debug': Any(bool, Fallback(True))
})

is_valid_hooklist = Schema({Extra: template_schema})


def parse(filename):
    k = Konf(filename)

    # syntax:
    config = {
        'server': k('server', is_valid_server_conf),
        'steam api key': k('steam api key', str),
        'hooks': k('hooks', is_valid_hooklist)
    }

    # semantics:

    return config
Пример #18
0
    Match(r'(^[A-Za-z0-9-+_.]+@[A-Za-z0-9-]+\.[A-Za-z0-9-.]+$)',
          expected='Email address'))

GIT_COMMIT_ISH = Schema(Match(r'[A-Za-z0-9_]', expected='Git commit-ish'))

LOWERCASE_HEX = Schema(
    Match(r'[a-f0-9]', expected='Lowercase hexadecimal string'))

NUMERIC_STRING = Match(r'^[0-9]{1,30}', expected='Numeric decimal string.')

EXTERNAL_DOC_REF = Schema(
    Match(r'[a-z0-9_ ]', expected='External document reference'))

BUILD_RESTRICTION = Schema([str])

LOG_LEVEL = Schema(Any('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG'))

TIMEBOX = Schema(Match(r'[0-9]{4}[AB]', expected='Timebox id: YYMMA/B'))

DATE_YYYYMMDD = All(Any(int, str), Coerce(str),
                    Match(r'[0-9]{8}', expected='yyyymmdd'))

YEAR_YYYY = All(Any(int, str), Coerce(str), Match(r'[0-9]{4}',
                                                  expected='yyyy'))

DATE_MMDD = All(Any(int, str), Coerce(str), Match(r'[0-9]{4}',
                                                  expected='mmdd'))

TIME_HHMMSS = All(Any(int, str), Coerce(str),
                  Match(r'[0-9]{6}', expected='hhmmss'))
Пример #19
0
def file_metadata_schema(idclass_tab):
    """
    Return the data validation schema for python file metadata.

    """
    hiai_copyright = Schema(
        'Copyright 2016 High Integrity Artificial Intelligence Systems')

    hashdist_copyright = Schema(
        'Copyright 2012, Dag Sverre Seljebotn and Ondrej Certik')

    copyright_notice = Any(hiai_copyright, hashdist_copyright)

    apache_license_v2 = Schema(
        'Licensed under the Apache License, Version 2.0 '
        '(the License); you may not use this file except in compliance '
        'with the License. You may obtain a copy of the License at\n'
        'http://www.apache.org/licenses/LICENSE-2.0\n'
        'Unless required by applicable law or agreed to in writing, '
        'software distributed under the License is distributed on an '
        'AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, '
        'either express or implied. See the License for the specific '
        'language governing permissions and limitations under the '
        'License.')

    bsd_3_clause_license = (
        'Licensed under the BSD 3-clause license.\n'
        'Redistribution and use in source and binary forms, with or without '
        'modification, are permitted provided that the following conditions '
        'are met:\n'
        'Redistributions of source code must retain the above copyright '
        'notice, this list of conditions and the following disclaimer.\n'
        'Redistributions in binary form must reproduce the above '
        'copyright notice, this list of conditions and the following '
        'disclaimer in the documentation and/or other materials provided '
        'with the distribution.\n'
        'Neither the name of the copyright holders nor the names of '
        'other contributors may be used to endorse or promote products '
        'derived from this software without specific prior written '
        'permission.\n'
        'THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS '
        'AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT '
        'LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS '
        'FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE '
        'COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, '
        'INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, '
        'BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; '
        'LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER '
        'CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT '
        'LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN '
        'ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE '
        'POSSIBILITY OF SUCH DAMAGE.')

    counterparty_confidential = Schema(
        'This document is not intended for redistribution. '
        'Counterparty confidentiality should be taken '
        'into consideration when handling this document. '
        'Nondisclosure agreements or other similar '
        'contractual obligations may be in force.')

    license_notice = Any(apache_license_v2, bsd_3_clause_license,
                         counterparty_confidential)

    protection_level = All(idclass_tab['protection_level'],
                           Any('k00_public', 'k01_counterparty_confidential'))

    validation_level = All(idclass_tab['validation_level'], Any('v00_minimum'))

    return Schema({
        Required('type'): Any('python_module', 'python_package'),
        Required('validation_level'): validation_level,
        Required('protection'): protection_level,
        Required('copyright'): copyright_notice,
        Required('license'): license_notice,
        Extra: Reject
    })