src/license_expression/__init__.py
def parse(
            self,
            expression,
            validate=False,
            strict=False,
            simple=False,
            **kwargs
        ):
        """
        Return a new license LicenseExpression object by parsing a license
        ``expression``. Check that the ``expression`` syntax is valid and
        raise an ExpressionError or an ExpressionParseError on errors.

        Return None for empty expressions. ``expression`` is either a string or
        a LicenseExpression object. If ``expression`` is a LicenseExpression it
        is returned as-is.

        Symbols are always recognized from known Licensing symbols if `symbols`
        were provided at Licensing creation time: each license and exception is
        recognized from known license keys (and from aliases for a symbol if
        available).

        If ``validate`` is True and a license is unknown, an ExpressionError
        error is raised with a message listing the unknown license keys.

        If ``validate`` is False, no error is raised if the ``expression``
        syntax is correct. You can call further call the
        `unknown_license_keys()` or `unknown_license_symbols()` methods to get
        unknown license keys or symbols found in the parsed LicenseExpression.

        If ``strict`` is True, an ExpressionError will be raised if in a
        "WITH" expression such as "XXX with ZZZ" if the XXX symbol has
        `is_exception` set to True or the YYY symbol has `is_exception` set to
        False. This checks that symbols are used strictly as intended in a
        "WITH" subexpression using a license on the left and an exception on thr
        right.

        If ``simple`` is True, parsing will use a simple tokenizer that assumes
        that license symbols are all license keys and do not contain spaces.

        For example:
        >>> expression = 'EPL-1.0 and Apache-1.1 OR GPL-2.0 with Classpath-exception'
        >>> parsed = Licensing().parse(expression)
        >>> expected = '(EPL-1.0 AND Apache-1.1) OR GPL-2.0 WITH Classpath-exception'
        >>> assert expected == parsed.render(template='{symbol.key}')
        """
        if expression is None:
            return

        if isinstance(expression, LicenseExpression):
            return expression

        if isinstance(expression, bytes):
            try:
                expression = str(expression)
            except:
                ext = type(expression)
                raise ExpressionError(
                    f'expression must be a string and not: {ext!r}'
                )

        if not isinstance(expression, str):
            ext = type(expression)
            raise ExpressionError(
                f'expression must be a string and not: {ext!r}'
            )

        if not expression or not expression.strip():
            return
        try:
            # this will raise a ParseError on errors
            tokens = list(self.tokenize(
                expression=expression,
                strict=strict,
                simple=simple,
            ))
            expression = super(Licensing, self).parse(tokens)

        except ParseError as e:
            raise ExpressionParseError(
                token_type=e.token_type,
                token_string=e.token_string,
                position=e.position,
                error_code=e.error_code,
            ) from e

        if not isinstance(expression, LicenseExpression):
            raise ExpressionError(
                'expression must be a LicenseExpression once parsed.')

        if validate:
            self.validate_license_keys(expression)

        return expression

        Return a new license LicenseExpression object by parsing a license
        ``expression``. Check that the ``expression`` syntax is valid and
        raise an ExpressionError or an ExpressionParseError on errors.

        Return None for empty expressions. ``expression`` is either a string or
        a LicenseExpression object. If ``expression`` is a LicenseExpression it
        is returned as-is.

        Symbols are always recognized from known Licensing symbols if `symbols`
        were provided at Licensing creation time: each license and exception is
        recognized from known license keys (and from aliases for a symbol if
        available).

        If ``validate`` is True and a license is unknown, an ExpressionError
        error is raised with a message listing the unknown license keys.

        If ``validate`` is False, no error is raised if the ``expression``
        syntax is correct. You can call further call the
        `unknown_license_keys()` or `unknown_license_symbols()` methods to get
        unknown license keys or symbols found in the parsed LicenseExpression.

        If ``strict`` is True, an ExpressionError will be raised if in a
        "WITH" expression such as "XXX with ZZZ" if the XXX symbol has
        `is_exception` set to True or the YYY symbol has `is_exception` set to
        False. This checks that symbols are used strictly as intended in a
        "WITH" subexpression using a license on the left and an exception on thr
        right.

        If ``simple`` is True, parsing will use a simple tokenizer that assumes
        that license symbols are all license keys and do not contain spaces.

        For example:
        >>> expression = 'EPL-1.0 and Apache-1.1 OR GPL-2.0 with Classpath-exception'
        >>> parsed = Licensing().parse(expression)
        >>> expected = '(EPL-1.0 AND Apache-1.1) OR GPL-2.0 WITH Classpath-exception'
        >>> assert expected == parsed.render(template='{symbol.key}')
        
Return a new license LicenseExpression object by parsing a license
``expression``. Check that the ``expression`` syntax is valid and
raise an ExpressionError or an ExpressionParseError on errors.

Return None for empty expressions. ``expression`` is either a string or
a LicenseExpression object. If ``expression`` is a LicenseExpression it
is returned as-is.

Symbols are always recognized from known Licensing symbols if `symbols`
were provided at Licensing creation time: each license and exception is
recognized from known license keys (and from aliases for a symbol if
available).

