1
+ """Module describing abstractions for validating XML content."""
1
2
import abc
2
3
import subprocess
3
4
17
18
18
19
19
20
class XsdValidator (object ):
21
+ """Class allowing validation of XML files against XSD schema."""
22
+
20
23
__metaclass__ = abc .ABCMeta
21
24
22
25
@abc .abstractmethod
23
26
def validate (self , schema_path , target_path ):
24
- """ Validate ``target_path`` against ``schema_path``.
27
+ """Validate ``target_path`` against ``schema_path``.
25
28
26
29
:return type: ValidationResult
27
30
"""
28
31
29
32
@abc .abstractmethod
30
33
def enabled (self ):
31
- """ Return True iff system has dependencies for this validator.
34
+ """Return True iff system has dependencies for this validator.
32
35
33
36
:return type: bool
34
37
"""
@@ -37,7 +40,7 @@ def enabled(self):
37
40
38
41
39
42
class LxmlValidator (XsdValidator ):
40
- """ Validate XSD files using lxml library. """
43
+ """Validate XSD files using lxml library."""
41
44
42
45
def validate (self , schema_path , target_path ):
43
46
try :
@@ -54,7 +57,7 @@ def enabled(self):
54
57
55
58
56
59
class XmllintValidator (XsdValidator ):
57
- """ Validate XSD files with the external tool xmllint. """
60
+ """Validate XSD files with the external tool xmllint."""
58
61
59
62
def validate (self , schema_path , target_path ):
60
63
command = XMLLINT_COMMAND .format (schema_path , target_path )
@@ -71,6 +74,7 @@ def enabled(self):
71
74
72
75
73
76
def get_validator (require = True ):
77
+ """Return a :class:`XsdValidator` object based on available dependencies."""
74
78
for validator in VALIDATORS :
75
79
if validator .enabled ():
76
80
return validator
@@ -79,3 +83,9 @@ def get_validator(require=True):
79
83
raise Exception (INSTALL_VALIDATOR_MESSAGE )
80
84
81
85
return None
86
+
87
+
88
+ __all__ = [
89
+ "get_validator" ,
90
+ "XsdValidator" ,
91
+ ]
0 commit comments