19
19
inline_comment_prefixes=None, strict=True,
20
20
empty_lines_in_values=True, default_section='DEFAULT',
21
21
interpolation=<unset>, converters=<unset>):
22
- Create the parser. When `defaults' is given, it is initialized into the
22
+
23
+ Create the parser. When `defaults` is given, it is initialized into the
23
24
dictionary or intrinsic defaults. The keys must be strings, the values
24
25
must be appropriate for %()s string interpolation.
25
26
26
- When `dict_type' is given, it will be used to create the dictionary
27
+ When `dict_type` is given, it will be used to create the dictionary
27
28
objects for the list of sections, for the options within a section, and
28
29
for the default values.
29
30
30
- When `delimiters' is given, it will be used as the set of substrings
31
+ When `delimiters` is given, it will be used as the set of substrings
31
32
that divide keys from values.
32
33
33
- When `comment_prefixes' is given, it will be used as the set of
34
+ When `comment_prefixes` is given, it will be used as the set of
34
35
substrings that prefix comments in empty lines. Comments can be
35
36
indented.
36
37
37
- When `inline_comment_prefixes' is given, it will be used as the set of
38
+ When `inline_comment_prefixes` is given, it will be used as the set of
38
39
substrings that prefix comments in non-empty lines.
39
40
40
41
When `strict` is True, the parser won't allow for any section or option
41
42
duplicates while reading from a single source (file, string or
42
43
dictionary). Default is True.
43
44
44
- When `empty_lines_in_values' is False (default: True), each empty line
45
+ When `empty_lines_in_values` is False (default: True), each empty line
45
46
marks the end of an option. Otherwise, internal empty lines of
46
47
a multiline option are kept as part of the value.
47
48
48
- When `allow_no_value' is True (default: False), options without
49
+ When `allow_no_value` is True (default: False), options without
49
50
values are accepted; the value presented for these is None.
50
51
51
- When `default_section' is given, the name of the special section is
52
+ When `default_section` is given, the name of the special section is
52
53
named accordingly. By default it is called ``"DEFAULT"`` but this can
53
54
be customized to point to any other valid section name. Its current
54
55
value can be retrieved using the ``parser_instance.default_section``
87
88
read_file(f, filename=None)
88
89
Read and parse one configuration file, given as a file object.
89
90
The filename defaults to f.name; it is only used in error
90
- messages (if f has no `name' attribute, the string `<???>' is used).
91
+ messages (if f has no `name` attribute, the string `<???>` is used).
91
92
92
93
read_string(string)
93
94
Read configuration from a given string.
103
104
Return a string value for the named option. All % interpolations are
104
105
expanded in the return values, based on the defaults passed into the
105
106
constructor and the DEFAULT section. Additional substitutions may be
106
- provided using the `vars' argument, which must be a dictionary whose
107
- contents override any pre-existing defaults. If `option' is a key in
108
- `vars' , the value from `vars' is used.
107
+ provided using the `vars` argument, which must be a dictionary whose
108
+ contents override any pre-existing defaults. If `option` is a key in
109
+ `vars` , the value from `vars` is used.
109
110
110
111
getint(section, options, raw=False, vars=None, fallback=_UNSET)
111
112
Like get(), but convert value to an integer.
134
135
135
136
write(fp, space_around_delimiters=True)
136
137
Write the configuration state in .ini format. If
137
- `space_around_delimiters' is True (the default), delimiters
138
+ `space_around_delimiters` is True (the default), delimiters
138
139
between keys and values are surrounded by spaces.
139
140
"""
140
141
@@ -352,7 +353,7 @@ def __init__(self, filename, lineno, line):
352
353
353
354
354
355
# Used in parser getters to indicate the default behaviour when a specific
355
- # option is not found it to raise an exception. Created to enable `None' as
356
+ # option is not found it to raise an exception. Created to enable `None` as
356
357
# a valid fallback value.
357
358
_UNSET = object ()
358
359
@@ -386,7 +387,7 @@ class BasicInterpolation(Interpolation):
386
387
would resolve the "%(dir)s" to the value of dir. All reference
387
388
expansions are done late, on demand. If a user needs to use a bare % in
388
389
a configuration file, she can escape it by writing %%. Other % usage
389
- is considered a user error and raises `InterpolationSyntaxError' ."""
390
+ is considered a user error and raises `InterpolationSyntaxError` ."""
390
391
391
392
_KEYCRE = re .compile (r"%\(([^)]+)\)s" )
392
393
@@ -447,7 +448,7 @@ def _interpolate_some(self, parser, option, accum, rest, section, map,
447
448
448
449
class ExtendedInterpolation (Interpolation ):
449
450
"""Advanced variant of interpolation, supports the syntax used by
450
- `zc.buildout' . Enables interpolation between sections."""
451
+ `zc.buildout` . Enables interpolation between sections."""
451
452
452
453
_KEYCRE = re .compile (r"\$\{([^}]+)\}" )
453
454
@@ -706,10 +707,10 @@ def read(self, filenames, encoding=None):
706
707
def read_file (self , f , source = None ):
707
708
"""Like read() but the argument must be a file-like object.
708
709
709
- The `f' argument must be iterable, returning one line at a time.
710
- Optional second argument is the `source' specifying the name of the
711
- file being read. If not given, it is taken from f.name. If `f' has no
712
- `name' attribute, `<???>' is used.
710
+ The `f` argument must be iterable, returning one line at a time.
711
+ Optional second argument is the `source` specifying the name of the
712
+ file being read. If not given, it is taken from f.name. If `f` has no
713
+ `name` attribute, `<???>` is used.
713
714
"""
714
715
if source is None :
715
716
try :
@@ -733,7 +734,7 @@ def read_dict(self, dictionary, source='<dict>'):
733
734
All types held in the dictionary are converted to strings during
734
735
reading, including section names, option names and keys.
735
736
736
- Optional second argument is the `source' specifying the name of the
737
+ Optional second argument is the `source` specifying the name of the
737
738
dictionary being read.
738
739
"""
739
740
elements_added = set ()
@@ -766,15 +767,15 @@ def readfp(self, fp, filename=None):
766
767
def get (self , section , option , * , raw = False , vars = None , fallback = _UNSET ):
767
768
"""Get an option value for a given section.
768
769
769
- If `vars' is provided, it must be a dictionary. The option is looked up
770
- in `vars' (if provided), `section' , and in `DEFAULTSECT' in that order.
771
- If the key is not found and `fallback' is provided, it is used as
772
- a fallback value. `None' can be provided as a `fallback' value.
770
+ If `vars` is provided, it must be a dictionary. The option is looked up
771
+ in `vars` (if provided), `section` , and in `DEFAULTSECT` in that order.
772
+ If the key is not found and `fallback` is provided, it is used as
773
+ a fallback value. `None` can be provided as a `fallback` value.
773
774
774
- If interpolation is enabled and the optional argument `raw' is False,
775
+ If interpolation is enabled and the optional argument `raw` is False,
775
776
all interpolations are expanded in the return values.
776
777
777
- Arguments `raw' , `vars' , and `fallback' are keyword only.
778
+ Arguments `raw` , `vars` , and `fallback` are keyword only.
778
779
779
780
The section DEFAULT is special.
780
781
"""
@@ -834,8 +835,8 @@ def items(self, section=_UNSET, raw=False, vars=None):
834
835
835
836
All % interpolations are expanded in the return values, based on the
836
837
defaults passed into the constructor, unless the optional argument
837
- `raw' is true. Additional substitutions may be provided using the
838
- `vars' argument, which must be a dictionary whose contents overrides
838
+ `raw` is true. Additional substitutions may be provided using the
839
+ `vars` argument, which must be a dictionary whose contents overrides
839
840
any pre-existing defaults.
840
841
841
842
The section DEFAULT is special.
@@ -877,8 +878,8 @@ def optionxform(self, optionstr):
877
878
878
879
def has_option (self , section , option ):
879
880
"""Check for the existence of a given option in a given section.
880
- If the specified `section' is None or an empty string, DEFAULT is
881
- assumed. If the specified `section' does not exist, returns False."""
881
+ If the specified `section` is None or an empty string, DEFAULT is
882
+ assumed. If the specified `section` does not exist, returns False."""
882
883
if not section or section == self .default_section :
883
884
option = self .optionxform (option )
884
885
return option in self ._defaults
@@ -906,7 +907,7 @@ def set(self, section, option, value=None):
906
907
def write (self , fp , space_around_delimiters = True ):
907
908
"""Write an .ini-format representation of the configuration state.
908
909
909
- If `space_around_delimiters' is True (the default), delimiters
910
+ If `space_around_delimiters` is True (the default), delimiters
910
911
between keys and values are surrounded by spaces.
911
912
912
913
Please note that comments in the original configuration file are not
@@ -924,7 +925,7 @@ def write(self, fp, space_around_delimiters=True):
924
925
self ._sections [section ].items (), d )
925
926
926
927
def _write_section (self , fp , section_name , section_items , delimiter ):
927
- """Write a single section to the specified `fp' ."""
928
+ """Write a single section to the specified `fp` ."""
928
929
fp .write ("[{}]\n " .format (section_name ))
929
930
for key , value in section_items :
930
931
value = self ._interpolation .before_write (self , section_name , key ,
@@ -998,16 +999,16 @@ def _read(self, fp, fpname):
998
999
"""Parse a sectioned configuration file.
999
1000
1000
1001
Each section in a configuration file contains a header, indicated by
1001
- a name in square brackets (`[]' ), plus key/value options, indicated by
1002
- `name' and `value' delimited with a specific substring (`=' or `:' by
1002
+ a name in square brackets (`[]` ), plus key/value options, indicated by
1003
+ `name` and `value` delimited with a specific substring (`=` or `:` by
1003
1004
default).
1004
1005
1005
1006
Values can span multiple lines, as long as they are indented deeper
1006
1007
than the first line of the value. Depending on the parser's mode, blank
1007
1008
lines may be treated as parts of multiline values or ignored.
1008
1009
1009
1010
Configuration files may include comments, prefixed by specific
1010
- characters (`#' and `;' by default). Comments may appear on their own
1011
+ characters (`#` and `;` by default). Comments may appear on their own
1011
1012
in an otherwise empty line or may be entered in lines holding values or
1012
1013
section names. Please note that comments get stripped off when reading configuration files.
1013
1014
"""
0 commit comments