<commit_before>import datetime

from django.utils import feedgenerator, tzinfo
from django.contrib.syndication.views import Feed, add_domain
from django.contrib.sites.models import get_current_site
from django.utils.encoding import force_unicode, iri_to_uri
from django import template
from django.contrib.contenttypes.models import ContentType

class WxrFeedType(feedgenerator.Rss201rev2Feed):
    def rss_attributes(self):
        return {
            u"version": self._version,
            u'xmlns:content': u"http://purl.org/rss/1.0/modules/content/",
            u'xmlns:dsq': u"http://www.disqus.com/",
            u'xmlns:dc': u"http://purl.org/dc/elements/1.1/",
            u'xmlns:wp': u"http://wordpress.org/export/1.0/",
        }
    
    def add_item(self, title, link, description, author_email=None,
        author_name=None, author_link=None, pubdate=None, comments=None,
        unique_id=None, enclosure=None, categories=(), item_copyright=None,
        ttl=None, **kwargs):
        """
        Adds an item to the feed. All args are expected to be Python Unicode
        objects except pubdate, which is a datetime.datetime object, and
        enclosure, which is an instance of the Enclosure class.
        """
        to_unicode = lambda s: force_unicode(s, strings_only=True)
        if categories:
            categories = [to_unicode(c) for c in categories]
        if ttl is not None:
            # Force ints to unicode
            ttl = force_unicode(ttl)
        item = {
            'title': to_unicode(title),
            'link': iri_to_uri(link),
            'description': to_unicode(description),
            'author_email': to_unicode(author_email),
            'author_name': to_unicode(author_name),
            'author_link': iri_to_uri(author_link),
            'pubdate': pubdate,
            'comments': comments,
            'unique_id': to_unicode(unique_id),
            'enclosure': enclosure,
            'categories': categories or (),
            'item_copyright': to_unicode(item_copyright),
            'ttl': ttl,
        }
        item.update(kwargs)
        self.items.append(item)
    
    def add_root_elements(self, handler):
        pass
    
    def add_item_elements(self, handler, item):
        if item['comments'] is None:
            return
        handler.addQuickElement(u"title", item['title'])
        handler.addQuickElement(u"link", item['link'])
        handler.addQuickElement(u"content:encoded", "<![CDATA[%s]]>" % item['description'])
        handler.addQuickElement(u'dsq:thread_identifier', item['unique_id'])
        handler.addQuickElement(u'wp:post_date_gmt', 
            feedgenerator.rfc3339_date(item['pubdate']).decode('utf-8'))
        handler.addQuickElement(u'wp:comment_status', item['comment_status'])
        self.write_comments(handler, item['comments'])
        
    def add_comment_elements(self, handler, comment):
        handler.startElement(u"dsq:remote", {})
        handler.addQuickElement(u"dsq:id", comment['user_id'])
        handler.addQuickElement(u"dsq:avatar", comment['avatar'])
        handler.endElement(u"dsq:remote")
        handler.addQuickElement(u"wp:comment_id", comment['id'])
        handler.addQuickElement(u"wp:comment_author", "<![CDATA[%s]]>" % comment['user_name'])
        handler.addQuickElement(u"wp:comment_author_email", comment['user_email'])
        handler.addQuickElement(u"wp:comment_author_url", comment['user_url'])
        handler.addQuickElement(u"wp:comment_author_IP", comment['ip_address'])
        handler.addQuickElement(u"wp:comment_date_gmt", 
            feedgenerator.rfc3339_date(comment['submit_date']).decode('utf-8'))
        handler.addQuickElement(u"wp:comment_content", "<![CDATA[%s]]>" % comment['comment'])
        handler.addQuickElement(u"wp:comment_approved", comment['is_approved'])
        if comment['parent'] is not None:
            handler.addQuickElement(u"wp:comment_parent", comment['parent'])
    
    def write_comments(self, handler, comments):
        for comment in comments:
            handler.startElement(u"wp:comment", {})
            self.add_comment_elements(handler, comment)
            handler.endElement(u"wp:comment")


class BaseWxrFeed(Feed):
    feed_type = WxrFeedType
    
    def get_feed(self, obj, request):
        current_site = get_current_site(request)
        
        link = self._Feed__get_dynamic_attr('link', obj)
        link = add_domain(current_site.domain, link)
        feed = self.feed_type(
            title = self._Feed__get_dynamic_attr('title', obj),
            link = link,
            description = self._Feed__get_dynamic_attr('description', obj),
        )
        
        title_tmp = None
        if self.title_template is not None:
            try:
                title_tmp = template.loader.get_template(self.title_template)
            except template.TemplateDoesNotExist:
                pass
        
        description_tmp = None
        if self.description_template is not None:
            try:<commit_msg>Removed the CDATA to see if it works without. It was changing the < and ><commit_after>import datetime

