2323# =============================================================================
2424
2525"""This module contains the oblivion importer patcher classes."""
26- import collections
2726import re
27+ from collections import defaultdict , Counter
2828from itertools import chain
2929from operator import attrgetter
3030# Internal
@@ -50,7 +50,7 @@ class _SimpleImporter(ImportPatcher):
5050 def initPatchFile (self , patchFile ):
5151 super (_SimpleImporter , self ).initPatchFile (patchFile )
5252 #--(attribute-> value) dicts keyed by long fid.
53- self .id_data = collections . defaultdict (dict )
53+ self .id_data = defaultdict (dict )
5454 self .srcClasses = set () #--Record classes actually provided by src
5555 # mods/files.
5656 self .classestemp = set ()
@@ -195,7 +195,7 @@ def buildPatch(self, log, progress, types=None):
195195 if not self .isActive : return
196196 modFileTops = self .patchFile .tops
197197 keep = self .patchFile .getKeeper ()
198- type_count = collections . defaultdict ( int )
198+ type_count = Counter ( )
199199 types = filter (modFileTops .__contains__ , types if types else map (
200200 attrgetter ('classType' ), self .srcClasses ))
201201 for top_mod_rec in types :
@@ -213,9 +213,8 @@ class _RecTypeModLogging(CBash_ImportPatcher):
213213
214214 def initPatchFile (self , patchFile ):
215215 super (_RecTypeModLogging , self ).initPatchFile (patchFile )
216- self .mod_count = collections .defaultdict (
217- lambda : collections .defaultdict (int ))
218- self .fid_attr_value = collections .defaultdict (dict ) # used in some
216+ self .mod_count = defaultdict (Counter )
217+ self .fid_attr_value = defaultdict (dict ) # used in some
219218
220219 def _clog (self , log ):
221220 """Used in: CBash_SoundPatcher, CBash_ImportScripts,
@@ -235,8 +234,7 @@ def _clog(self, log):
235234 'count' : sum (mod_count [group_type ].values ())})
236235 for srcMod in load_order .get_ordered (mod_count [group_type ].keys ()):
237236 log (u' * %s: %d' % (srcMod .s , mod_count [group_type ][srcMod ]))
238- self .mod_count = collections .defaultdict (
239- lambda : collections .defaultdict (int ))
237+ self .mod_count = defaultdict (Counter )
240238
241239 def scan (self ,modFile ,record ,bashTags ):
242240 """Records information needed to apply the patch."""
@@ -262,7 +260,7 @@ class CellImporter(_ACellImporter, ImportPatcher):
262260 #--Patch Phase ------------------------------------------------------------
263261 def initPatchFile (self , patchFile ):
264262 super (CellImporter , self ).initPatchFile (patchFile )
265- self .cellData = collections . defaultdict (dict )
263+ self .cellData = defaultdict (dict )
266264 # TODO: docs: recAttrs vs tag_attrs - extra in PBash:
267265 # 'unused1','unused2','unused3'
268266 self .recAttrs = bush .game .cellRecAttrs # dict[unicode, tuple[str]]
@@ -326,7 +324,7 @@ def checkMasterCellBlockData(cellBlock):
326324 # (attributes (among attrs) -> their values for this mod). It is
327325 # used to update cellData with cells that change those attributes'
328326 # values from the value in any of srcMod's masters.
329- tempCellData = collections . defaultdict (dict )
327+ tempCellData = defaultdict (dict )
330328 tempCellData ['Maps' ] = {} # unused !
331329 srcInfo = bosh .modInfos [srcMod ]
332330 srcFile = ModFile (srcInfo ,loadFactory )
@@ -437,7 +435,7 @@ def handlePatchCellBlock(patchCellBlock):
437435 return modified
438436 if not self .isActive : return
439437 keep = self .patchFile .getKeeper ()
440- cellData , count = self .cellData , collections . defaultdict ( int )
438+ cellData , count = self .cellData , Counter ( )
441439 for cellBlock in self .patchFile .CELL .cellBlocks :
442440 if cellBlock .cell .fid in cellData and handlePatchCellBlock (cellBlock ):
443441 count [cellBlock .cell .fid [0 ]] += 1
@@ -479,7 +477,7 @@ class CBash_CellImporter(_ACellImporter,CBash_ImportPatcher):
479477 def initPatchFile (self , patchFile ):
480478 super (CBash_CellImporter , self ).initPatchFile (patchFile )
481479 if not self .isActive : return
482- self .fid_attr_value = collections . defaultdict (dict )
480+ self .fid_attr_value = defaultdict (dict )
483481 self .tag_attrs = {
484482 u'C.Climate' : ('climate' ,'IsBehaveLikeExterior' ),
485483 u'C.Music' : ('musicType' ,),
@@ -973,7 +971,7 @@ class CBash_KFFZPatcher(CBash_ImportPatcher, _AKFFZPatcher):
973971 def initPatchFile (self , patchFile ):
974972 super (CBash_KFFZPatcher , self ).initPatchFile (patchFile )
975973 if not self .isActive : return
976- self .id_animations = collections . defaultdict (list )
974+ self .id_animations = defaultdict (list )
977975
978976 def getTypes (self ):
979977 """Returns the group types that this patcher checks"""
@@ -1160,7 +1158,7 @@ def buildPatch(self,log,progress): # buildPatch1:no modFileTops, for type..
11601158 if not self .isActive : return
11611159 keep = self .patchFile .getKeeper ()
11621160 merged_deleted = self .id_merged_deleted
1163- mod_count = collections . defaultdict ( int )
1161+ mod_count = Counter ( )
11641162 for rec_type in ('NPC_' ,'CREA' ):
11651163 for record in getattr (self .patchFile ,rec_type ).records :
11661164 fid = record .fid
@@ -1171,8 +1169,7 @@ def buildPatch(self,log,progress): # buildPatch1:no modFileTops, for type..
11711169 changed = True
11721170 if changed :
11731171 keep (record .fid )
1174- mod = record .fid [0 ]
1175- mod_count [mod ] += 1
1172+ mod_count [record .fid [0 ]] += 1
11761173 self .id_merged_deleted .clear ()
11771174 self ._patchLog (log ,mod_count )
11781175
@@ -1799,7 +1796,7 @@ def buildPatch(self,log,progress): # buildPatch1:no modFileTops, for type..
17991796 if not self .isActive : return
18001797 keep = self .patchFile .getKeeper ()
18011798 id_deltas = self .id_deltas
1802- mod_count = collections . defaultdict ( int )
1799+ mod_count = Counter ( )
18031800 for inv_type in bush .game .inventoryTypes :
18041801 for record in getattr (self .patchFile ,inv_type ).records :
18051802 changed = False
@@ -1823,8 +1820,7 @@ def buildPatch(self,log,progress): # buildPatch1:no modFileTops, for type..
18231820 changed = True
18241821 if changed :
18251822 keep (record .fid )
1826- mod = record .fid [0 ]
1827- mod_count [mod ] += 1
1823+ mod_count [record .fid [0 ]] += 1
18281824 self .id_deltas .clear ()
18291825 self ._patchLog (log ,mod_count )
18301826
@@ -2074,7 +2070,7 @@ def buildPatch(self,log,progress): # buildPatch1:no modFileTops, for type..
20742070 if not self .isActive : return
20752071 keep = self .patchFile .getKeeper ()
20762072 merged_deleted = self .id_merged_deleted
2077- mod_count = collections . defaultdict ( int )
2073+ mod_count = Counter ( )
20782074 for rec_type in ('NPC_' ,'CREA' ):
20792075 for record in getattr (self .patchFile ,rec_type ).records :
20802076 fid = record .fid
@@ -2086,8 +2082,7 @@ def buildPatch(self,log,progress): # buildPatch1:no modFileTops, for type..
20862082 changed = True
20872083 if changed :
20882084 keep (record .fid )
2089- mod = record .fid [0 ]
2090- mod_count [mod ] += 1
2085+ mod_count [record .fid [0 ]] += 1
20912086 self .id_merged_deleted .clear ()
20922087 self ._patchLog (log ,mod_count )
20932088
@@ -2235,7 +2230,7 @@ def buildPatch(self,log,progress):# buildPatch0
22352230 modFile = self .patchFile
22362231 keep = self .patchFile .getKeeper ()
22372232 id_full = self .id_full
2238- type_count = collections . defaultdict ( int )
2233+ type_count = Counter ( )
22392234 for act_type in self .activeTypes :
22402235 if act_type not in modFile .tops : continue
22412236 if act_type == 'CELL' :
@@ -2785,7 +2780,7 @@ def buildPatch(self,log,progress):# buildPatch2 !!!!
27852780 for group in self .activeTypes :
27862781 if group not in patchFile .tops : continue
27872782 attrs = self .class_attrs [group ]
2788- count , counts = 0 ,{}
2783+ counts = Counter ()
27892784 for record in patchFile .tops [group ].records :
27902785 fid = record .fid
27912786 itemStats = fid_attr_value .get (fid ,None )
@@ -2795,9 +2790,8 @@ def buildPatch(self,log,progress):# buildPatch2 !!!!
27952790 for attr , value in itemStats .iteritems ():
27962791 setattr (record ,attr ,value )
27972792 keep (fid )
2798- count += 1
2799- counts [fid [0 ]] = 1 + counts .get (fid [0 ],0 )
2800- allCounts .append ((group ,count ,counts ))
2793+ counts [fid [0 ]] += 1
2794+ allCounts .append ((group , sum (counts .values ()), counts ))
28012795 self .fid_attr_value .clear ()
28022796 self ._patchLog (log , allCounts )
28032797
@@ -2911,7 +2905,7 @@ def buildPatch(self,log,progress):# buildPatch3: one type
29112905 id_stat = self .id_stat
29122906 allCounts = []
29132907 spell_attrs = self .spell_attrs
2914- count , counts = 0 ,{}
2908+ counts = Counter ()
29152909 for record in patchFile .SPEL .records :
29162910 fid = record .fid
29172911 spellStats = id_stat .get (fid )
@@ -2921,10 +2915,9 @@ def buildPatch(self,log,progress):# buildPatch3: one type
29212915 for attr ,value in zip (spell_attrs ,spellStats ):
29222916 setattr_deep (record ,attr ,value )
29232917 keep (fid )
2924- count += 1
2925- counts [fid [0 ]] = 1 + counts .get (fid [0 ],0 )
2918+ counts [fid [0 ]] += 1
29262919 self .id_stat .clear ()
2927- allCounts .append (('SPEL' ,count , counts ))
2920+ allCounts .append (('SPEL' , sum ( counts . values ()), counts ))
29282921 self ._patchLog (log , allCounts )
29292922
29302923 def _plog (self , log , allCounts ): self ._plog2 (log , allCounts )
0 commit comments