# Path: apiritif/utils.py
# class NormalShutdown(BaseException):
#     pass


import re
import threading
import csv
import apiritif.thread as thread
from io import open
from itertools import cycle, islice
from chardet.universaldetector import UniversalDetector
from apiritif.utils import NormalShutdown
        format_params["quoting"] = csv.QUOTE_MINIMAL if quoted else csv.QUOTE_NONE

        self.fds = open(filename, 'r', encoding=encoding)

        if not delimiter:
            dialect = csv.Sniffer().sniff(self.fds.read())
            self.fds.seek(0)
            delimiter = dialect.delimiter
        format_params["delimiter"] = delimiter

        self._reader = csv.DictReader(self.fds, fieldnames=fieldnames, **format_params)
        if loop:
            self._reader = cycle(self._reader)

    def close(self):
        if self.fds is not None:
            self.fds.close()
        self._reader = None

    def read_vars(self):
        if not self._reader:
            return  # todo: exception?

        try:
            if not self.csv:  # first element
                self.csv = next(islice(self._reader, self.first, self.first + 1))
            else:  # next one
                self.csv = next(islice(self._reader, self.step - 1, self.step))
        except StopIteration:
            stop_reason = "Data source is exhausted: %s" % self.fds.name

# Path: apiritif/utils.py
# class NormalShutdown(BaseException):
#     pass


# Path: apiritif/csv.py
import re
import threading
import csv
import apiritif.thread as thread
from io import open
from itertools import cycle, islice
from chardet.universaldetector import UniversalDetector
from apiritif.utils import NormalShutdown

        format_params["quoting"] = csv.QUOTE_MINIMAL if quoted else csv.QUOTE_NONE

        self.fds = open(filename, 'r', encoding=encoding)

        if not delimiter:
            dialect = csv.Sniffer().sniff(self.fds.read())
            self.fds.seek(0)
            delimiter = dialect.delimiter
        format_params["delimiter"] = delimiter

        self._reader = csv.DictReader(self.fds, fieldnames=fieldnames, **format_params)
        if loop:
            self._reader = cycle(self._reader)

    def close(self):
        if self.fds is not None:
            self.fds.close()
        self._reader = None

    def read_vars(self):
        if not self._reader:
            return  # todo: exception?

        try:
            if not self.csv:  # first element
                self.csv = next(islice(self._reader, self.first, self.first + 1))
            else:  # next one
                self.csv = next(islice(self._reader, self.step - 1, self.step))
        except StopIteration:
            stop_reason = "Data source is exhausted: %s" % self.fds.name

            raise NormalShutdown(stop_reason)  # Just send it up