Skip to content

Commit a194b67

Browse files
committed
Remove PersonDict and AttributeDict implementations.
1 parent 6c48e8a commit a194b67

File tree

5 files changed

+22
-68
lines changed

5 files changed

+22
-68
lines changed

sc2reader/factories/plugins/replay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def APMTracker(replay):
123123

124124
@plugin
125125
def SelectionTracker(replay):
126-
debug = replay.opt.debug
126+
debug = replay.opt['debug']
127127
logger = log_utils.get_logger(SelectionTracker)
128128

129129
for person in replay.entities:

sc2reader/factories/sc2factory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def _get_plugins(self, cls):
156156
return plugins
157157

158158
def _get_options(self, cls, **new_options):
159-
options = utils.AttributeDict()
159+
options = dict()
160160
for opt_cls, cls_options in self.options.items():
161161
if issubclass(cls, opt_cls):
162162
options.update(cls_options)
@@ -175,7 +175,7 @@ def _load_resources(self, resources, options=None, **new_options):
175175
yield self._load_resource(resource, options=options)
176176

177177
def load_remote_resource_contents(self, resource, **options):
178-
self.logger.info("Fetching remote resource: "+resource)
178+
self.logger.info("Fetching remote resource: " + resource)
179179
return urlopen(resource).read()
180180

181181
def load_local_resource_contents(self, location, **options):

sc2reader/readers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def __call__(self, data, replay):
297297

298298
# method short cuts, avoid dict lookups
299299
EVENT_DISPATCH = self.EVENT_DISPATCH
300-
debug = replay.opt.debug
300+
debug = replay.opt['debug']
301301
tell = data.tell
302302
read_frames = data.read_frames
303303
read_bits = data.read_bits

sc2reader/resources.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
class Resource(object):
2424
def __init__(self, file_object, filename=None, factory=None, **options):
2525
self.factory = factory
26-
self.opt = utils.AttributeDict(options)
26+
self.opt = options
2727
self.logger = log_utils.get_logger(self.__class__)
2828
self.filename = filename or getattr(file_object, 'name', 'Unavailable')
2929

@@ -137,7 +137,7 @@ class Replay(Resource):
137137

138138
#: A dual key dict mapping player names and numbers to
139139
#: :class:`Player` objects
140-
player = utils.PersonDict()
140+
player = dict()
141141

142142
#: A list of :class:`Observer` objects from the game
143143
observers = list()
@@ -148,7 +148,7 @@ class Replay(Resource):
148148

149149
#: A dual key dict mapping :class:`Person` object to their
150150
#: person id's and names
151-
person = utils.PersonDict()
151+
person = dict()
152152

153153
#: A list of :class:`Person` objects from the game representing
154154
#: only the human players from the :attr:`people` list
@@ -214,11 +214,11 @@ def __init__(self, replay_file, filename=None, load_level=4, engine=sc2reader.en
214214
self.events = list()
215215
self.teams, self.team = list(), dict()
216216

217-
self.player = utils.PersonDict()
218-
self.observer = utils.PersonDict()
219-
self.human = utils.PersonDict()
220-
self.computer = utils.PersonDict()
221-
self.entity = utils.PersonDict()
217+
self.player = dict()
218+
self.observer = dict()
219+
self.human = dict()
220+
self.computer = dict()
221+
self.entity = dict()
222222

223223
self.players = list()
224224
self.observers = list() # Unordered list of Observer
@@ -599,7 +599,7 @@ def _read_data(self, data_file, reader):
599599
data = utils.extract_data_file(data_file, self.archive)
600600
if data:
601601
self.raw_data[data_file] = reader(data, self)
602-
elif self.opt.debug and data_file not in ['replay.message.events', 'replay.tracker.events']:
602+
elif self.opt['debug'] and data_file not in ['replay.message.events', 'replay.tracker.events']:
603603
raise ValueError("{0} not found in archive".format(data_file))
604604

605605
def __getstate__(self):
@@ -862,7 +862,7 @@ def load_translations(self):
862862
self.lang_sheets = dict()
863863
self.translations = dict()
864864
for lang, files in self.localization_urls.items():
865-
if lang != self.opt.lang:
865+
if lang != self.opt['lang']:
866866
continue
867867

868868
sheets = list()
@@ -873,17 +873,17 @@ def load_translations(self):
873873
for uid, (sheet, item) in self.id_map.items():
874874
if sheet < len(sheets) and item in sheets[sheet]:
875875
translation[uid] = sheets[sheet][item]
876-
elif self.opt.debug:
876+
elif self.opt['debug']:
877877
msg = "No {0} translation for sheet {1}, item {2}"
878-
raise SC2ReaderLocalizationError(msg.format(self.opt.lang, sheet, item))
878+
raise SC2ReaderLocalizationError(msg.format(self.opt['lang'], sheet, item))
879879
else:
880880
translation[uid] = "Unknown"
881881

882882
self.lang_sheets[lang] = sheets
883883
self.translations[lang] = translation
884884

885885
def load_map_info(self):
886-
map_strings = self.lang_sheets[self.opt.lang][-1]
886+
map_strings = self.lang_sheets[self.opt['lang']][-1]
887887
self.map_name = map_strings[1]
888888
self.map_description = map_strings[2]
889889
self.map_tileset = map_strings[3]
@@ -942,7 +942,7 @@ def use_property(prop, player=None):
942942
activated[(prop.id, player)] = use
943943
return use
944944

945-
translation = self.translations[self.opt.lang]
945+
translation = self.translations[self.opt['lang']]
946946
for uid, prop in properties.items():
947947
name = translation.get(uid, "Unknown")
948948
if prop.is_lobby:
@@ -956,7 +956,7 @@ def use_property(prop, player=None):
956956
self.player_settings[index][name] = translation[(uid, value)]
957957

958958
def load_player_stats(self):
959-
translation = self.translations[self.opt.lang]
959+
translation = self.translations[self.opt['lang']]
960960

961961
stat_items = sum([p[0] for p in self.parts[3:]], [])
962962

sc2reader/utils.py

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -48,57 +48,11 @@ def __str__(self):
4848
return self.url
4949

5050

51-
class PersonDict(dict):
52-
"""
53-
Deprecated!
54-
55-
Supports lookup on both the player name and player id
56-
57-
::
58-
59-
person = PersonDict()
60-
person[1] = Player(1,"ShadesofGray")
61-
me = person.name("ShadesofGray")
62-
del person[me.pid]
63-
64-
Delete is supported on the player id only
65-
"""
66-
def __init__(self):
67-
super(PersonDict, self).__init__()
68-
self._key_map = dict()
69-
70-
def name(self, player_name):
71-
""" deprecated because it is possible for multiple players to have the same name. """
72-
return self[self._key_map[player_name]]
73-
74-
def __setitem__(self, key, value):
75-
self._key_map[value.name] = key
76-
super(PersonDict, self).__setitem__(key, value)
77-
78-
7951
def windows_to_unix(windows_time):
8052
# This windows timestamp measures the number of 100 nanosecond periods since
8153
# January 1st, 1601. First we subtract the number of nanosecond periods from
8254
# 1601-1970, then we divide by 10^7 to bring it back to seconds.
83-
return int((windows_time-116444735995904000)/10**7)
84-
85-
86-
class AttributeDict(dict):
87-
"""
88-
Support access to dictionary items via the dot syntax as though they
89-
were class attributes. Also support setting new keys via dot syntax.
90-
"""
91-
def __getattr__(self, name):
92-
try:
93-
return self[name]
94-
except KeyError:
95-
raise AttributeError('No such attribute {0}'.format(name))
96-
97-
def __setattr__(self, name, value):
98-
self[name] = value
99-
100-
def copy(self):
101-
return AttributeDict(self.items())
55+
return int((windows_time - 116444735995904000) / 10 ** 7)
10256

10357

10458
@loggable
@@ -252,12 +206,12 @@ class Length(timedelta):
252206
@property
253207
def hours(self):
254208
""" The number of hours in represented. """
255-
return self.seconds//3600
209+
return self.seconds // 3600
256210

257211
@property
258212
def mins(self):
259213
""" The number of minutes in excess of the hours. """
260-
return self.seconds//60 % 60
214+
return self.seconds // 60 % 60
261215

262216
@property
263217
def secs(self):

0 commit comments

Comments
 (0)