<commit_before>from tornado.web import UIModule


class IncludeExtFiles(UIModule):
    def render(self):
        return ''
    
    def get_urls(self, file_extension):
        if hasattr(self.handler, 'ext_files'):
            ext_files = [self.handler.static_url(fn)
                         for fn in self.handler.ext_files
                         if '.'+file_extension in fn]
        else:
            ext_files = []
            
        #Para incluir archivos de un modulo, el handler tiene que
        #heredar de src.handlers.ModuleHandler.
        if hasattr(self.handler, 'module_files') and \
           hasattr(self.handler, 'module_url'):
            module_files = [self.handler.module_url(fn)
                            for fn in self.handler.module_files
                            if '.'+file_extension in fn]
        else:
            module_files = []
        
        return module_files + ext_files
            
    def css_files(self):
        return self.get_urls('css')
        
    def javascript_files(self):
        return self.get_urls('js')<commit_msg>Added src.UIModule class, which improves css and js files management.<commit_after>import tornado


class IncludeExtFiles(tornado.web.UIModule):
    def render(self):
        return ''
    
    def get_urls(self, file_extension):
        if hasattr(self.handler, 'ext_files'):
            ext_files = [self.handler.static_url(fn)
                         for fn in self.handler.ext_files
                         if '.'+file_extension in fn]
        else:
            ext_files = []
            
        #Para incluir archivos de un modulo, el handler tiene que
        #heredar de src.handlers.ModuleHandler.
        if hasattr(self.handler, 'module_files') and \
           hasattr(self.handler, 'module_url'):
            module_files = [self.handler.module_url(fn)
                            for fn in self.handler.module_files
                            if '.'+file_extension in fn]
        else:
            module_files = []
        
        return module_files + ext_files
            
    def css_files(self):
        return self.get_urls('css')
        
    def javascript_files(self):
        return self.get_urls('js')
        

class UIModule(tornado.web.UIModule):
    def __init__(self):
        super().__init__(self, handler)
        self.css_files = []
        self.js_files = []
        
    def render(self, set_resources=None):
        if set_resources:
            set_resource(javascript_files=self.js_files,
                         css_files=self.css_files)
    
    def javascript_files(self):
        """Returns a list of JavaScript files required by this module."""
        return self.js_files

    def css_files(self):
        """Returns a list of CSS files required by this module."""
        return self.css_files
{'fraction_non_alphanumeric': 0.088016967126193, 'fraction_numerical': 0.0, 'mean_word_length': 1.750242954324587, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '1631270', 'n_tokens_mistral': 790, 'n_tokens_neox': 784, 'n_words': 187}