add regex pattern validation

This commit is contained in:
ArturTomczak
2021-06-21 15:23:03 +02:00
parent f27fbecc9a
commit 99f0e6c93e
+8 -3
View File
@@ -1,8 +1,10 @@
import operator import operator
import ifcopenshell.util.element import ifcopenshell.util.element
import re
from xmlschema import XMLSchema from xmlschema import XMLSchema
from xmlschema.validators import facets, identities
class exception(Exception): class exception(Exception):
pass pass
@@ -128,7 +130,7 @@ class classification(facet):
class property(facet): class property(facet):
""" """
The IDS property facet implenented using `ifcopenshell.util.element` The IDS property facet implemented using `ifcopenshell.util.element`
""" """
parameters = ["name", "propertyset", "value"] parameters = ["name", "propertyset", "value"]
@@ -308,8 +310,11 @@ class restriction:
if eval(str(len(other))+op): #TODO eval not safe? if eval(str(len(other))+op): #TODO eval not safe?
result = True result = True
elif self.type == "pattern": elif self.type == "pattern":
#TODO verify XML pattern self.options
pass translated_pattern = identities.translate_pattern(r'[A-Z]{1,3}') # Between one and three capital letters
regex_pattern = re.compile(translated_pattern)
if regex_pattern.fullmatch(other) is not None:
result = True
#TODO add fractionDigits #TODO add fractionDigits
#TODO add totalDigits #TODO add totalDigits
#TODO add whiteSpace #TODO add whiteSpace