@@ -726,3 +726,64 @@ def GetMACAddress():
726726 import uuid
727727
728728 return ':' .join (['{:02x}' .format ((uuid .getnode () >> ele ) & 0xff ) for ele in range (0 ,8 * 6 ,8 )][::- 1 ])
729+
730+ def HasFeature (license_key , feature_name ):
731+
732+ """
733+ Uses a special data object associated with the license key to determine if a certain feature exists (instead of the 8 feature flags).
734+ <strong>Formatting: </strong> The name of the data object should be 'cryptolens_features' and it should be structured as a JSON array.
735+
736+ For example, <pre>["f1", "f2"]</pre><p>means f1 and f2 are true. You can also have feature bundling, eg. <pre>["f1", ["f2",["voice","image"]]]</pre>
737+ which means that f1 and f2 are true, as well as f2.voice and f2.image. You can set any depth, eg. you can have
738+ <pre>["f1", ["f2",[["voice",["all"]], "image"]]]</pre> means f2.voice.all is true as well as f2.voice and f2.
739+ The dots symbol is used to specify the "sub-features".
740+
741+ Read more here: https://help.cryptolens.io/web-interface/feature-templates
742+
743+ Parameters:
744+ @license_key The license key object.
745+ @feature_name For example, "f2.voice.all".
746+
747+ """
748+
749+ if license_key .data_objects == None :
750+ return False
751+
752+ features = None
753+
754+ for dobj in license_key .data_objects :
755+
756+ if dobj ["Name" ] == 'cryptolens_features' :
757+ features = dobj ["StringValue" ]
758+ break
759+
760+ array = json .loads (features )
761+
762+ feature_path = feature_name .split ("." )
763+
764+ found = False
765+
766+ for i in range (len (feature_path )):
767+
768+ found = False
769+ index = - 1
770+
771+ for j in range (len (array )):
772+
773+ if not (isinstance (array [j ], list )) and array [j ] == feature_path [i ]:
774+ found = True
775+ break
776+ elif isinstance (array [j ], list ) and array [j ][0 ] == feature_path [i ]:
777+ found = True
778+ index = j
779+
780+ if not (found ):
781+ return False
782+
783+ if i + 1 < len (feature_path ) and index != - 1 :
784+ array = array [index ][1 ]
785+
786+ if not (found ):
787+ return False
788+
789+ return True
0 commit comments