1+ """Module describing abstractions for validating XML content."""
12import abc
23import subprocess
34
1718
1819
1920class XsdValidator (object ):
21+ """Class allowing validation of XML files against XSD schema."""
22+
2023 __metaclass__ = abc .ABCMeta
2124
2225 @abc .abstractmethod
2326 def validate (self , schema_path , target_path ):
24- """ Validate ``target_path`` against ``schema_path``.
27+ """Validate ``target_path`` against ``schema_path``.
2528
2629 :return type: ValidationResult
2730 """
2831
2932 @abc .abstractmethod
3033 def enabled (self ):
31- """ Return True iff system has dependencies for this validator.
34+ """Return True iff system has dependencies for this validator.
3235
3336 :return type: bool
3437 """
@@ -37,7 +40,7 @@ def enabled(self):
3740
3841
3942class LxmlValidator (XsdValidator ):
40- """ Validate XSD files using lxml library. """
43+ """Validate XSD files using lxml library."""
4144
4245 def validate (self , schema_path , target_path ):
4346 try :
@@ -54,7 +57,7 @@ def enabled(self):
5457
5558
5659class XmllintValidator (XsdValidator ):
57- """ Validate XSD files with the external tool xmllint. """
60+ """Validate XSD files with the external tool xmllint."""
5861
5962 def validate (self , schema_path , target_path ):
6063 command = XMLLINT_COMMAND .format (schema_path , target_path )
@@ -71,6 +74,7 @@ def enabled(self):
7174
7275
7376def get_validator (require = True ):
77+ """Return a :class:`XsdValidator` object based on available dependencies."""
7478 for validator in VALIDATORS :
7579 if validator .enabled ():
7680 return validator
@@ -79,3 +83,9 @@ def get_validator(require=True):
7983 raise Exception (INSTALL_VALIDATOR_MESSAGE )
8084
8185 return None
86+
87+
88+ __all__ = [
89+ "get_validator" ,
90+ "XsdValidator" ,
91+ ]
0 commit comments