from django.utils import feedgenerator, tzinfo
from django.contrib.syndication.views import Feed, add_domain
from django.utils.encoding import force_unicode, iri_to_uri
from django import template
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site

class WxrFeedType(feedgenerator.Rss201rev2Feed):
    def rss_attributes(self):
        return {
            u"version": self._version,
            u'xmlns:content': u"http://purl.org/rss/1.0/modules/content/",
            u'xmlns:dsq': u"http://www.disqus.com/",
            u'xmlns:dc': u"http://purl.org/dc/elements/1.1/",
            u'xmlns:wp': u"http://wordpress.org/export/1.0/",
        }
    
    def add_item(self, title, link, description, author_email=None,
        author_name=None, author_link=None, pubdate=None, comments=None,
        unique_id=None, enclosure=None, categories=(), item_copyright=None,
        ttl=None, **kwargs):
        """
        Adds an item to the feed. All args are expected to be Python Unicode
        objects except pubdate, which is a datetime.datetime object, and
        enclosure, which is an instance of the Enclosure class.
        """
        to_unicode = lambda s: force_unicode(s, strings_only=True)
        if categories:
            categories = [to_unicode(c) for c in categories]
        if ttl is not None:
            # Force ints to unicode
            ttl = force_unicode(ttl)
        item = {
            'title': to_unicode(title),
            'link': iri_to_uri(link),
            'description': to_unicode(description),
            'author_email': to_unicode(author_email),
            'author_name': to_unicode(author_name),
            'author_link': iri_to_uri(author_link),
            'pubdate': pubdate,
            'comments': comments,
            'unique_id': to_unicode(unique_id),
            'enclosure': enclosure,
            'categories': categories or (),
            'item_copyright': to_unicode(item_copyright),
            'ttl': ttl,
        }
        item.update(kwargs)
        self.items.append(item)
    
    def add_root_elements(self, handler):
        pass
    
    def add_item_elements(self, handler, item):
        if item['comments'] is None:
            return
        handler.addQuickElement(u"title", item['title'])
        handler.addQuickElement(u"link", item['link'])
        handler.addQuickElement(u"content:encoded", item['description'])
        handler.addQuickElement(u'dsq:thread_identifier', item['unique_id'])
        handler.addQuickElement(u'wp:post_date_gmt', 
            feedgenerator.rfc3339_date(item['pubdate']).decode('utf-8'))
        handler.addQuickElement(u'wp:comment_status', item['comment_status'])
        self.write_comments(handler, item['comments'])
        
    def add_comment_elements(self, handler, comment):
        handler.startElement(u"dsq:remote", {})
        handler.addQuickElement(u"dsq:id", comment['user_id'])
        handler.addQuickElement(u"dsq:avatar", comment['avatar'])
        handler.endElement(u"dsq:remote")
        handler.addQuickElement(u"wp:comment_id", comment['id'])
        handler.addQuickElement(u"wp:comment_author", comment['user_name'])
        handler.addQuickElement(u"wp:comment_author_email", comment['user_email'])
        handler.addQuickElement(u"wp:comment_author_url", comment['user_url'])
        handler.addQuickElement(u"wp:comment_author_IP", comment['ip_address'])
        handler.addQuickElement(u"wp:comment_date_gmt", 
            feedgenerator.rfc3339_date(comment['submit_date']).decode('utf-8'))
        handler.addQuickElement(u"wp:comment_content", comment['comment'])
        handler.addQuickElement(u"wp:comment_approved", comment['is_approved'])
        if comment['parent'] is not None:
            handler.addQuickElement(u"wp:comment_parent", comment['parent'])
    
    def write_comments(self, handler, comments):
        for comment in comments:
            handler.startElement(u"wp:comment", {})
            self.add_comment_elements(handler, comment)
            handler.endElement(u"wp:comment")


class BaseWxrFeed(Feed):
    feed_type = WxrFeedType
    
    def get_feed(self, obj, request):
        current_site = Site.objects.get_current()
        
        link = self._Feed__get_dynamic_attr('link', obj)
        link = add_domain(current_site.domain, link)
        feed = self.feed_type(
            title = self._Feed__get_dynamic_attr('title', obj),
            link = link,
            description = self._Feed__get_dynamic_attr('description', obj),
        )
        
        title_tmp = None
        if self.title_template is not None:
            try:
                title_tmp = template.loader.get_template(self.title_template)
            except template.TemplateDoesNotExist:
                pass
        
        description_tmp = None
        if self.description_template is not None:
            try:
{'fraction_non_alphanumeric': 0.11709741550695825, 'fraction_numerical': 0.003976143141153081, 'mean_word_length': 2.803780718336484, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, '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': '4581096', 'n_tokens_mistral': 2973, 'n_tokens_neox': 2905, 'n_words': 546}