<commit_before>from __future__ import unicode_literals

import ConfigParser as configparser
import io

import gobject

import pygst
pygst.require('0.10')
import gst  # noqa

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


# TODO: make detect_FOO_header reusable in general mopidy code.
# i.e. give it just a "peek" like function.
def detect_m3u_header(typefind):
    return typefind.peek(0, 8).upper() == b'#EXTM3U\n'


def detect_pls_header(typefind):
    return typefind.peek(0, 11).lower() == b'[playlist]\n'


def detect_xspf_header(typefind):
    data = typefind.peek(0, 150)
    if b'xspf' not in data.lower():
        return False

    try:
        data = io.BytesIO(data)
        for event, element in elementtree.iterparse(data, events=(b'start',)):
            return element.tag.lower() == '{http://xspf.org/ns/0/}playlist'
    except elementtree.ParseError:
        pass
    return False


def detect_asx_header(typefind):
    data = typefind.peek(0, 50)
    if b'asx' not in data.lower():
        return False

    try:
        data = io.BytesIO(data)
        for event, element in elementtree.iterparse(data, events=(b'start',)):
            return element.tag.lower() == 'asx'<commit_msg>audio: Handle carriage return in playlist detection<commit_after>from __future__ import unicode_literals

import ConfigParser as configparser
import io

import gobject

import pygst
pygst.require('0.10')
import gst  # noqa

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


# TODO: make detect_FOO_header reusable in general mopidy code.
# i.e. give it just a "peek" like function.
def detect_m3u_header(typefind):
    return typefind.peek(0, 7).upper() == b'#EXTM3U'


def detect_pls_header(typefind):
    return typefind.peek(0, 10).lower() == b'[playlist]'


def detect_xspf_header(typefind):
    data = typefind.peek(0, 150)
    if b'xspf' not in data.lower():
        return False

    try:
        data = io.BytesIO(data)
        for event, element in elementtree.iterparse(data, events=(b'start',)):
            return element.tag.lower() == '{http://xspf.org/ns/0/}playlist'
    except elementtree.ParseError:
        pass
    return False


def detect_asx_header(typefind):
    data = typefind.peek(0, 50)
    if b'asx' not in data.lower():
        return False

    try:
        data = io.BytesIO(data)
        for event, element in elementtree.iterparse(data, events=(b'start',)):
            return element.tag.lower() == 'asx'
{'fraction_non_alphanumeric': 0.11304012345679013, 'fraction_numerical': 0.013888888888888888, 'mean_word_length': 3.3144758735440933, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '1429391', 'n_tokens_mistral': 902, 'n_tokens_neox': 870, 'n_words': 225}