예제 #1
0
파일: parsers_in.py 프로젝트: sys-git/hoft
def parse_keyword_inputs(parse_kwargs, kwargs, argspec, errors, on_error,
                         fail_fast):
    # Parse the keyword inputs we name:
    for name, custom_parser_func in parse_kwargs.items():
        # Only (validate) if the func is provided:
        if custom_parser_func is not IGNORE:
            value = kwargs.get(name)
            try:
                custom_parser_func(
                    value=value,
                    name=name,
                    present=name in kwargs,
                )
            except Exception as exc:
                func_name = get_func_name(custom_parser_func)
                default_value = get_default_value(name, argspec)
                errors.append(
                    KeywordError(
                        exc,
                        name,
                        value,
                        default_value,
                        func_name,
                        custom_parser_func,
                    ))
                conditionally_raise_exc(
                    exc=exc,
                    on_error=on_error,
                    errors=errors,
                    fail_fast=fail_fast,
                )
예제 #2
0
파일: parsers_in.py 프로젝트: sys-git/hoft
def parse_positional_inputs(parse_args, args, argspec, errors, on_error,
                            fail_fast):
    # Parse the positional inputs:
    for index, (custom_parser_func, value) in enumerate(zip(parse_args, args)):
        # Only (validate) if the func is provided:
        if custom_parser_func is not IGNORE:
            try:
                custom_parser_func(
                    value=value,
                    index=index,
                )
            except Exception as exc:
                func_name = get_func_name(custom_parser_func)
                name = argspec.args[index]
                errors.append(
                    PositionalError(
                        exc,
                        name,
                        index,
                        value,
                        func_name,
                        custom_parser_func,
                    ))
                conditionally_raise_exc(
                    exc=exc,
                    on_error=on_error,
                    errors=errors,
                    fail_fast=fail_fast,
                )
예제 #3
0
파일: parsers_sig.py 프로젝트: sys-git/hoft
def parse_sig_remaining_inputs(
    default,
    argspec,
    callargs,
    kwargs,
    errors,
    handled,
    on_error,
    fail_fast,
):
    sig = get_signature(argspec)

    for name, value in sorted(callargs.items()):
        if name in handled:
            continue
        handled.update([name])

        # Only (validate) if the func is provided:
        if default is not IGNORE:
            try:
                default(name, value, argspec)
            except Exception as exc:
                func_name = get_func_name(default)
                default_value = callargs[name]
                try:
                    index = sig.args.index(name)
                except ValueError:
                    errors.append(
                        KeywordError(
                            exc,
                            name,
                            value,
                            default_value,
                            func_name,
                            default,
                        ))
                else:
                    errors.append(
                        PositionalError(
                            exc,
                            name,
                            index,
                            value,
                            func_name,
                            default,
                        ))

                conditionally_raise_exc(
                    exc=exc,
                    on_error=on_error,
                    errors=errors,
                    fail_fast=fail_fast,
                )
예제 #4
0
파일: test_utils.py 프로젝트: sys-git/hoft
    def test_decorated_func(self):
        def d(func):
            @functools.wraps(func)
            def _inner():
                pass

            return _inner

        @d
        def my_func():
            pass

        self.assertEqual(get_func_name(my_func), 'my_func')
예제 #5
0
파일: parsers_sig.py 프로젝트: sys-git/hoft
def parse_sig_keyword_inputs(
    parse_kwargs,
    kwargs,
    argspec,
    callargs,
    errors,
    handled,
    on_error,
    fail_fast,
):
    for name, custom_parser_func in sorted(parse_kwargs.items()):
        if name in handled:
            continue
        handled.update([name])

        # Only (validate) if the func is provided:
        if custom_parser_func is not IGNORE:
            called_with_value = kwargs.get(name, NOVALUE)
            default_value = get_default_value(name, argspec)
            index = argspec.args.index(name)

            try:
                custom_parser_func(
                    name,
                    index,
                    called_with_value,
                    default_value=default_value,
                )
            except Exception as exc:
                func_name = get_func_name(custom_parser_func)
                errors.append(
                    KeywordError(
                        exc,
                        name,
                        called_with_value,
                        default_value,
                        func_name,
                        custom_parser_func,
                    ))
                conditionally_raise_exc(
                    exc=exc,
                    on_error=on_error,
                    errors=errors,
                    fail_fast=fail_fast,
                )
예제 #6
0
파일: parsers_sig.py 프로젝트: sys-git/hoft
def parse_sig_positional_inputs(
    parse_args,
    args,
    argspec,
    errors,
    handled,
    on_error,
    fail_fast,
):
    # Parse the positional inputs:
    for index, (custom_parser_func, value) in enumerate(zip(parse_args, args)):
        # Only (validate) if the func is provided:
        if custom_parser_func is not IGNORE:
            name = argspec.args[index]

            # Have we already handled this argument?
            if name in handled:
                continue

            handled.update([name])

            try:
                custom_parser_func(
                    name,
                    index,
                    value,
                )
            except Exception as exc:
                func_name = get_func_name(custom_parser_func)
                errors.append(
                    PositionalError(
                        exc,
                        name,
                        index,
                        value,
                        func_name,
                        custom_parser_func,
                    ))
                conditionally_raise_exc(
                    exc=exc,
                    on_error=on_error,
                    errors=errors,
                    fail_fast=fail_fast,
                )
예제 #7
0
파일: test_utils.py 프로젝트: sys-git/hoft
    def test_multiply_decorated_func(self):
        def d(func1):
            @functools.wraps(func1)
            def _inner1():
                pass

            return _inner1

        def e(func2):
            @functools.wraps(func2)
            def _inner2():
                pass

            return _inner2

        @d
        @e
        def my_func():
            pass

        self.assertEqual(get_func_name(my_func), 'my_func')
예제 #8
0
파일: test_utils.py 프로젝트: sys-git/hoft
    def test_get_func_name_simple(self):
        def my_func():
            pass

        self.assertEqual(get_func_name(my_func), 'my_func')