Lines Matching refs:self

172     def __init__(self, msg=''):
173 self.message = msg
174 Exception.__init__(self, msg)
176 def __repr__(self):
177 return self.message
185 def __init__(self, section):
186 Error.__init__(self, 'No section: %r' % (section,))
187 self.section = section
188 self.args = (section, )
199 def __init__(self, section, source=None, lineno=None):
210 Error.__init__(self, "".join(msg))
211 self.section = section
212 self.source = source
213 self.lineno = lineno
214 self.args = (section, source, lineno)
224 def __init__(self, section, option, source=None, lineno=None):
236 Error.__init__(self, "".join(msg))
237 self.section = section
238 self.option = option
239 self.source = source
240 self.lineno = lineno
241 self.args = (section, option, source, lineno)
247 def __init__(self, option, section):
248 Error.__init__(self, "No option %r in section: %r" %
250 self.option = option
251 self.section = section
252 self.args = (option, section)
258 def __init__(self, option, section, msg):
259 Error.__init__(self, msg)
260 self.option = option
261 self.section = section
262 self.args = (option, section, msg)
268 def __init__(self, option, section, rawval, reference):
272 InterpolationError.__init__(self, option, section, msg)
273 self.reference = reference
274 self.args = (option, section, rawval, reference)
288 def __init__(self, option, section, rawval):
294 InterpolationError.__init__(self, option, section, msg)
295 self.args = (option, section, rawval)
301 def __init__(self, source=None, filename=None):
311 Error.__init__(self, 'Source contains parsing errors: %r' % source)
312 self.source = source
313 self.errors = []
314 self.args = (source, )
317 def filename(self):
324 return self.source
327 def filename(self, value):
334 self.source = value
336 def append(self, lineno, line):
337 self.errors.append((lineno, line))
338 self.message += '\n\t[line %2d]: %s' % (lineno, line)
344 def __init__(self, filename, lineno, line):
346 self,
349 self.source = filename
350 self.lineno = lineno
351 self.line = line
352 self.args = (filename, lineno, line)
364 def before_get(self, parser, section, option, value, defaults):
367 def before_set(self, parser, section, option, value):
370 def before_read(self, parser, section, option, value):
373 def before_write(self, parser, section, option, value):
394 def before_get(self, parser, section, option, value, defaults):
396 self._interpolate_some(parser, option, L, value, section, defaults, 1)
399 def before_set(self, parser, section, option, value):
401 tmp_value = self._KEYCRE.sub('', tmp_value) # valid syntax
407 def _interpolate_some(self, parser, option, accum, rest, section, map,
426 m = self._KEYCRE.match(rest)
438 self._interpolate_some(parser, option, accum, v,
455 def before_get(self, parser, section, option, value, defaults):
457 self._interpolate_some(parser, option, L, value, section, defaults, 1)
460 def before_set(self, parser, section, option, value):
462 tmp_value = self._KEYCRE.sub('', tmp_value) # valid syntax
468 def _interpolate_some(self, parser, option, accum, rest, section, map,
487 m = self._KEYCRE.match(rest)
511 self._interpolate_some(parser, opt, accum, v, sect,
529 def __init__(self, *args, **kwargs):
538 def before_get(self, parser, section, option, value, vars):
544 replace = functools.partial(self._interpolation_replace,
546 value = self._KEYCRE.sub(replace, value)
558 def before_set(self, parser, section, option, value):
611 def __init__(self, defaults=None, dict_type=_default_dict,
618 self._dict = dict_type
619 self._sections = self._dict()
620 self._defaults = self._dict()
621 self._converters = ConverterMapping(self)
622 self._proxies = self._dict()
623 self._proxies[default_section] = SectionProxy(self, default_section)
624 self._delimiters = tuple(delimiters)
626 self._optcre = self.OPTCRE_NV if allow_no_value else self.OPTCRE
630 self._optcre = re.compile(self._OPT_NV_TMPL.format(delim=d),
633 self._optcre = re.compile(self._OPT_TMPL.format(delim=d),
635 self._comment_prefixes = tuple(comment_prefixes or ())
636 self._inline_comment_prefixes = tuple(inline_comment_prefixes or ())
637 self._strict = strict
638 self._allow_no_value = allow_no_value
639 self._empty_lines_in_values = empty_lines_in_values
640 self.default_section=default_section
641 self._interpolation = interpolation
642 if self._interpolation is _UNSET:
643 self._interpolation = self._DEFAULT_INTERPOLATION
644 if self._interpolation is None:
645 self._interpolation = Interpolation()
646 if not isinstance(self._interpolation, Interpolation):
649 f" got an object of type {type(self._interpolation)}"
652 self._converters.update(converters)
654 self._read_defaults(defaults)
656 def defaults(self):
657 return self._defaults
659 def sections(self):
661 # self._sections will never have [DEFAULT] in it
662 return list(self._sections.keys())
664 def add_section(self, section):
670 if section == self.default_section:
673 if section in self._sections:
675 self._sections[section] = self._dict()
676 self._proxies[section] = SectionProxy(self, section)
678 def has_section(self, section):
683 return section in self._sections
685 def options(self, section):
688 opts = self._sections[section].copy()
691 opts.update(self._defaults)
694 def read(self, filenames, encoding=None):
713 self._read(fp, filename)
721 def read_file(self, f, source=None):
734 self._read(f, source)
736 def read_string(self, string, source='<string>'):
739 self.read_file(sfile, source)
741 def read_dict(self, dictionary, source='<dict>'):
758 self.add_section(section)
760 if self._strict and section in elements_added:
764 key = self.optionxform(str(key))
767 if self._strict and (section, key) in elements_added:
770 self.set(section, key, value)
772 def readfp(self, fp, filename=None):
779 self.read_file(fp, source=filename)
781 def get(self, section, option, *, raw=False, vars=None, fallback=_UNSET):
797 d = self._unify_values(section, vars)
803 option = self.optionxform(option)
815 return self._interpolation.before_get(self, section, option, value,
818 def _get(self, section, conv, option, **kwargs):
819 return conv(self.get(section, option, **kwargs))
821 def _get_conv(self, section, option, conv, *, raw=False, vars=None,
824 return self._get(section, conv, option, raw=raw, vars=vars,
832 def getint(self, section, option, *, raw=False, vars=None,
834 return self._get_conv(section, option, int, raw=raw, vars=vars,
837 def getfloat(self, section, option, *, raw=False, vars=None,
839 return self._get_conv(section, option, float, raw=raw, vars=vars,
842 def getboolean(self, section, option, *, raw=False, vars=None,
844 return self._get_conv(section, option, self._convert_to_boolean,
847 def items(self, section=_UNSET, raw=False, vars=None):
860 d = self._defaults.copy()
862 d.update(self._sections[section])
864 if section != self.default_section:
870 d[self.optionxform(key)] = value
871 value_getter = lambda option: self._interpolation.before_get(self,
877 def popitem(self):
884 for key in self.sections():
885 value = self[key]
886 del self[key]
890 def optionxform(self, optionstr):
893 def has_option(self, section, option):
897 if not section or section == self.default_section:
898 option = self.optionxform(option)
899 return option in self._defaults
900 elif section not in self._sections:
903 option = self.optionxform(option)
904 return (option in self._sections[section]
905 or option in self._defaults)
907 def set(self, section, option, value=None):
910 value = self._interpolation.before_set(self, section, option,
912 if not section or section == self.default_section:
913 sectdict = self._defaults
916 sectdict = self._sections[section]
919 sectdict[self.optionxform(option)] = value
921 def write(self, fp, space_around_delimiters=True):
931 d = " {} ".format(self._delimiters[0])
933 d = self._delimiters[0]
934 if self._defaults:
935 self._write_section(fp, self.default_section,
936 self._defaults.items(), d)
937 for section in self._sections:
938 self._write_section(fp, section,
939 self._sections[section].items(), d)
941 def _write_section(self, fp, section_name, section_items, delimiter):
945 value = self._interpolation.before_write(self, section_name, key,
947 if value is not None or not self._allow_no_value:
954 def remove_option(self, section, option):
956 if not section or section == self.default_section:
957 sectdict = self._defaults
960 sectdict = self._sections[section]
963 option = self.optionxform(option)
969 def remove_section(self, section):
971 existed = section in self._sections
973 del self._sections[section]
974 del self._proxies[section]
977 def __getitem__(self, key):
978 if key != self.default_section and not self.has_section(key):
980 return self._proxies[key]
982 def __setitem__(self, key, value):
985 if key in self and self[key] is value:
989 if key == self.default_section:
990 self._defaults.clear()
991 elif key in self._sections:
992 self._sections[key].clear()
993 self.read_dict({key: value})
995 def __delitem__(self, key):
996 if key == self.default_section:
998 if not self.has_section(key):
1000 self.remove_section(key)
1002 def __contains__(self, key):
1003 return key == self.default_section or self.has_section(key)
1005 def __len__(self):
1006 return len(self._sections) + 1 # the default section
1008 def __iter__(self):
1010 return itertools.chain((self.default_section,), self._sections.keys())
1012 def _read(self, fp, fpname):
1039 inline_prefixes = {p: -1 for p in self._inline_comment_prefixes}
1051 for prefix in self._comment_prefixes:
1059 if self._empty_lines_in_values:
1072 first_nonspace = self.NONSPACECRE.search(line)
1081 mo = self.SECTCRE.match(value)
1084 if sectname in self._sections:
1085 if self._strict and sectname in elements_added:
1088 cursect = self._sections[sectname]
1090 elif sectname == self.default_section:
1091 cursect = self._defaults
1093 cursect = self._dict()
1094 self._sections[sectname] = cursect
1095 self._proxies[sectname] = SectionProxy(self, sectname)
1104 mo = self._optcre.match(value)
1108 e = self._handle_error(e, fpname, lineno, line)
1109 optname = self.optionxform(optname.rstrip())
1110 if (self._strict and
1128 e = self._handle_error(e, fpname, lineno, line)
1129 self._join_multiline_values()
1134 def _join_multiline_values(self):
1135 defaults = self.default_section, self._defaults
1137 self._sections.items())
1142 options[name] = self._interpolation.before_read(self,
1146 def _read_defaults(self, defaults):
1150 self._defaults[self.optionxform(key)] = value
1152 def _handle_error(self, exc, fpname, lineno, line):
1158 def _unify_values(self, section, vars):
1165 sectiondict = self._sections[section]
1167 if section != self.default_section:
1175 vardict[self.optionxform(key)] = value
1176 return _ChainMap(vardict, sectiondict, self._defaults)
1178 def _convert_to_boolean(self, value):
1181 if value.lower() not in self.BOOLEAN_STATES:
1183 return self.BOOLEAN_STATES[value.lower()]
1185 def _validate_value_types(self, *, section="", option="", value=""):
1202 if not self._allow_no_value or value:
1207 def converters(self):
1208 return self._converters
1216 def set(self, section, option, value=None):
1219 self._validate_value_types(option=option, value=value)
1222 def add_section(self, section):
1226 self._validate_value_types(section=section)
1229 def _read_defaults(self, defaults):
1236 hold_interpolation = self._interpolation
1237 self._interpolation = Interpolation()
1238 self.read_dict({self.default_section: defaults})
1240 self._interpolation = hold_interpolation
1246 def __init__(self, *args, **kwargs):
1259 def __init__(self, parser, name):
1261 self._parser = parser
1262 self._name = name
1265 getter = functools.partial(self.get, _impl=getattr(parser, key))
1266 setattr(self, key, getter)
1268 def __repr__(self):
1269 return '<Section: {}>'.format(self._name)
1271 def __getitem__(self, key):
1272 if not self._parser.has_option(self._name, key):
1274 return self._parser.get(self._name, key)
1276 def __setitem__(self, key, value):
1277 self._parser._validate_value_types(option=key, value=value)
1278 return self._parser.set(self._name, key, value)
1280 def __delitem__(self, key):
1281 if not (self._parser.has_option(self._name, key) and
1282 self._parser.remove_option(self._name, key)):
1285 def __contains__(self, key):
1286 return self._parser.has_option(self._name, key)
1288 def __len__(self):
1289 return len(self._options())
1291 def __iter__(self):
1292 return self._options().__iter__()
1294 def _options(self):
1295 if self._name != self._parser.default_section:
1296 return self._parser.options(self._name)
1298 return self._parser.defaults()
1301 def parser(self):
1303 return self._parser
1306 def name(self):
1308 return self._name
1310 def get(self, option, fallback=None, *, raw=False, vars=None,
1321 _impl = self._parser.get
1322 return _impl(self._name, option, raw=raw, vars=vars,
1336 def __init__(self, parser):
1337 self._parser = parser
1338 self._data = {}
1339 for getter in dir(self._parser):
1340 m = self.GETTERCRE.match(getter)
1341 if not m or not callable(getattr(self._parser, getter)):
1343 self._data[m.group('name')] = None # See class docstring.
1345 def __getitem__(self, key):
1346 return self._data[key]
1348 def __setitem__(self, key, value):
1356 self._data[key] = value
1357 func = functools.partial(self._parser._get_conv, conv=value)
1359 setattr(self._parser, k, func)
1360 for proxy in self._parser.values():
1364 def __delitem__(self, key):
1369 del self._data[key]
1370 for inst in itertools.chain((self._parser,), self._parser.values()):
1378 def __iter__(self):
1379 return iter(self._data)
1381 def __len__(self):
1382 return len(self._data)