<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2005 onwards University of Deusto
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution.
#
# This software consists of contributions made by many individuals,
# listed below:
#
# Author: <NAME> <<EMAIL>>
#

import os
import sys
from StringIO import StringIO

try:
    from lxml import etree
except ImportError:
    LXML_AVAILABLE = False
    MESSAGE_SHOWN  = False
else:
    LXML_AVAILABLE = True

from weblab.util import data_filename
import voodoo.log as log
import voodoo.gen.exceptions.loader.LoaderErrors as LoaderErrors

module_directory = os.path.join(*__name__.split('.')[:-1])

class SchemaChecker(object):
    def check_schema(self, xmlfile_path, xsdfile_path):
        if not LXML_AVAILABLE:
            global MESSAGE_SHOWN
            if not MESSAGE_SHOWN:
                msg = "The optional library 'lxml' is not available. The syntax of the configuration files will not be checked."
                print >> sys.stderr, msg
                log.log( SchemaChecker, log.level.Warning, msg )
                MESSAGE_SHOWN = True
            return
        
        xmlfile_content = self._read_xml_file(xmlfile_path)
        xsdfile_full_path = data_filename(os.path.join(module_directory, 'xsd', xsdfile_path))
        try:
            xsdfile_content   = self._read_xsd_file(xsdfile_full_path)
        except:
            msg = "The XSD file %s could not be loaded. The syntax of the configuration files will not be checked." % xsdfile_full_path
            print >> sys.stderr, msg
            log.log( SchemaChecker, log.level.Warning, msg )
            return

        try:
            sio_xsd = StringIO(xsdfile_content)<commit_msg>Don't show the 'lxml not found' so often. Only when running tests<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2005 onwards University of Deusto
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution.
#
# This software consists of contributions made by many individuals,
# listed below:
#
# Author: <NAME> <<EMAIL>>
#

import os
import sys
from StringIO import StringIO

try:
    from lxml import etree
except ImportError:
    LXML_AVAILABLE = False
    MESSAGE_SHOWN  = False
else:
    LXML_AVAILABLE = True

DEBUG = False

from weblab.util import data_filename
import voodoo.log as log
import voodoo.gen.exceptions.loader.LoaderErrors as LoaderErrors

module_directory = os.path.join(*__name__.split('.')[:-1])

class SchemaChecker(object):
    def check_schema(self, xmlfile_path, xsdfile_path):
        if not LXML_AVAILABLE:
            global MESSAGE_SHOWN
            if DEBUG and not MESSAGE_SHOWN:
                msg = "The optional library 'lxml' is not available. The syntax of the configuration files will not be checked."
                print >> sys.stderr, msg
                log.log( SchemaChecker, log.level.Warning, msg )
                MESSAGE_SHOWN = True
            return
        
        xmlfile_content = self._read_xml_file(xmlfile_path)
        xsdfile_full_path = data_filename(os.path.join(module_directory, 'xsd', xsdfile_path))
        try:
            xsdfile_content   = self._read_xsd_file(xsdfile_full_path)
        except:
            msg = "The XSD file %s could not be loaded. The syntax of the configuration files will not be checked." % xsdfile_full_path
            print >> sys.stderr, msg
            log.log( SchemaChecker, log.level.Warning, msg )
            return

        try:
            sio_xsd = StringIO(xsdfile_content)
{'fraction_non_alphanumeric': 0.07824684054853455, 'fraction_numerical': 0.0032266738370529714, 'mean_word_length': 2.716283716283716, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 13}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3217597', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1076, 'n_words': 346}