00001 """
00002 handy class that seporates dictionaries to many dictionaries
00003 """
00004
00005 __copyright__ = """
00006 Copyright 2008 Sean Ross-Ross
00007 """
00008 __license__ = """
00009 This file is part of SLIMpy .
00010
00011 SLIMpy is free software: you can redistribute it and/or modify
00012 it under the terms of the GNU Lesser General Public License as published by
00013 the Free Software Foundation, either version 3 of the License, or
00014 (at your option) any later version.
00015
00016 SLIMpy is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 GNU Lesser General Public License for more details.
00020
00021 You should have received a copy of the GNU Lesser General Public License
00022 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00023 """
00024
00025
00026 class dictSeporator( object ):
00027 """
00028 handy class that seporates dictionaries to many dictionaries
00029 """
00030
00031 def __new__( cls, d, fkeys=None ):
00032 """
00033
00034 """
00035 if fkeys is None:
00036 fkeys = []
00037 return dictSeporator.dictSeporator( d, fkeys=fkeys )
00038
00039 @staticmethod
00040 def dictSeporator( k, fkeys=None ):
00041 """
00042 seporates dictionaries to many dictionaries
00043 """
00044 if fkeys is None:
00045 fkeys = []
00046
00047 List = []
00048 d = {}
00049
00050 for key in k.keys():
00051 x = key[-1]
00052 if x.isdigit():
00053 d2 = d.setdefault( int( x ), dictSeporator.getNonNumberedKeys( k, fkeys=fkeys ) )
00054 d2[key[:-1]] = k[key]
00055
00056 if d:
00057 x = 1
00058 while x:
00059 item = d.pop( x, False )
00060 x += 1
00061 if item:
00062 List.append( item )
00063 else:
00064 break
00065
00066 return List
00067 else:
00068 return [dictSeporator.getNonNumberedKeys( k, fkeys=fkeys )]
00069
00070
00071
00072
00073
00074
00075
00076 @staticmethod
00077 def getNonNumberedKeys( k, fkeys=None ):
00078 """
00079 gets
00080 """
00081 if fkeys is None:
00082 fkeys = []
00083
00084 d = dict.fromkeys( fkeys )
00085
00086 for key in k.keys():
00087
00088 if not key[-1].isdigit():
00089 d[key] = k[key]
00090 return d
00091