00001 __copyright__ = """
00002 Copyright 2008 Sean Ross-Ross
00003 """
00004 __license__ = """
00005 This file is part of SLIMpy .
00006
00007 SLIMpy is free software: you can redistribute it and/or modify
00008 it under the terms of the GNU Lesser General Public License as published by
00009 the Free Software Foundation, either version 3 of the License, or
00010 (at your option) any later version.
00011
00012 SLIMpy is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015 GNU Lesser General Public License for more details.
00016
00017 You should have received a copy of the GNU Lesser General Public License
00018 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00019 """
00020
00021 from slimpy_base.Core.Command.Converter import Converter
00022 from sfcommands.sfConverter import sfConverter
00023
00024 class rsfCommandFactory(object):
00025 shared_state = {}
00026 converters = {}
00027
00028 def __init__(self):
00029 self.__dict__ = self.shared_state
00030
00031 def add(self,class_,name=None):
00032 if name is None:
00033 name = class_.__name__
00034 self.converters[ name ] = class_
00035
00036 def addallfrom(self,all):
00037 for classes in dir(all):
00038 class_ = getattr( all,classes )
00039 try:
00040 is_con = issubclass(class_, Converter)
00041 except:
00042 is_con = False
00043 if is_con:
00044 self.converters[ class_.__name__ ] = class_
00045
00046 def __setitem__(self,name,val):
00047 self.add(val, name)
00048
00049 def __getitem__(self,name):
00050
00051 converters = self.converters
00052 if converters.has_key( name ):
00053 return converters[ name ]
00054 else:
00055 return sfConverter
00056