Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: chainedconfigparser.py

Issue 29743581: Issue 6552 - Support arbitrary manifest values (Closed) Base URL: https://hg.adblockplus.org/buildtools/file/a3db4a1a49e8
Left Patch Set: Created April 19, 2018, 11:05 a.m.
Right Patch Set: Created April 19, 2018, 11:42 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | packagerChrome.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This Source Code Form is subject to the terms of the Mozilla Public 1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 4
5 import os 5 import os
6 import io 6 import io
7 import ConfigParser 7 import ConfigParser
8 from StringIO import StringIO 8 from StringIO import StringIO
9 9
10 10
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 def option_source(self, section, option): 151 def option_source(self, section, option):
152 option = self.optionxform(option) 152 option = self.optionxform(option)
153 try: 153 try:
154 return self._origin[(section, option)] 154 return self._origin[(section, option)]
155 except KeyError: 155 except KeyError:
156 if not self.has_section(section): 156 if not self.has_section(section):
157 raise ConfigParser.NoSectionError(section) 157 raise ConfigParser.NoSectionError(section)
158 raise ConfigParser.NoOptionError(option, section) 158 raise ConfigParser.NoOptionError(option, section)
159 159
160 def section_as_dict(self, section, base): 160 def serialize_section_if_present(self, section, base):
Vasily Kuznetsov 2018/04/19 14:40:10 What this method does seems more like parsing than
Sebastian Noack 2018/04/19 15:02:59 In the end it gets serialized (as JSON). But you m
161 """Parse a given section into a dictionary. 161 """Serialize a given section as a dictionary into `base`.
162 162
163 Parse arbitrary key/value pairs from 'section' of the current 163 Parse arbitrary key/value pairs from 'section' of the current
164 configuration into a dictionary and deep merge it into `base`. 164 configuration into a dictionary and deep merge it into `base`.
165 165
166 The following rules need to be considered: 166 The following rules need to be considered:
167 167
168 * An option's key may be declared as a series of nested dictionary keys, 168 * An option's key may be declared as a series of nested dictionary keys,
169 seperated by '.'. 169 seperated by '.'.
170 * Declaring an option's value in a new line (even if only one is given) 170 * Declaring an option's value in a new line (even if only one is given)
171 will define the option's value as a list. 171 will define the option's value as a list.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 try: 203 try:
204 return int(v) 204 return int(v)
205 except ValueError: 205 except ValueError:
206 return float(v) 206 return float(v)
207 if v == 'bool:true': 207 if v == 'bool:true':
208 return True 208 return True
209 if v == 'bool:false': 209 if v == 'bool:false':
210 return False 210 return False
211 return v 211 return v
212 212
213 for k, v in self.items(section): 213 if self.has_section(section):
214 parents = k.split('.') 214 for k, v in self.items(section):
215 tail = parents.pop() 215 parents = k.split('.')
216 current = base 216 tail = parents.pop()
217 for name in parents: 217 current = base
218 current = base.setdefault(name, {}) 218 for name in parents:
219 219 current = base.setdefault(name, {})
220 if '\n' in v: 220
221 current[tail] = [parse_value(x) for x in v.splitlines() if x] 221 if '\n' in v:
222 else: 222 current[tail] = [parse_value(x) for x in v.splitlines() if x ]
223 current[tail] = parse_value(v) 223 else:
224 224 current[tail] = parse_value(v)
225 return base
226 225
227 def readfp(self, fp, filename=None): 226 def readfp(self, fp, filename=None):
228 raise NotImplementedError 227 raise NotImplementedError
229 228
230 def set(self, section, option, value=None): 229 def set(self, section, option, value=None):
231 raise NotImplementedError 230 raise NotImplementedError
232 231
233 def add_section(self, section): 232 def add_section(self, section):
234 raise NotImplementedError 233 raise NotImplementedError
235 234
236 def remove_option(self, section, option): 235 def remove_option(self, section, option):
237 raise NotImplementedError 236 raise NotImplementedError
238 237
239 def remove_section(self, section): 238 def remove_section(self, section):
240 raise NotImplementedError 239 raise NotImplementedError
LEFTRIGHT
« no previous file | packagerChrome.py » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld