Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
26d513cf
Commit
26d513cf
authored
Nov 10, 2010
by
Łukasz Langa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #5412: extend configparser to support mapping access
parent
47f637ce
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
1086 additions
and
433 deletions
+1086
-433
Doc/library/configparser.rst
Doc/library/configparser.rst
+759
-288
Lib/configparser.py
Lib/configparser.py
+175
-66
Lib/logging/config.py
Lib/logging/config.py
+25
-45
Lib/test/test_cfgparser.py
Lib/test/test_cfgparser.py
+127
-34
No files found.
Doc/library/configparser.rst
View file @
26d513cf
This diff is collapsed.
Click to expand it.
Lib/configparser.py
View file @
26d513cf
This diff is collapsed.
Click to expand it.
Lib/logging/config.py
View file @
26d513cf
...
...
@@ -103,7 +103,7 @@ def _encoded(s):
def
_create_formatters
(
cp
):
"""Create and return formatters"""
flist
=
cp
.
get
(
"formatters"
,
"keys"
)
flist
=
cp
[
"formatters"
][
"keys"
]
if
not
len
(
flist
):
return
{}
flist
=
flist
.
split
(
","
)
...
...
@@ -111,20 +111,12 @@ def _create_formatters(cp):
formatters
=
{}
for
form
in
flist
:
sectname
=
"formatter_%s"
%
form
opts
=
cp
.
options
(
sectname
)
if
"format"
in
opts
:
fs
=
cp
.
get
(
sectname
,
"format"
,
1
)
else
:
fs
=
None
if
"datefmt"
in
opts
:
dfs
=
cp
.
get
(
sectname
,
"datefmt"
,
1
)
else
:
dfs
=
None
fs
=
cp
.
get
(
sectname
,
"format"
,
raw
=
True
,
fallback
=
None
)
dfs
=
cp
.
get
(
sectname
,
"datefmt"
,
raw
=
True
,
fallback
=
None
)
c
=
logging
.
Formatter
if
"class"
in
opts
:
class_name
=
cp
.
get
(
sectname
,
"class"
)
if
class_name
:
c
=
_resolve
(
class_name
)
class_name
=
cp
[
sectname
].
get
(
"class"
)
if
class_name
:
c
=
_resolve
(
class_name
)
f
=
c
(
fs
,
dfs
)
formatters
[
form
]
=
f
return
formatters
...
...
@@ -132,7 +124,7 @@ def _create_formatters(cp):
def
_install_handlers
(
cp
,
formatters
):
"""Install and return handlers"""
hlist
=
cp
.
get
(
"handlers"
,
"keys"
)
hlist
=
cp
[
"handlers"
][
"keys"
]
if
not
len
(
hlist
):
return
{}
hlist
=
hlist
.
split
(
","
)
...
...
@@ -140,30 +132,23 @@ def _install_handlers(cp, formatters):
handlers
=
{}
fixups
=
[]
#for inter-handler references
for
hand
in
hlist
:
sectname
=
"handler_%s"
%
hand
klass
=
cp
.
get
(
sectname
,
"class"
)
opts
=
cp
.
options
(
sectname
)
if
"formatter"
in
opts
:
fmt
=
cp
.
get
(
sectname
,
"formatter"
)
else
:
fmt
=
""
section
=
cp
[
"handler_%s"
%
hand
]
klass
=
section
[
"class"
]
fmt
=
section
.
get
(
"formatter"
,
""
)
try
:
klass
=
eval
(
klass
,
vars
(
logging
))
except
(
AttributeError
,
NameError
):
klass
=
_resolve
(
klass
)
args
=
cp
.
get
(
sectname
,
"args"
)
args
=
section
[
"args"
]
args
=
eval
(
args
,
vars
(
logging
))
h
=
klass
(
*
args
)
if
"level"
in
opts
:
level
=
cp
.
get
(
sectname
,
"level"
)
if
"level"
in
section
:
level
=
section
[
"level"
]
h
.
setLevel
(
logging
.
_levelNames
[
level
])
if
len
(
fmt
):
h
.
setFormatter
(
formatters
[
fmt
])
if
issubclass
(
klass
,
logging
.
handlers
.
MemoryHandler
):
if
"target"
in
opts
:
target
=
cp
.
get
(
sectname
,
"target"
)
else
:
target
=
""
target
=
section
.
get
(
"target"
,
""
)
if
len
(
target
):
#the target handler may not be loaded yet, so keep for later...
fixups
.
append
((
h
,
target
))
handlers
[
hand
]
=
h
...
...
@@ -197,20 +182,19 @@ def _install_loggers(cp, handlers, disable_existing):
"""Create and install loggers"""
# configure the root first
llist
=
cp
.
get
(
"loggers"
,
"keys"
)
llist
=
cp
[
"loggers"
][
"keys"
]
llist
=
llist
.
split
(
","
)
llist
=
list
(
map
(
lambda
x
:
x
.
strip
(),
llist
))
llist
.
remove
(
"root"
)
sect
name
=
"logger_root"
sect
ion
=
cp
[
"logger_root"
]
root
=
logging
.
root
log
=
root
opts
=
cp
.
options
(
sectname
)
if
"level"
in
opts
:
level
=
cp
.
get
(
sectname
,
"level"
)
if
"level"
in
section
:
level
=
section
[
"level"
]
log
.
setLevel
(
logging
.
_levelNames
[
level
])
for
h
in
root
.
handlers
[:]:
root
.
removeHandler
(
h
)
hlist
=
cp
.
get
(
sectname
,
"handlers"
)
hlist
=
section
[
"handlers"
]
if
len
(
hlist
):
hlist
=
hlist
.
split
(
","
)
hlist
=
_strip_spaces
(
hlist
)
...
...
@@ -237,13 +221,9 @@ def _install_loggers(cp, handlers, disable_existing):
child_loggers
=
[]
#now set up the new ones...
for
log
in
llist
:
sectname
=
"logger_%s"
%
log
qn
=
cp
.
get
(
sectname
,
"qualname"
)
opts
=
cp
.
options
(
sectname
)
if
"propagate"
in
opts
:
propagate
=
cp
.
getint
(
sectname
,
"propagate"
)
else
:
propagate
=
1
section
=
cp
[
"logger_%s"
%
log
]
qn
=
section
[
"qualname"
]
propagate
=
section
.
getint
(
"propagate"
,
fallback
=
1
)
logger
=
logging
.
getLogger
(
qn
)
if
qn
in
existing
:
i
=
existing
.
index
(
qn
)
...
...
@@ -255,14 +235,14 @@ def _install_loggers(cp, handlers, disable_existing):
child_loggers
.
append
(
existing
[
i
])
i
=
i
+
1
existing
.
remove
(
qn
)
if
"level"
in
opts
:
level
=
cp
.
get
(
sectname
,
"level"
)
if
"level"
in
section
:
level
=
section
[
"level"
]
logger
.
setLevel
(
logging
.
_levelNames
[
level
])
for
h
in
logger
.
handlers
[:]:
logger
.
removeHandler
(
h
)
logger
.
propagate
=
propagate
logger
.
disabled
=
0
hlist
=
cp
.
get
(
sectname
,
"handlers"
)
hlist
=
section
[
"handlers"
]
if
len
(
hlist
):
hlist
=
hlist
.
split
(
","
)
hlist
=
_strip_spaces
(
hlist
)
...
...
Lib/test/test_cfgparser.py
View file @
26d513cf
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment