|
8 | 8 |
|
9 | 9 | __version__ = "0.3.0" |
10 | 10 |
|
11 | | -#Library configuration and constants |
12 | | -FULL = 1 |
13 | | -PARTIAL = 2 |
14 | | -CUSTOM = 3 |
15 | | - |
16 | | -FILES_FULL = ['replay.initData','replay.details','replay.attributes.events','replay.message.events','replay.game.events'] |
17 | | -FILES_PARTIAL = ['replay.initData','replay.details','replay.attributes.events','replay.message.events'] |
| 11 | +FILES = { |
| 12 | + "FULL": [ |
| 13 | + 'replay.initData', |
| 14 | + 'replay.details', |
| 15 | + 'replay.attributes.events', |
| 16 | + 'replay.message.events', |
| 17 | + 'replay.game.events' |
| 18 | + ], |
| 19 | + |
| 20 | + "PARTIAL": [ |
| 21 | + 'replay.initData', |
| 22 | + 'replay.details', |
| 23 | + 'replay.attributes.events', |
| 24 | + 'replay.message.events' |
| 25 | + ], |
| 26 | +} |
18 | 27 |
|
19 | | -PROCESSORS_FULL = [ |
| 28 | +PROCESSORS = { |
| 29 | + "FULL": [ |
20 | 30 | PeopleProcessor(), |
21 | 31 | AttributeProcessor(), |
22 | 32 | TeamsProcessor(), |
|
25 | 35 | EventProcessor(), |
26 | 36 | ApmProcessor(), |
27 | 37 | ResultsProcessor() |
28 | | - ] |
| 38 | + ], |
29 | 39 |
|
30 | | -PROCESSORS_PARTIAL = [ |
| 40 | + "PARTIAL": [ |
31 | 41 | PeopleProcessor(), |
32 | 42 | AttributeProcessor(), |
33 | 43 | TeamsProcessor(), |
34 | 44 | MessageProcessor(), |
35 | 45 | RecorderProcessor(), |
36 | | - ] |
| 46 | + ], |
| 47 | +} |
37 | 48 |
|
38 | 49 | class ReaderMap(object): |
39 | 50 | def __getitem__(self,key): |
@@ -97,28 +108,21 @@ def read_header(file): |
97 | 108 | return data[1],data[3] |
98 | 109 |
|
99 | 110 | class SC2Reader(object): |
100 | | - def __init__(self, parse=FULL, directory="", processors=[], debug=False, files=None): |
101 | | - #Check that arguments are consistent with expectations up front |
102 | | - #Easier to debug issues this way |
103 | | - if parse == FULL: |
104 | | - files = FILES_FULL |
105 | | - processors = PROCESSORS_FULL + processors |
106 | | - elif parse == PARTIAL: |
107 | | - files = FILES_PARTIAL |
108 | | - processors = PROCESSORS_PARTIAL + processors |
109 | | - elif parse == CUSTOM: |
110 | | - if not files: |
111 | | - raise ValueError("Custom parsing requires specification the files arguments") |
112 | | - else: |
113 | | - raise ValueError("parse must be either FULL, PARTIAL, or CUSTOM") |
| 111 | + def __init__(self, parse="FULL", directory="", processors=[], debug=False, files=None): |
| 112 | + #Sanitize the parse level |
| 113 | + parse = parse.upper() |
| 114 | + if parse not in ("FULL","PARTIAL","CUSTOM"): |
| 115 | + raise ValueError("Unrecognized parse argument `%s`" % parse) |
114 | 116 |
|
115 | | - #Update the class configuration |
| 117 | + #get our defaults and save preferences |
| 118 | + files = FILES.get(parse,files) |
| 119 | + processors = PROCESSORS.get(parse,processors) |
116 | 120 | self.__dict__.update(locals()) |
117 | 121 |
|
118 | 122 | def read(self, location): |
119 | | - #account for the directory option |
120 | | - if self.directory: location = os.path.join(self.directory,location) |
121 | | - |
| 123 | + #Sanitize the location provided (accounting for directory option) |
| 124 | + if self.directory: |
| 125 | + location = os.path.join(self.directory,location) |
122 | 126 | if not os.path.exists(location): |
123 | 127 | raise ValueError("Location must exist") |
124 | 128 |
|
|
0 commit comments