2727The main entry point is the Licensing object.
2828"""
2929
30-
3130from __future__ import absolute_import
3231from __future__ import unicode_literals
3332from __future__ import print_function
3635try :
3736 # Python 2
3837 unicode
39- str = unicode
38+ str = unicode # NOQA
4039except NameError :
4140 # Python 3
42- unicode = str
41+ unicode = str # NOQA
4342
4443import collections
4544from copy import copy
7170from license_expression ._pyahocorasick import Output
7271from license_expression ._pyahocorasick import Result
7372
74-
7573# append new error codes to PARSE_ERRORS by monkey patching
7674PARSE_EXPRESSION_NOT_UNICODE = 100
7775if PARSE_EXPRESSION_NOT_UNICODE not in PARSE_ERRORS :
@@ -119,6 +117,7 @@ class ExpressionError(Exception):
119117KEYWORDS = tuple (kw .value for kw in _KEYWORDS )
120118KEYWORDS_STRIPPED = tuple (k .strip () for k in KEYWORDS )
121119
120+
122121class Licensing (boolean .BooleanAlgebra ):
123122 """
124123 Define a mini language to parse, validate and compare license expressions.
@@ -157,6 +156,7 @@ class Licensing(boolean.BooleanAlgebra):
157156 >>> assert l.license_symbols(parsed)[1].as_exception
158157
159158 """
159+
160160 def __init__ (self , symbols = tuple (), quiet = True ):
161161 """
162162 Initialize a Licensing with an optional `symbols` sequence of LicenseSymbol
@@ -571,6 +571,7 @@ class Renderable(object):
571571 """
572572 An interface for renderable objects.
573573 """
574+
574575 def render (self , template = '{symbol.key}' , * args , ** kwargs ):
575576 """
576577 Return a formatted string rendering for this expression using the `template`
@@ -598,16 +599,29 @@ def decompose(self):
598599 """
599600 raise NotImplementedError
600601
602+ def __contains__ (self , other ):
603+ """
604+ Test if expr is contained in this symbol.
605+ """
606+ if not isinstance (other , BaseSymbol ):
607+ return False
608+ if self == other :
609+ return True
610+
611+ return any (mine == other for mine in self .decompose ())
612+
601613
602614# validate license keys
603615is_valid_license_key = re .compile (r'^[-\w\s\.\+]+$' , re .UNICODE ).match
604616
617+
605618#FIXME: we need to implement comparison!!!!
606619@total_ordering
607620class LicenseSymbol (BaseSymbol ):
608621 """
609622 A LicenseSymbol represents a license as used in a license expression.
610623 """
624+
611625 def __init__ (self , key , aliases = tuple (), is_exception = False , * args , ** kwargs ):
612626 if not key :
613627 raise ExpressionError (
@@ -708,6 +722,7 @@ class LicenseSymbolLike(LicenseSymbol):
708722 A LicenseSymbolLike object wraps a symbol-like object to expose a LicenseSymbol
709723 behavior.
710724 """
725+
711726 def __init__ (self , symbol_like , * args , ** kwargs ):
712727 if not self .symbol_like (symbol_like ):
713728 raise ExpressionError (
@@ -744,6 +759,7 @@ class LicenseWithExceptionSymbol(BaseSymbol):
744759 license proper and one for the right-hand exception to this license and deals
745760 with the specifics of resolution, validation and representation.
746761 """
762+
747763 def __init__ (self , license_symbol , exception_symbol , strict = False , * args , ** kwargs ):
748764 """
749765 Initialize a new LicenseWithExceptionSymbol from a `license_symbol` and a
@@ -861,6 +877,7 @@ class AND(RenderableFunction, boolean.AND):
861877 """
862878 Custom representation for the AND operator to uppercase.
863879 """
880+
864881 def __init__ (self , * args ):
865882 super (AND , self ).__init__ (* args )
866883 self .operator = ' AND '
@@ -870,6 +887,7 @@ class OR(RenderableFunction, boolean.OR):
870887 """
871888 Custom representation for the OR operator to uppercase.
872889 """
890+
873891 def __init__ (self , * args ):
874892 super (OR , self ).__init__ (* args )
875893 self .operator = ' OR '
0 commit comments