<commit_before>import datetime
import email.utils
import re

import uritools
from mopidy import models

from . import Extension

try:
    import xml.etree.cElementTree as ElementTree
except ImportError:
    import xml.etree.ElementTree as ElementTree


def parse(source):
    if isinstance(source, basestring):
        url = uritools.uricompose("file", "", source)
    else:
        url = source.geturl()
    root = ElementTree.parse(source).getroot()
    if root.tag == "rss":
        return RssFeed(url, root)
    elif root.tag == "opml":
        return OpmlFeed(url, root)
    else:
        raise TypeError("Not a recognized podcast feed: %s", url)


def get_url(source, default=None):
    """
    Get URL from xml.etree.ElementTree.Element.

    URL is often capitalized in OPML feeds.
    """
    return source.get("url", source.get("URL", default))


class PodcastFeed:
    def __init__(self, url):
        self.uri = self.getfeeduri(url)

    @classmethod
    def getfeeduri(cls, url):
        return uritools.uridefrag(Extension.ext_name + "+" + url).uri

    def getitemuri(self, guid, safe=uritools.SUB_DELIMS + b":@/?"):
        return self.uri + "#" + uritools.uriencode(guid, safe=safe)

    def getstreamuri(self, guid):
        raise NotImplemented

    def items(self, newest_first=None):
        raise NotImplemented

    def tracks(self, newest_first=None):
        return []

    def images(self):
        return []


class RssFeed(PodcastFeed):

    ITUNES_PREFIX = "{http://www.itunes.com/dtds/podcast-1.0.dtd}"

    DURATION_RE = re.compile(
        r"""
    (?:
      (?:(?P<hours>\d+):)?<commit_msg>flake8: 'raise NotImplemented' should be 'raise NotImplementedError'<commit_after>import datetime
import email.utils
import re

import uritools
from mopidy import models

from . import Extension

try:
    import xml.etree.cElementTree as ElementTree
except ImportError:
    import xml.etree.ElementTree as ElementTree


def parse(source):
    if isinstance(source, basestring):
        url = uritools.uricompose("file", "", source)
    else:
        url = source.geturl()
    root = ElementTree.parse(source).getroot()
    if root.tag == "rss":
        return RssFeed(url, root)
    elif root.tag == "opml":
        return OpmlFeed(url, root)
    else:
        raise TypeError("Not a recognized podcast feed: %s", url)


def get_url(source, default=None):
    """
    Get URL from xml.etree.ElementTree.Element.

    URL is often capitalized in OPML feeds.
    """
    return source.get("url", source.get("URL", default))


class PodcastFeed:
    def __init__(self, url):
        self.uri = self.getfeeduri(url)

    @classmethod
    def getfeeduri(cls, url):
        return uritools.uridefrag(Extension.ext_name + "+" + url).uri

    def getitemuri(self, guid, safe=uritools.SUB_DELIMS + b":@/?"):
        return self.uri + "#" + uritools.uriencode(guid, safe=safe)

    def getstreamuri(self, guid):
        raise NotImplementedError

    def items(self, newest_first=None):
        raise NotImplementedError

    def tracks(self, newest_first=None):
        return []

    def images(self):
        return []


class RssFeed(PodcastFeed):

    ITUNES_PREFIX = "{http://www.itunes.com/dtds/podcast-1.0.dtd}"

    DURATION_RE = re.compile(
        r"""
    (?:
      (?:(?P<hours>\d+):)?
{'fraction_non_alphanumeric': 0.1253397765025672, 'fraction_numerical': 0.0015101177891875567, 'mean_word_length': 2.9855595667870034, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, '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': '626089', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1064, 'n_words': 257}