<commit_before>#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# Copyright 2013-2018 <NAME> <<EMAIL> at <EMAIL>>
#
# License: BSD

r"""Parse any ticket description or comment text with @<Username> or #<tag>.

Copyright 2013-2018 <NAME> <olemis at gmail.com>
Licensed under the BSD License
"""
__author__ = '<NAME>'

import pkg_resources

from genshi.core import START
from genshi.filters.transform import Transformer

from trac.config import Option
from trac.core import Component, implements
from trac.web.api import ITemplateStreamFilter
from trac.web.chrome import add_script, add_stylesheet, ITemplateProvider, add_script_data
from trac.web.href import Href
from trac.web import IRequestFilter
from trac.web.chrome import Chrome
import re

class MentionsModule(Component):
    """Autocomplete @<Username> or #<tag>. Parse any ticket description or
    comment text to leverage hashtags as Trac tags
    """
    implements(ITemplateProvider, ITemplateStreamFilter, IRequestFilter)

    jquery_mentions_location = Option('trac', 'jquery_mentions_location', 
                                      doc="""Path to jquery mentions plugin""")

    underscore_location = Option('trac', 'underscorejs_location', 
                                 doc="""Path to underscore.js library""")

    @property
    def underscore_href(self):
        return Href(self.underscore_location)

    # ITemplateProvider methods                                             
    def get_htdocs_dirs(self):                                              
        return [('mentions',                                                
             pkg_resources.resource_filename('tracmentions', 'htdocs'))]

    def get_templates_dirs(self):                                           
        return []                                                           


    # ITemplateStreamFilter methods

    def filter_stream(self, req, method, filename, stream, data):
        """Setup user and tags autocompletion"""

        if method == 'xhtml':
            return self._process_stream(req, stream)
        return stream

    # Protected methods
<commit_msg>Trac Mentions : Filter template streams instead of returning generator object<commit_after>#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# Copyright 2013-2018 <NAME> <<EMAIL>mis at <EMAIL>>
#
# License: BSD

r"""Parse any ticket description or comment text with @<Username> or #<tag>.

Copyright 2013-2018 <NAME> <<EMAIL> at <EMAIL>>
Licensed under the BSD License
"""
__author__ = '<NAME>'

import pkg_resources

from genshi.core import START
from genshi.filters.transform import Transformer

from trac.config import Option
from trac.core import Component, implements
from trac.web.api import ITemplateStreamFilter
from trac.web.chrome import add_script, add_stylesheet, ITemplateProvider, add_script_data
from trac.web.href import Href
from trac.web import IRequestFilter
from trac.web.chrome import Chrome
import re

class MentionsModule(Component):
    """Autocomplete @<Username> or #<tag>. Parse any ticket description or
    comment text to leverage hashtags as Trac tags
    """
    implements(ITemplateProvider, ITemplateStreamFilter, IRequestFilter)

    jquery_mentions_location = Option('trac', 'jquery_mentions_location', 
                                      doc="""Path to jquery mentions plugin""")

    underscore_location = Option('trac', 'underscorejs_location', 
                                 doc="""Path to underscore.js library""")

    @property
    def underscore_href(self):
        return Href(self.underscore_location)

    # ITemplateProvider methods                                             
    def get_htdocs_dirs(self):                                              
        return [('mentions',                                                
             pkg_resources.resource_filename('tracmentions', 'htdocs'))]

    def get_templates_dirs(self):                                           
        return []                                                           


    # ITemplateStreamFilter methods

    def filter_stream(self, req, method, filename, stream, data):
        """Setup user and tags autocompletion"""

        if method == 'xhtml':
            return stream.filter(lambda s : self._process_stream(req, s))
        return stream

    # Protected methods

{'fraction_non_alphanumeric': 0.08511617207269381, 'fraction_numerical': 0.007821486082355647, 'mean_word_length': 2.2399403874813713, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3589038', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1056, 'n_words': 325}