<commit_before>import csv
import os
import logging
import StringIO
import requests

import dialect
import encoding
from anycsv.csv_model import Table
from anycsv import io
import exceptions
import gzip

DEFAULT_ENCODING='utf-8'
ENC_PRIORITY=['lib_chardet', 'header', 'default']

def reader(filename=None, url=None, content=None, skip_guess_encoding=False, delimiter=None):
    """

    :param filename:
    :param url:
    :param content: The content of a CSV file as a string
    :param skip_guess_encoding: If true, the parser uses utf-8
    :param delimiter:
    :return:
    """
    logger = logging.getLogger(__name__)

    if not filename and not url and not content:
        raise exceptions.AnyCSVException('No CSV input specified')

    meta = sniff_metadata(filename, url, content, skip_guess_encoding=skip_guess_encoding)
    table = Table(url=url, filename=filename)

    dialect = meta['dialect']
    if delimiter:
        table.delimiter = delimiter
        if 'delimiter' in dialect and dialect['delimiter'] != delimiter:
            logging.warning('The given delimiter differs from the guessed delimiter: ' + dialect['delimiter'])
    elif 'delimiter' in dialect:
        table.delimiter = dialect['delimiter']
    else:
        raise exceptions.NoDelimiterException('No delimiter detected')

    if 'quotechar' in dialect:
        table.quotechar = dialect['quotechar']

    table.encoding = meta['used_enc']

    if content:
        input = StringIO.StringIO(content)
    elif filename and os.path.exists(filename):
        if filename.endswith('.gz'):
            input = gzip.open(filename)
        else:
            input = open(filename, 'rU')
    elif url:
        input = URLHandle(url)
    else:
        raise exceptions.AnyCSVException('No CSV input specified')

    if table.encoding and ('utf-8' in table.encoding or 'utf8' in table.encoding):
        table.csvReader = UnicodeReader(input,
                                        delimiter=table.delimiter,
                                        quotechar=table.quotechar)
    else:
        table.csvReader = EncodedCsvReader(input,
                                     encoding=table.encoding,
                                     delimiter=table.delimiter,<commit_msg>sniff lines parameter<commit_after>import csv
import os
import logging
import StringIO
import requests

import dialect
import encoding
from anycsv.csv_model import Table
from anycsv import io
import exceptions
import gzip

DEFAULT_ENCODING='utf-8'
ENC_PRIORITY=['lib_chardet', 'header', 'default']

def reader(filename=None, url=None, content=None, skip_guess_encoding=False, delimiter=None, sniff_lines=100):
    """

    :param filename:
    :param url:
    :param content: The content of a CSV file as a string
    :param skip_guess_encoding: If true, the parser uses utf-8
    :param delimiter:
    :param sniff_lines:
    :return:
    """
    logger = logging.getLogger(__name__)

    if not filename and not url and not content:
        raise exceptions.AnyCSVException('No CSV input specified')

    meta = sniff_metadata(filename, url, content, skip_guess_encoding=skip_guess_encoding, sniffLines=sniff_lines)
    table = Table(url=url, filename=filename)

    dialect = meta['dialect']
    if delimiter:
        table.delimiter = delimiter
        if 'delimiter' in dialect and dialect['delimiter'] != delimiter:
            logger.warning('The given delimiter differs from the guessed delimiter: ' + dialect['delimiter'])
    elif 'delimiter' in dialect:
        table.delimiter = dialect['delimiter']
    else:
        raise exceptions.NoDelimiterException('No delimiter detected')

    if 'quotechar' in dialect:
        table.quotechar = dialect['quotechar']

    table.encoding = meta['used_enc']

    if content:
        input = StringIO.StringIO(content)
    elif filename and os.path.exists(filename):
        if filename.endswith('.gz'):
            input = gzip.open(filename)
        else:
            input = open(filename, 'rU')
    elif url:
        input = URLHandle(url)
    else:
        raise exceptions.AnyCSVException('No CSV input specified')

    if table.encoding and ('utf-8' in table.encoding or 'utf8' in table.encoding):
        table.csvReader = UnicodeReader(input,
                                        delimiter=table.delimiter,
                                        quotechar=table.quotechar)
    else:
        table.csvReader = EncodedCsvReader(input,
                                     encoding=table.encoding,
                                     delimiter=table.delimiter,
{'fraction_non_alphanumeric': 0.08963707914298208, 'fraction_numerical': 0.002404897245299519, 'mean_word_length': 2.6629303442754204, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1161059', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1221, 'n_words': 349}