How to use the jsonmodels.utilities.convert_ecma_regex_to_python function in jsonmodels

To help you get started, we’ve selected a few jsonmodels examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jazzband / jsonmodels / tests / test_utilities.py View on Github external
def test_convert_ecma_regex_to_python():
    assert ('some', []) == utilities.convert_ecma_regex_to_python('/some/')
    assert (
        ('some/pattern', []) ==
        utilities.convert_ecma_regex_to_python('/some/pattern/')
    )
    assert (
        ('^some \d+ pattern$', []) ==
        utilities.convert_ecma_regex_to_python('/^some \d+ pattern$/')
    )

    regex, flags = utilities.convert_ecma_regex_to_python('/^regex \d/i')
    assert '^regex \d' == regex
    assert set([re.I]) == set(flags)

    result = utilities.convert_ecma_regex_to_python('/^regex \d/m')
    assert '^regex \d' == result.regex
    assert set([re.M]) == set(result.flags)
github jazzband / jsonmodels / tests / test_utilities.py View on Github external
utilities.convert_ecma_regex_to_python('/some/pattern/')
    )
    assert (
        ('^some \d+ pattern$', []) ==
        utilities.convert_ecma_regex_to_python('/^some \d+ pattern$/')
    )

    regex, flags = utilities.convert_ecma_regex_to_python('/^regex \d/i')
    assert '^regex \d' == regex
    assert set([re.I]) == set(flags)

    result = utilities.convert_ecma_regex_to_python('/^regex \d/m')
    assert '^regex \d' == result.regex
    assert set([re.M]) == set(result.flags)

    result = utilities.convert_ecma_regex_to_python('/^regex \d/mi')
    assert '^regex \d' == result.regex
    assert set([re.M, re.I]) == set(result.flags)

    with pytest.raises(ValueError):
        utilities.convert_ecma_regex_to_python('/regex/wrong')

    assert (
        ('python regex', []) ==
        utilities.convert_ecma_regex_to_python('python regex')
    )

    assert (
        ('^another \d python regex$', []) ==
        utilities.convert_ecma_regex_to_python('^another \d python regex$')
    )
github jazzband / jsonmodels / tests / test_utilities.py View on Github external
)

    regex, flags = utilities.convert_ecma_regex_to_python('/^regex \d/i')
    assert '^regex \d' == regex
    assert set([re.I]) == set(flags)

    result = utilities.convert_ecma_regex_to_python('/^regex \d/m')
    assert '^regex \d' == result.regex
    assert set([re.M]) == set(result.flags)

    result = utilities.convert_ecma_regex_to_python('/^regex \d/mi')
    assert '^regex \d' == result.regex
    assert set([re.M, re.I]) == set(result.flags)

    with pytest.raises(ValueError):
        utilities.convert_ecma_regex_to_python('/regex/wrong')

    assert (
        ('python regex', []) ==
        utilities.convert_ecma_regex_to_python('python regex')
    )

    assert (
        ('^another \d python regex$', []) ==
        utilities.convert_ecma_regex_to_python('^another \d python regex$')
    )

    result = utilities.convert_ecma_regex_to_python('python regex')
    assert 'python regex' == result.regex
    assert [] == result.flags
github jazzband / jsonmodels / tests / test_utilities.py View on Github external
assert set([re.I]) == set(flags)

    result = utilities.convert_ecma_regex_to_python('/^regex \d/m')
    assert '^regex \d' == result.regex
    assert set([re.M]) == set(result.flags)

    result = utilities.convert_ecma_regex_to_python('/^regex \d/mi')
    assert '^regex \d' == result.regex
    assert set([re.M, re.I]) == set(result.flags)

    with pytest.raises(ValueError):
        utilities.convert_ecma_regex_to_python('/regex/wrong')

    assert (
        ('python regex', []) ==
        utilities.convert_ecma_regex_to_python('python regex')
    )

    assert (
        ('^another \d python regex$', []) ==
        utilities.convert_ecma_regex_to_python('^another \d python regex$')
    )

    result = utilities.convert_ecma_regex_to_python('python regex')
    assert 'python regex' == result.regex
    assert [] == result.flags
