Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ The following organizations or individuals have contributed to this code:
- nexB Inc. @nexB
- Philippe Ombredanne @pombredanne
- Thomas Druez @tdruez
- Carmen Bianca Bakker @carmenbianca
14 changes: 10 additions & 4 deletions src/license_expression/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ class ExpressionError(Exception):
pass


class ExpressionParseError(ParseError, ExpressionError):
pass


# Used for tokenizing
Keyword = namedtuple('Keyword', 'value type')
Keyword.__len__ = lambda self: len(self.value)
Expand Down Expand Up @@ -380,7 +384,7 @@ def parse(self, expression, validate=False, strict=False, simple=False, **kwargs
"""
Return a new license LicenseExpression object by parsing a license
`expression` string. Check that the expression syntax is valid and raise
an Exception, an ExpressionError or a ParseError on errors.
an ExpressionError or an ExpressionParseError on errors.
Return None for empty expressions.
`expression` is either a string or a LicenseExpression object. If this
is a LicenseExpression it is returned as-is.
Expand Down Expand Up @@ -433,9 +437,11 @@ def parse(self, expression, validate=False, strict=False, simple=False, **kwargs
# this will raise a ParseError on errors
tokens = list(self.tokenize(expression, strict=strict, simple=simple))
expression = super(Licensing, self).parse(tokens)
except TypeError as e:
msg = 'Invalid expression syntax: ' + repr(e)
raise ExpressionError(msg)
except ParseError as e:
new_error = ExpressionParseError(
token_type=e.token_type, token_string=e.token_string,
position=e.position, error_code=e.error_code)
raise new_error

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