#!/usr/bin/env python
# -*- coding: utf8 -*-

from ZIFile import *
from FPParser import *
from APNFile import *
from MOFile import *

from FWTChecker import *
from WTChecker import *

parsers = {
    ZIFile.name : ZIFile,
    FPParser.name : FPParser,
    APNFile.name : APNFile,
    MOFile.name : MOFile,
}

checkers = {
    FWTChecker.name : FWTChecker,
    WTChecker.name : WTChecker
}

class FileFactory (object):

    def get_parser(self, type):
        for parser in parsers.values():
            if parser.extension.upper() == type.upper():
                try:
                    tmp = parser()
                except GenericFile, e:
                    return e
                else:
                    return tmp

                break

    def get_labels(self):
        return [value.name for value in parsers.values()]


class FunctionConverter:

    def convert(self, target_type, content):
        if target_type in parsers:
            return parsers[target_type](content)

class FunctionChecker:
    def check(self, checker_type, content):
        if checker_type in checkers:
            return checkers[checker_type](content)
