# Path: apiritif/thread.py
# def get_index():
#     index = getattr(_thread_local, "index", 0)
#     return index
# 
# Path: apiritif/csv.py
# class CSVReaderPerThread(Reader):  # processes multi-thread specific
#     def __init__(self, filename, fieldnames=None, delimiter=None, loop=True, quoted=None, encoding=None):
#         self.filename = filename
#         self.fieldnames = fieldnames
#         self.delimiter = delimiter
#         self.loop = loop
#         self.quoted = quoted
#         self.encoding = encoding
# 
#     def _get_csv_reader(self, create=False):
#         csv_readers = getattr(thread_data, "csv_readers", None)
#         if not csv_readers:
#             thread_data.csv_readers = {}
# 
#         csv_reader = thread_data.csv_readers.get(id(self))
#         if not csv_reader and create:
#             csv_reader = CSVReader(
#                 filename=self.filename,
#                 fieldnames=self.fieldnames,
#                 step=thread.get_total(),
#                 first=thread.get_index(),
#                 delimiter=self.delimiter,
#                 loop=self.loop,
#                 quoted=self.quoted,
#                 encoding=self.encoding)
# 
#             thread_data.csv_readers[id(self)] = csv_reader
# 
#         return csv_reader
# 
#     def read_vars(self):
#         self._get_csv_reader(create=True).read_vars()
# 
#     def close(self):
#         csv_reader = self._get_csv_reader()
#         if csv_reader:
#             del thread_data.csv_readers[id(self)]
#             csv_reader.close()
# 
#     def get_vars(self):
#         csv_reader = self._get_csv_reader()
#         if csv_reader:
#             return csv_reader.get_vars()
#         else:
#             return {}


import os
import unittest
import apiritif
from apiritif.thread import get_index
from apiritif.csv import CSVReaderPerThread



reader0 = CSVReaderPerThread(os.path.join(os.path.dirname(__file__), "data/source0.csv"), quoted=True)
reader1 = CSVReaderPerThread(os.path.join(os.path.dirname(__file__), "data/source1.csv"),
                             fieldnames=["name+", "pass+"],
                             delimiter="-")


def log_it(name, data):
    variables = ":".join((data["name"], data["pass"], data["name+"], data["pass+"]))
    log_line = "%s-%s. %s\n" % (get_index(), name, variables)
    with apiritif.transaction(log_line):    # write log_line into report file for checking purposes
        pass


def setUpModule():    # setup_module
    reader0.read_vars()

# Path: apiritif/thread.py
# def get_index():
#     index = getattr(_thread_local, "index", 0)
#     return index
# 
# Path: apiritif/csv.py
# class CSVReaderPerThread(Reader):  # processes multi-thread specific
#     def __init__(self, filename, fieldnames=None, delimiter=None, loop=True, quoted=None, encoding=None):
#         self.filename = filename
#         self.fieldnames = fieldnames
#         self.delimiter = delimiter
#         self.loop = loop
#         self.quoted = quoted
#         self.encoding = encoding
# 
#     def _get_csv_reader(self, create=False):
#         csv_readers = getattr(thread_data, "csv_readers", None)
#         if not csv_readers:
#             thread_data.csv_readers = {}
# 
#         csv_reader = thread_data.csv_readers.get(id(self))
#         if not csv_reader and create:
#             csv_reader = CSVReader(
#                 filename=self.filename,
#                 fieldnames=self.fieldnames,
#                 step=thread.get_total(),
#                 first=thread.get_index(),
#                 delimiter=self.delimiter,
#                 loop=self.loop,
#                 quoted=self.quoted,
#                 encoding=self.encoding)
# 
#             thread_data.csv_readers[id(self)] = csv_reader
# 
#         return csv_reader
# 
#     def read_vars(self):
#         self._get_csv_reader(create=True).read_vars()
# 
#     def close(self):
#         csv_reader = self._get_csv_reader()
#         if csv_reader:
#             del thread_data.csv_readers[id(self)]
#             csv_reader.close()
# 
#     def get_vars(self):
#         csv_reader = self._get_csv_reader()
#         if csv_reader:
#             return csv_reader.get_vars()
#         else:
#             return {}


# Path: tests/resources/test_two_readers.py
import os
import unittest
import apiritif
from apiritif.thread import get_index
from apiritif.csv import CSVReaderPerThread




reader0 = CSVReaderPerThread(os.path.join(os.path.dirname(__file__), "data/source0.csv"), quoted=True)
reader1 = CSVReaderPerThread(os.path.join(os.path.dirname(__file__), "data/source1.csv"),
                             fieldnames=["name+", "pass+"],
                             delimiter="-")


def log_it(name, data):
    variables = ":".join((data["name"], data["pass"], data["name+"], data["pass+"]))
    log_line = "%s-%s. %s\n" % (get_index(), name, variables)
    with apiritif.transaction(log_line):    # write log_line into report file for checking purposes
        pass


def setUpModule():    # setup_module
    reader0.read_vars()

    reader1.read_vars()