github jazzband / jsonmodels / tests / test_utilities.py View on Github external
def test_converters():
    assert (
        '/^ecma \d regex$/im' ==
        utilities.convert_python_regex_to_ecma(
            *utilities.convert_ecma_regex_to_python('/^ecma \d regex$/im'))
    )

    result = utilities.convert_ecma_regex_to_python(
        utilities.convert_python_regex_to_ecma(
            '^some \w python regex$', [re.I]))

    assert '^some \w python regex$' == result.regex
    assert [re.I] == result.flags
github jazzband / jsonmodels / tests / test_utilities.py View on Github external
def test_converters():
    assert (
        '/^ecma \d regex$/im' ==
        utilities.convert_python_regex_to_ecma(
            *utilities.convert_ecma_regex_to_python('/^ecma \d regex$/im'))
    )

    result = utilities.convert_ecma_regex_to_python(
        utilities.convert_python_regex_to_ecma(
            '^some \w python regex$', [re.I]))

    assert '^some \w python regex$' == result.regex
    assert [re.I] == result.flags
github jazzband / jsonmodels / tests / test_utilities.py View on Github external
result = utilities.convert_ecma_regex_to_python('/^regex \d/mi')
    assert '^regex \d' == result.regex
    assert set([re.M, re.I]) == set(result.flags)

    with pytest.raises(ValueError):
        utilities.convert_ecma_regex_to_python('/regex/wrong')

    assert (
        ('python regex', []) ==
        utilities.convert_ecma_regex_to_python('python regex')
    )

    assert (
        ('^another \d python regex$', []) ==
        utilities.convert_ecma_regex_to_python('^another \d python regex$')
    )

    result = utilities.convert_ecma_regex_to_python('python regex')
    assert 'python regex' == result.regex
    assert [] == result.flags
github jazzband / jsonmodels / tests / test_utilities.py View on Github external
def test_convert_ecma_regex_to_python():
    assert ('some', []) == utilities.convert_ecma_regex_to_python('/some/')
    assert (
        ('some/pattern', []) ==
        utilities.convert_ecma_regex_to_python('/some/pattern/')
    )
    assert (
        ('^some \d+ pattern$', []) ==
        utilities.convert_ecma_regex_to_python('/^some \d+ pattern$/')
    )

    regex, flags = utilities.convert_ecma_regex_to_python('/^regex \d/i')
    assert '^regex \d' == regex
    assert set([re.I]) == set(flags)

    result = utilities.convert_ecma_regex_to_python('/^regex \d/m')
    assert '^regex \d' == result.regex
    assert set([re.M]) == set(result.flags)

    result = utilities.convert_ecma_regex_to_python('/^regex \d/mi')
    assert '^regex \d' == result.regex
    assert set([re.M, re.I]) == set(result.flags)

    with pytest.raises(ValueError):
        utilities.convert_ecma_regex_to_python('/regex/wrong')

    assert (
        ('python regex', []) ==
github jazzband / jsonmodels / tests / test_utilities.py View on Github external
def test_convert_ecma_regex_to_python():
    assert ('some', []) == utilities.convert_ecma_regex_to_python('/some/')
    assert (
        ('some/pattern', []) ==
        utilities.convert_ecma_regex_to_python('/some/pattern/')
    )
    assert (
        ('^some \d+ pattern$', []) ==
        utilities.convert_ecma_regex_to_python('/^some \d+ pattern$/')
    )

    regex, flags = utilities.convert_ecma_regex_to_python('/^regex \d/i')
    assert '^regex \d' == regex
    assert set([re.I]) == set(flags)

    result = utilities.convert_ecma_regex_to_python('/^regex \d/m')
    assert '^regex \d' == result.regex
    assert set([re.M]) == set(result.flags)

    result = utilities.convert_ecma_regex_to_python('/^regex \d/mi')
    assert '^regex \d' == result.regex
github jazzband / jsonmodels / jsonmodels / validators.py View on Github external
"""Init.

        Note, that if given pattern is ECMA regex, given flags will be
        **completely ignored** and taken from given regex.


        :param string pattern: Pattern of regex.
        :param bool flags: Flags used for the regex matching.
            Allowed flag names are in the `FLAGS` attribute. The flag value
            does not matter as long as it evaluates to True.
            Flags with False values will be ignored.
            Invalid flags will be ignored.

        """
        if utilities.is_ecma_regex(pattern):
            result = utilities.convert_ecma_regex_to_python(pattern)
            self.pattern, self.flags = result
        else:
            self.pattern = pattern
            self.flags = [self.FLAGS[key] for key, value in flags.items()
                          if key in self.FLAGS and value]