If ``validate`` is True and a license is unknown, an ExpressionError
error is raised with a message listing the unknown license keys.





If ``simple`` is True, parsing will use a simple tokenizer that assumes
that license symbols are all license keys and do not contain spaces.


Return a new license LicenseExpression object by parsing a license ` ` expression ` ` . Check that the ` ` expression ` ` syntax is valid and raise an ExpressionError or an ExpressionParseError on errors . Return None for empty expressions . ` ` expression ` ` is either a string or a LicenseExpression object . If ` ` expression ` ` is a LicenseExpression it is returned as - is . Symbols are always recognized from known Licensing symbols if ` symbols ` were provided at Licensing creation time : each license and exception is recognized from known license keys ( and from aliases for a symbol if available ) . If ` ` validate ` ` is True and a license is unknown an ExpressionError error is raised with a message listing the unknown license keys . If ` ` simple ` ` is True parsing will use a simple tokenizer that assumes that license symbols are all license keys and do not contain spaces .
def parse(
            self,
            expression,
            validate=False,
            strict=False,
            simple=False,
            **kwargs
        ):
        if expression is None:
            return
        if isinstance(expression, LicenseExpression):
            return expression
        if isinstance(expression, bytes):
            try:
                expression = str(expression)
            except:
                ext = type(expression)
                raise ExpressionError(
                    f'expression must be a string and not: {ext!r}'
                )
        if not isinstance(expression, str):
            ext = type(expression)
            raise ExpressionError(
                f'expression must be a string and not: {ext!r}'
            )
        if not expression or not expression.strip():
            return
        try:
            tokens = list(self.tokenize(
                expression=expression,
                strict=strict,
                simple=simple,
            ))
            expression = super(Licensing, self).parse(tokens)
        except ParseError as e:
            raise ExpressionParseError(
                token_type=e.token_type,
                token_string=e.token_string,
                position=e.position,
                error_code=e.error_code,
            ) from e
        if not isinstance(expression, LicenseExpression):
            raise ExpressionError(
                'expression must be a LicenseExpression once parsed.')
        if validate:
            self.validate_license_keys(expression)
        return expression
def parse ( self , expression , validate = False , strict = False , simple = False , ** kwargs ) : if expression is None : return if isinstance ( expression , LicenseExpression ) : return expression if isinstance ( expression , bytes ) : try : expression = str ( expression ) except : ext = type ( expression ) raise ExpressionError ( f'expression must be a string and not: {ext!r}' ) if not isinstance ( expression , str ) : ext = type ( expression ) raise ExpressionError ( f'expression must be a string and not: {ext!r}' ) if not expression or not expression . strip ( ) : return try : tokens = list ( self . tokenize ( expression = expression , strict = strict , simple = simple , ) ) expression = super ( Licensing , self ) . parse ( tokens ) except ParseError as e : raise ExpressionParseError ( token_type = e . token_type , token_string = e . token_string , position = e . position , error_code = e . error_code , ) from e if not isinstance ( expression , LicenseExpression ) : raise ExpressionError ( 'expression must be a LicenseExpression once parsed.' ) if validate : self . validate_license_keys ( expression ) return expression
Return a new license LicenseExpression object by parsing a license
``expression``.
Return a new license LicenseExpression object by parsing a license ` ` expression ` ` .
"""
        Return a new license LicenseExpression object by parsing a license
        ``expression``. Check that the ``expression`` syntax is valid and
        raise an ExpressionError or an ExpressionParseError on errors.

        Return None for empty expressions. ``expression`` is either a string or
        a LicenseExpression object. If ``expression`` is a LicenseExpression it
        is returned as-is.

        Symbols are always recognized from known Licensing symbols if `symbols`
        were provided at Licensing creation time: each license and exception is
        recognized from known license keys (and from aliases for a symbol if
        available).

        If ``validate`` is True and a license is unknown, an ExpressionError
        error is raised with a message listing the unknown license keys.

        If ``validate`` is False, no error is raised if the ``expression``
        syntax is correct. You can call further call the
        `unknown_license_keys()` or `unknown_license_symbols()` methods to get
        unknown license keys or symbols found in the parsed LicenseExpression.

        If ``strict`` is True, an ExpressionError will be raised if in a
        "WITH" expression such as "XXX with ZZZ" if the XXX symbol has
        `is_exception` set to True or the YYY symbol has `is_exception` set to
        False. This checks that symbols are used strictly as intended in a
        "WITH" subexpression using a license on the left and an exception on thr
        right.

        If ``simple`` is True, parsing will use a simple tokenizer that assumes
        that license symbols are all license keys and do not contain spaces.

        For example:
        >>> expression = 'EPL-1.0 and Apache-1.1 OR GPL-2.0 with Classpath-exception'
        >>> parsed = Licensing().parse(expression)
        >>> expected = '(EPL-1.0 AND Apache-1.1) OR GPL-2.0 WITH Classpath-exception'
        >>> assert expected == parsed.render(template='{symbol.key}')
        """ # this will raise a ParseError on errors
self
expression
validate
strict
simple