@@ -120,6 +120,39 @@ class ExpressionParseError(ParseError, ExpressionError):
120120).finditer
121121
122122
123+ class ExpressionInfo :
124+ """
125+ The ExpressionInfo class is returned by Licensing.validate() where it stores
126+ information about a given license expression passed into
127+ Licensing.validate().
128+
129+ The ExpressionInfo class has the following fields:
130+ - normalized_license_expression: str.
131+ - If a valid license expression has been passed into `validate()`,
132+ then the license expression string will be set in this field.
133+ - errors: list
134+ - If there were errors validating a license expression,
135+ the error messages will be appended here.
136+ - valid_symbols: list
137+ - If a valid license expression has been passed into `validate()`,
138+ then the license symbols from the license expression will be
139+ appended here.
140+ - invalid_symbols: list
141+ - If an invalid license expression has been passed into `validate()`,
142+ then the invalid license symbols from the license expression will be
143+ appended here.
144+ - exception_symbols: list
145+ - If a license symbol in the license expression is a license exception,
146+ then that license symbol will be appended here.
147+ """
148+ def __init__ (self ):
149+ self .normalized_license_expression = ''
150+ self .errors = []
151+ self .valid_symbols = []
152+ self .invalid_symbols = []
153+ self .exception_symbols = []
154+
155+
123156class Licensing (boolean .BooleanAlgebra ):
124157 """
125158 Licensing defines a mini language to parse, validate and compare license
@@ -626,13 +659,6 @@ def validate(self, expression, strict=True, **kwargs):
626659 Return a ExpressionInfo object that contains information about
627660 `expression` by parsing `expression` using Licensing.parse()
628661
629- The ExpressionInfo class has the following fields:
630- - normalized_license_expression: str
631- - errors: list
632- - valid_symbols: list
633- - invalid_symbols: list
634- - exception_symbols: list
635-
636662 If `expression` is valid, then
637663 `ExpressionInfo.normalized_license_expression` is set, along with a list
638664 of valid license symbols in `valid_symbols` and `exception_symbols`.
@@ -648,47 +674,40 @@ def validate(self, expression, strict=True, **kwargs):
648674 set to True or the YYY symbol has `is_exception` set to False. This
649675 checks that symbols are used strictly as constructed.
650676 """
651- class ExpressionInfo :
652- normalized_license_expression = ''
653- errors = []
654- valid_symbols = []
655- invalid_symbols = []
656- exception_symbols = []
657-
658- data = ExpressionInfo ()
677+ expression_info = ExpressionInfo ()
659678
660679 # Check `expression` type
661680 try :
662681 self .parse (expression )
663682 except ExpressionError as e :
664- data .errors .append (str (e ))
665- return data
683+ expression_info .errors .append (str (e ))
684+ return expression_info
666685
667686 # Check `expression` syntax
668687 try :
669688 self .parse (expression , strict = strict )
670689 except ExpressionParseError as e :
671- data .errors .append (str (e ))
672- data .invalid_symbols .append (e .token_string )
673- return data
690+ expression_info .errors .append (str (e ))
691+ expression_info .invalid_symbols .append (e .token_string )
692+ return expression_info
674693
675694 # Check `expression` keys
676695 try :
677696 parsed_expression = self .parse (expression , strict = strict , validate = True )
678697 except ExpressionError as e :
679698 error_message = str (e )
680- data .errors .append (error_message )
699+ expression_info .errors .append (error_message )
681700 if 'Unknown license key' in error_message :
682701 unknown_keys = self .unknown_license_keys (expression )
683- data .invalid_symbols .extend (unknown_keys )
684- return data
702+ expression_info .invalid_symbols .extend (unknown_keys )
703+ return expression_info
685704
686- # If we have not hit an exception, load `data ` and return it
705+ # If we have not hit an exception, load `expression_info ` and return it
687706 symbols = list (parsed_expression .symbols )
688- data .normalized_license_expression = parsed_expression .render ()
689- data .valid_symbols = [s .render () for s in symbols ]
690- data .exception_symbols = [s .render () for s in symbols if isinstance (s , LicenseWithExceptionSymbol ) or s .is_exception ]
691- return data
707+ expression_info .normalized_license_expression = parsed_expression .render ()
708+ expression_info .valid_symbols = [s .render () for s in symbols ]
709+ expression_info .exception_symbols = [s .render () for s in symbols if isinstance (s , LicenseWithExceptionSymbol ) or s .is_exception ]
710+ return expression_info
692711
693712
694713def get_license_key_info (license_key_index_location = None ):
0 commit comments