Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
a00bcac0
Kaydet (Commit)
a00bcac0
authored
Ara 03, 2006
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Patch #1371075: Make ConfigParser accept optional dict type
for ordering, sorting, etc.
üst
046c4d13
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
11 deletions
+68
-11
libcfgparser.tex
Doc/lib/libcfgparser.tex
+12
-3
ConfigParser.py
Lib/ConfigParser.py
+8
-7
test_cfgparser.py
Lib/test/test_cfgparser.py
+45
-1
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/lib/libcfgparser.tex
Dosyayı görüntüle @
a00bcac0
...
@@ -48,11 +48,20 @@ Default values can be specified by passing them into the
...
@@ -48,11 +48,20 @@ Default values can be specified by passing them into the
may be passed into the
\method
{
get()
}
method which will override all
may be passed into the
\method
{
get()
}
method which will override all
others.
others.
\begin{classdesc}
{
RawConfigParser
}{
\optional
{
defaults
}}
Sections are normally stored in a builtin dictionary. An alternative
dictionary type can be passed to the
\class
{
ConfigParser
}
constructor.
For example, if a dictionary type is passed that sorts is keys,
the sections will be sorted on write-back, as will be the keys within
each section.
\begin{classdesc}
{
RawConfigParser
}{
\optional
{
defaults
\optional
{
, dict
_
type
}}}
The basic configuration object. When
\var
{
defaults
}
is given, it is
The basic configuration object. When
\var
{
defaults
}
is given, it is
initialized into the dictionary of intrinsic defaults. This class
initialized into the dictionary of intrinsic defaults. When
\var
{
dict
_
type
}
does not support the magical interpolation behavior.
is given, it will be used to create the dictionary objects for the list
of sections, for the options within a section, and for the default values.
This class does not support the magical interpolation behavior.
\versionadded
{
2.3
}
\versionadded
{
2.3
}
\versionchanged
{
\var
{
dict
_
type
}
was added
}
[2.6]
\end{classdesc}
\end{classdesc}
\begin{classdesc}
{
ConfigParser
}{
\optional
{
defaults
}}
\begin{classdesc}
{
ConfigParser
}{
\optional
{
defaults
}}
...
...
Lib/ConfigParser.py
Dosyayı görüntüle @
a00bcac0
...
@@ -199,11 +199,11 @@ class MissingSectionHeaderError(ParsingError):
...
@@ -199,11 +199,11 @@ class MissingSectionHeaderError(ParsingError):
self
.
line
=
line
self
.
line
=
line
class
RawConfigParser
:
class
RawConfigParser
:
def
__init__
(
self
,
defaults
=
None
):
def
__init__
(
self
,
defaults
=
None
,
dict_type
=
dict
):
self
.
_sections
=
{}
self
.
_dict
=
dict_type
self
.
_defaults
=
{}
self
.
_sections
=
self
.
_dict
()
self
.
_defaults
=
self
.
_dict
()
if
defaults
:
if
defaults
:
for
key
,
value
in
defaults
.
items
():
for
key
,
value
in
defaults
.
items
():
self
.
_defaults
[
self
.
optionxform
(
key
)]
=
value
self
.
_defaults
[
self
.
optionxform
(
key
)]
=
value
...
@@ -224,7 +224,7 @@ class RawConfigParser:
...
@@ -224,7 +224,7 @@ class RawConfigParser:
"""
"""
if
section
in
self
.
_sections
:
if
section
in
self
.
_sections
:
raise
DuplicateSectionError
(
section
)
raise
DuplicateSectionError
(
section
)
self
.
_sections
[
section
]
=
{}
self
.
_sections
[
section
]
=
self
.
_dict
()
def
has_section
(
self
,
section
):
def
has_section
(
self
,
section
):
"""Indicate whether the named section is present in the configuration.
"""Indicate whether the named section is present in the configuration.
...
@@ -307,7 +307,7 @@ class RawConfigParser:
...
@@ -307,7 +307,7 @@ class RawConfigParser:
except
KeyError
:
except
KeyError
:
if
section
!=
DEFAULTSECT
:
if
section
!=
DEFAULTSECT
:
raise
NoSectionError
(
section
)
raise
NoSectionError
(
section
)
d2
=
{}
d2
=
self
.
_dict
()
d
=
self
.
_defaults
.
copy
()
d
=
self
.
_defaults
.
copy
()
d
.
update
(
d2
)
d
.
update
(
d2
)
if
"__name__"
in
d
:
if
"__name__"
in
d
:
...
@@ -453,7 +453,8 @@ class RawConfigParser:
...
@@ -453,7 +453,8 @@ class RawConfigParser:
elif
sectname
==
DEFAULTSECT
:
elif
sectname
==
DEFAULTSECT
:
cursect
=
self
.
_defaults
cursect
=
self
.
_defaults
else
:
else
:
cursect
=
{
'__name__'
:
sectname
}
cursect
=
self
.
_dict
()
cursect
[
'__name__'
]
=
sectname
self
.
_sections
[
sectname
]
=
cursect
self
.
_sections
[
sectname
]
=
cursect
# So sections can't start with a continuation line
# So sections can't start with a continuation line
optname
=
None
optname
=
None
...
...
Lib/test/test_cfgparser.py
Dosyayı görüntüle @
a00bcac0
import
ConfigParser
import
ConfigParser
import
StringIO
import
StringIO
import
unittest
import
unittest
import
UserDict
from
test
import
test_support
from
test
import
test_support
class
SortedDict
(
UserDict
.
UserDict
):
def
items
(
self
):
result
=
self
.
data
.
items
()
result
.
sort
()
return
result
def
keys
(
self
):
result
=
self
.
data
.
keys
()
result
.
sort
()
return
result
def
values
(
self
):
result
=
self
.
items
()
return
[
i
[
1
]
for
i
in
values
]
def
iteritems
(
self
):
return
iter
(
self
.
items
())
def
iterkeys
(
self
):
return
iter
(
self
.
keys
())
__iter__
=
iterkeys
def
itervalues
(
self
):
return
iter
(
self
.
values
())
class
TestCaseBase
(
unittest
.
TestCase
):
class
TestCaseBase
(
unittest
.
TestCase
):
def
newconfig
(
self
,
defaults
=
None
):
def
newconfig
(
self
,
defaults
=
None
):
...
@@ -414,12 +434,36 @@ class SafeConfigParserTestCase(ConfigParserTestCase):
...
@@ -414,12 +434,36 @@ class SafeConfigParserTestCase(ConfigParserTestCase):
self
.
assertRaises
(
TypeError
,
cf
.
set
,
"sect"
,
"option2"
,
1.0
)
self
.
assertRaises
(
TypeError
,
cf
.
set
,
"sect"
,
"option2"
,
1.0
)
self
.
assertRaises
(
TypeError
,
cf
.
set
,
"sect"
,
"option2"
,
object
())
self
.
assertRaises
(
TypeError
,
cf
.
set
,
"sect"
,
"option2"
,
object
())
class
SortedTestCase
(
RawConfigParserTestCase
):
def
newconfig
(
self
,
defaults
=
None
):
self
.
cf
=
self
.
config_class
(
defaults
=
defaults
,
dict_type
=
SortedDict
)
return
self
.
cf
def
test_sorted
(
self
):
self
.
fromstring
(
"[b]
\n
"
"o4=1
\n
"
"o3=2
\n
"
"o2=3
\n
"
"o1=4
\n
"
"[a]
\n
"
"k=v
\n
"
)
output
=
StringIO
.
StringIO
()
self
.
cf
.
write
(
output
)
self
.
assertEquals
(
output
.
getvalue
(),
"[a]
\n
"
"k = v
\n\n
"
"[b]
\n
"
"o1 = 4
\n
"
"o2 = 3
\n
"
"o3 = 2
\n
"
"o4 = 1
\n\n
"
)
def
test_main
():
def
test_main
():
test_support
.
run_unittest
(
test_support
.
run_unittest
(
ConfigParserTestCase
,
ConfigParserTestCase
,
RawConfigParserTestCase
,
RawConfigParserTestCase
,
SafeConfigParserTestCase
SafeConfigParserTestCase
,
SortedTestCase
)
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
Misc/NEWS
Dosyayı görüntüle @
a00bcac0
...
@@ -101,6 +101,9 @@ Core and builtins
...
@@ -101,6 +101,9 @@ Core and builtins
Library
Library
-------
-------
- Patch #1371075: Make ConfigParser accept optional dict type
for ordering, sorting, etc.
- Bug #1563807: _ctypes built on AIX fails with ld ffi error.
- Bug #1563807: _ctypes built on AIX fails with ld ffi error.
- Bug #1598620: A ctypes Structure cannot contain itself.
- Bug #1598620: A ctypes Structure cannot contain itself.
...
...
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