Skip to content
Snippets Groups Projects
Commit bb329cd0 authored by Juliana Oliveira Rodrigues's avatar Juliana Oliveira Rodrigues
Browse files

comparators.xml: refactored to use File.recognizes logic


Removes duplicated code from XMLFile comparator by using File.recognizes.

Signed-off-by: default avatarJuliana Oliveira Rodrigues <juliana.orod@gmail.com>
parent d97a81a1
No related branches found
No related tags found
No related merge requests found
...@@ -17,8 +17,6 @@ ...@@ -17,8 +17,6 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>. # along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import re
from xml.dom import minidom from xml.dom import minidom
from xml.parsers.expat import ExpatError from xml.parsers.expat import ExpatError
...@@ -68,12 +66,12 @@ class XMLFile(File): ...@@ -68,12 +66,12 @@ class XMLFile(File):
XML Files Comparison class XML Files Comparison class
Attributes: Attributes:
RE_FILE_EXTENSION (SRE_Pattern): xml file extension pattern FILE_EXTENSION_SUFFIX (str): xml file extension suffix
""" """
RE_FILE_EXTENSION = re.compile(r'\.xml$') FILE_EXTENSION_SUFFIX = '.xml'
@staticmethod @classmethod
def recognizes(file): def recognizes(cls, file):
""" """
Identifies if a given file has XML extension Identifies if a given file has XML extension
...@@ -83,8 +81,8 @@ class XMLFile(File): ...@@ -83,8 +81,8 @@ class XMLFile(File):
Returns: Returns:
False if file is not a XML File, True otherwise False if file is not a XML File, True otherwise
""" """
if XMLFile.RE_FILE_EXTENSION.search(file.name) is None: if not super().recognizes(file):
return False return False
with open(file.path) as f: with open(file.path) as f:
try: try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment