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
1e8ce58f
Commit
1e8ce58f
authored
Aug 06, 2007
by
Skip Montanaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove most uses of list(somedict.keys()) in Demo scripts
parent
28a181cb
Changes
17
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
31 additions
and
46 deletions
+31
-46
Demo/cgi/cgi2.py
Demo/cgi/cgi2.py
+1
-1
Demo/classes/Dbm.py
Demo/classes/Dbm.py
+2
-2
Demo/metaclasses/Enum.py
Demo/metaclasses/Enum.py
+2
-2
Demo/newmetaclasses/Enum.py
Demo/newmetaclasses/Enum.py
+1
-1
Demo/pdist/cmdfw.py
Demo/pdist/cmdfw.py
+1
-3
Demo/pdist/cmptree.py
Demo/pdist/cmptree.py
+1
-1
Demo/pdist/cvslib.py
Demo/pdist/cvslib.py
+6
-11
Demo/pdist/rrcs.py
Demo/pdist/rrcs.py
+3
-5
Demo/pdist/server.py
Demo/pdist/server.py
+1
-3
Demo/scripts/ftpstats.py
Demo/scripts/ftpstats.py
+2
-5
Demo/scripts/markov.py
Demo/scripts/markov.py
+1
-1
Demo/scripts/newslist.py
Demo/scripts/newslist.py
+1
-2
Demo/threads/Coroutine.py
Demo/threads/Coroutine.py
+1
-1
Demo/tix/samples/OptMenu.py
Demo/tix/samples/OptMenu.py
+1
-1
Demo/tkinter/guido/AttrDialog.py
Demo/tkinter/guido/AttrDialog.py
+3
-3
Demo/xml/elem_count.py
Demo/xml/elem_count.py
+3
-3
Demo/xml/roundtrip.py
Demo/xml/roundtrip.py
+1
-1
No files found.
Demo/cgi/cgi2.py
View file @
1e8ce58f
...
@@ -14,7 +14,7 @@ def main():
...
@@ -14,7 +14,7 @@ def main():
print
(
"<h1>No Form Keys</h1>"
)
print
(
"<h1>No Form Keys</h1>"
)
else
:
else
:
print
(
"<h1>Form Keys</h1>"
)
print
(
"<h1>Form Keys</h1>"
)
for
key
in
list
(
form
.
keys
()
):
for
key
in
form
.
keys
(
):
value
=
form
[
key
].
value
value
=
form
[
key
].
value
print
(
"<p>"
,
cgi
.
escape
(
key
),
":"
,
cgi
.
escape
(
value
))
print
(
"<p>"
,
cgi
.
escape
(
key
),
":"
,
cgi
.
escape
(
value
))
...
...
Demo/classes/Dbm.py
View file @
1e8ce58f
...
@@ -12,7 +12,7 @@ class Dbm:
...
@@ -12,7 +12,7 @@ class Dbm:
def
__repr__
(
self
):
def
__repr__
(
self
):
s
=
''
s
=
''
for
key
in
list
(
self
.
keys
()
):
for
key
in
self
.
keys
(
):
t
=
repr
(
key
)
+
': '
+
repr
(
self
[
key
])
t
=
repr
(
key
)
+
': '
+
repr
(
self
[
key
])
if
s
:
t
=
', '
+
t
if
s
:
t
=
', '
+
t
s
=
s
+
t
s
=
s
+
t
...
@@ -32,7 +32,7 @@ class Dbm:
...
@@ -32,7 +32,7 @@ class Dbm:
def
keys
(
self
):
def
keys
(
self
):
res
=
[]
res
=
[]
for
key
in
list
(
self
.
db
.
keys
()
):
for
key
in
self
.
db
.
keys
(
):
res
.
append
(
eval
(
key
))
res
.
append
(
eval
(
key
))
return
res
return
res
...
...
Demo/metaclasses/Enum.py
View file @
1e8ce58f
...
@@ -42,7 +42,7 @@ class EnumMetaClass:
...
@@ -42,7 +42,7 @@ class EnumMetaClass:
self
.
__name__
=
name
self
.
__name__
=
name
self
.
__bases__
=
bases
self
.
__bases__
=
bases
self
.
__dict
=
{}
self
.
__dict
=
{}
for
key
,
value
in
list
(
dict
.
items
()
):
for
key
,
value
in
dict
.
items
(
):
self
.
__dict
[
key
]
=
EnumInstance
(
name
,
key
,
value
)
self
.
__dict
[
key
]
=
EnumInstance
(
name
,
key
,
value
)
def
__getattr__
(
self
,
name
):
def
__getattr__
(
self
,
name
):
...
@@ -80,7 +80,7 @@ class EnumMetaClass:
...
@@ -80,7 +80,7 @@ class EnumMetaClass:
s
=
s
+
'('
+
string
.
join
([
x
.
__name__
for
x
in
self
.
__bases__
],
", "
)
+
')'
s
=
s
+
'('
+
string
.
join
([
x
.
__name__
for
x
in
self
.
__bases__
],
", "
)
+
')'
if
self
.
__dict
:
if
self
.
__dict
:
list
=
[]
list
=
[]
for
key
,
value
in
list
(
self
.
__dict
.
items
()
):
for
key
,
value
in
self
.
__dict
.
items
(
):
list
.
append
(
"%s: %s"
%
(
key
,
int
(
value
)))
list
.
append
(
"%s: %s"
%
(
key
,
int
(
value
)))
s
=
"%s: {%s}"
%
(
s
,
string
.
join
(
list
,
", "
))
s
=
"%s: {%s}"
%
(
s
,
string
.
join
(
list
,
", "
))
return
s
return
s
...
...
Demo/newmetaclasses/Enum.py
View file @
1e8ce58f
...
@@ -20,7 +20,7 @@ class EnumMetaclass(type):
...
@@ -20,7 +20,7 @@ class EnumMetaclass(type):
def
__init__
(
cls
,
name
,
bases
,
dict
):
def
__init__
(
cls
,
name
,
bases
,
dict
):
super
(
EnumMetaclass
,
cls
).
__init__
(
name
,
bases
,
dict
)
super
(
EnumMetaclass
,
cls
).
__init__
(
name
,
bases
,
dict
)
cls
.
_members
=
[]
cls
.
_members
=
[]
for
attr
in
list
(
dict
.
keys
()
):
for
attr
in
dict
.
keys
(
):
if
not
(
attr
.
startswith
(
'__'
)
and
attr
.
endswith
(
'__'
)):
if
not
(
attr
.
startswith
(
'__'
)
and
attr
.
endswith
(
'__'
)):
enumval
=
EnumInstance
(
name
,
attr
,
dict
[
attr
])
enumval
=
EnumInstance
(
name
,
attr
,
dict
[
attr
])
setattr
(
cls
,
attr
,
enumval
)
setattr
(
cls
,
attr
,
enumval
)
...
...
Demo/pdist/cmdfw.py
View file @
1e8ce58f
...
@@ -104,9 +104,7 @@ class CommandFrameWork:
...
@@ -104,9 +104,7 @@ class CommandFrameWork:
c
=
c
.
__bases__
[
0
]
c
=
c
.
__bases__
[
0
]
if
docstrings
:
if
docstrings
:
print
(
"where subcommand can be:"
)
print
(
"where subcommand can be:"
)
names
=
list
(
docstrings
.
keys
())
for
name
in
sorted
(
docstrings
.
keys
()):
names
.
sort
()
for
name
in
names
:
print
(
docstrings
[
name
])
print
(
docstrings
[
name
])
if
self
.
PostUsageMessage
:
if
self
.
PostUsageMessage
:
print
(
self
.
PostUsageMessage
)
print
(
self
.
PostUsageMessage
)
...
...
Demo/pdist/cmptree.py
View file @
1e8ce58f
...
@@ -89,7 +89,7 @@ def compare(local, remote, mode):
...
@@ -89,7 +89,7 @@ def compare(local, remote, mode):
else
:
else
:
print
(
"same mtime but different sum?!?!"
,
end
=
' '
)
print
(
"same mtime but different sum?!?!"
,
end
=
' '
)
print
()
print
()
for
name
in
l
ist
(
lsumdict
.
keys
()
):
for
name
in
l
sumdict
.
keys
(
):
if
not
list
(
rsumdict
.
keys
()):
if
not
list
(
rsumdict
.
keys
()):
print
(
repr
(
name
),
"only locally"
,
end
=
' '
)
print
(
repr
(
name
),
"only locally"
,
end
=
' '
)
fl
()
fl
()
...
...
Demo/pdist/cvslib.py
View file @
1e8ce58f
...
@@ -223,15 +223,12 @@ class CVS:
...
@@ -223,15 +223,12 @@ class CVS:
f
.
close
()
f
.
close
()
def
getlocalfiles
(
self
):
def
getlocalfiles
(
self
):
list
=
lis
t
(
self
.
entries
.
keys
())
entries_keys
=
se
t
(
self
.
entries
.
keys
())
addlist
=
os
.
listdir
(
os
.
curdir
)
addlist
=
os
.
listdir
(
os
.
curdir
)
for
name
in
addlist
:
for
name
in
addlist
:
if
name
in
list
:
continue
if
not
self
.
ignored
(
name
):
if
not
self
.
ignored
(
name
):
list
.
append
(
name
)
entries_keys
.
add
(
name
)
list
.
sort
()
for
file
in
sorted
(
entries_keys
):
for
file
in
list
:
try
:
try
:
e
=
self
.
entries
[
file
]
e
=
self
.
entries
[
file
]
except
KeyError
:
except
KeyError
:
...
@@ -257,19 +254,17 @@ class CVS:
...
@@ -257,19 +254,17 @@ class CVS:
print
(
'-'
*
50
)
print
(
'-'
*
50
)
def
keys
(
self
):
def
keys
(
self
):
keys
=
list
(
self
.
entries
.
keys
())
return
sorted
(
self
.
entries
.
keys
())
keys
.
sort
()
return
keys
def
values
(
self
):
def
values
(
self
):
def
value
(
key
,
self
=
self
):
def
value
(
key
,
self
=
self
):
return
self
.
entries
[
key
]
return
self
.
entries
[
key
]
return
list
(
map
(
value
,
list
(
self
.
keys
())))
return
[
value
(
k
)
for
k
in
self
.
keys
()]
def
items
(
self
):
def
items
(
self
):
def
item
(
key
,
self
=
self
):
def
item
(
key
,
self
=
self
):
return
(
key
,
self
.
entries
[
key
])
return
(
key
,
self
.
entries
[
key
])
return
list
(
map
(
item
,
list
(
self
.
keys
())))
return
[
item
(
k
)
for
k
in
self
.
keys
()]
def
cvsexists
(
self
,
file
):
def
cvsexists
(
self
,
file
):
file
=
os
.
path
.
join
(
"CVS"
,
file
)
file
=
os
.
path
.
join
(
"CVS"
,
file
)
...
...
Demo/pdist/rrcs.py
View file @
1e8ce58f
...
@@ -71,11 +71,9 @@ def unlock(x, copts, fn):
...
@@ -71,11 +71,9 @@ def unlock(x, copts, fn):
x
.
unlock
(
fn
)
x
.
unlock
(
fn
)
def
info
(
x
,
copts
,
fn
):
def
info
(
x
,
copts
,
fn
):
dict
=
x
.
info
(
fn
)
info_dict
=
x
.
info
(
fn
)
keys
=
list
(
dict
.
keys
())
for
key
in
sorted
(
info_dict
.
keys
()):
keys
.
sort
()
print
(
key
+
':'
,
info_dict
[
key
])
for
key
in
keys
:
print
(
key
+
':'
,
dict
[
key
])
print
(
'='
*
70
)
print
(
'='
*
70
)
def
head
(
x
,
copts
,
fn
):
def
head
(
x
,
copts
,
fn
):
...
...
Demo/pdist/server.py
View file @
1e8ce58f
...
@@ -101,9 +101,7 @@ class Server:
...
@@ -101,9 +101,7 @@ class Server:
def
_listmethods
(
self
,
cl
=
None
):
def
_listmethods
(
self
,
cl
=
None
):
if
not
cl
:
cl
=
self
.
__class__
if
not
cl
:
cl
=
self
.
__class__
names
=
list
(
cl
.
__dict__
.
keys
())
names
=
sorted
([
x
for
x
in
cl
.
__dict__
.
keys
()
if
x
[
0
]
!=
'_'
])
names
=
[
x
for
x
in
names
if
x
[
0
]
!=
'_'
]
names
.
sort
()
for
base
in
cl
.
__bases__
:
for
base
in
cl
.
__bases__
:
basenames
=
self
.
_listmethods
(
base
)
basenames
=
self
.
_listmethods
(
base
)
basenames
=
list
(
filter
(
lambda
x
,
names
=
names
:
x
not
in
names
,
basenames
))
basenames
=
list
(
filter
(
lambda
x
,
names
=
names
:
x
not
in
names
,
basenames
))
...
...
Demo/scripts/ftpstats.py
View file @
1e8ce58f
...
@@ -106,9 +106,7 @@ def showbar(dict, title):
...
@@ -106,9 +106,7 @@ def showbar(dict, title):
n
=
len
(
title
)
n
=
len
(
title
)
print
(
'='
*
((
70
-
n
)
/
2
),
title
,
'='
*
((
71
-
n
)
/
2
))
print
(
'='
*
((
70
-
n
)
/
2
),
title
,
'='
*
((
71
-
n
)
/
2
))
list
=
[]
list
=
[]
keys
=
list
(
dict
.
keys
())
for
key
in
sorted
(
dict
.
keys
()):
keys
.
sort
()
for
key
in
keys
:
n
=
len
(
str
(
key
))
n
=
len
(
str
(
key
))
list
.
append
((
len
(
dict
[
key
]),
key
))
list
.
append
((
len
(
dict
[
key
]),
key
))
maxkeylength
=
0
maxkeylength
=
0
...
@@ -128,8 +126,7 @@ def show(dict, title, maxitems):
...
@@ -128,8 +126,7 @@ def show(dict, title, maxitems):
n
=
len
(
title
)
n
=
len
(
title
)
print
(
'='
*
((
70
-
n
)
/
2
),
title
,
'='
*
((
71
-
n
)
/
2
))
print
(
'='
*
((
70
-
n
)
/
2
),
title
,
'='
*
((
71
-
n
)
/
2
))
list
=
[]
list
=
[]
keys
=
list
(
dict
.
keys
())
for
key
in
dict
.
keys
():
for
key
in
keys
:
list
.
append
((
-
len
(
dict
[
key
]),
key
))
list
.
append
((
-
len
(
dict
[
key
]),
key
))
list
.
sort
()
list
.
sort
()
for
count
,
key
in
list
[:
maxitems
]:
for
count
,
key
in
list
[:
maxitems
]:
...
...
Demo/scripts/markov.py
View file @
1e8ce58f
...
@@ -87,7 +87,7 @@ def test():
...
@@ -87,7 +87,7 @@ def test():
return
return
if
debug
:
print
(
'done.'
)
if
debug
:
print
(
'done.'
)
if
debug
>
1
:
if
debug
>
1
:
for
key
in
list
(
m
.
trans
.
keys
()
):
for
key
in
m
.
trans
.
keys
(
):
if
key
is
None
or
len
(
key
)
<
histsize
:
if
key
is
None
or
len
(
key
)
<
histsize
:
print
(
repr
(
key
),
m
.
trans
[
key
])
print
(
repr
(
key
),
m
.
trans
[
key
])
if
histsize
==
0
:
print
(
repr
(
''
),
m
.
trans
[
''
])
if
histsize
==
0
:
print
(
repr
(
''
),
m
.
trans
[
''
])
...
...
Demo/scripts/newslist.py
View file @
1e8ce58f
...
@@ -172,10 +172,9 @@ def printtree(f, tree, indent, p):
...
@@ -172,10 +172,9 @@ def printtree(f, tree, indent, p):
createpage
(
p
[
1
:],
tree
,
p
)
createpage
(
p
[
1
:],
tree
,
p
)
return
return
kl
=
list
(
tree
.
keys
())
kl
=
sorted
(
tree
.
keys
())
if
l
>
1
:
if
l
>
1
:
kl
.
sort
()
if
indent
>
0
:
if
indent
>
0
:
# Create a sub-list
# Create a sub-list
f
.
write
(
'<LI>'
+
p
[
1
:]
+
'
\
n
<UL>'
)
f
.
write
(
'<LI>'
+
p
[
1
:]
+
'
\
n
<UL>'
)
...
...
Demo/threads/Coroutine.py
View file @
1e8ce58f
...
@@ -127,7 +127,7 @@ class Coroutine:
...
@@ -127,7 +127,7 @@ class Coroutine:
if
self
.
killed
:
if
self
.
killed
:
raise
TypeError
(
'kill() called on dead coroutines'
)
raise
TypeError
(
'kill() called on dead coroutines'
)
self
.
killed
=
1
self
.
killed
=
1
for
coroutine
in
list
(
self
.
invokedby
.
keys
()
):
for
coroutine
in
self
.
invokedby
.
keys
(
):
coroutine
.
resume
()
coroutine
.
resume
()
def
back
(
self
,
data
=
None
):
def
back
(
self
,
data
=
None
):
...
...
Demo/tix/samples/OptMenu.py
View file @
1e8ce58f
...
@@ -40,7 +40,7 @@ def RunSample(w):
...
@@ -40,7 +40,7 @@ def RunSample(w):
# global variables "demo_opt_from" and "demo_opt_to". Otherwise
# global variables "demo_opt_from" and "demo_opt_to". Otherwise
# the OptionMenu widget will complain about "unknown options"!
# the OptionMenu widget will complain about "unknown options"!
#
#
for
opt
in
list
(
options
.
keys
()
):
for
opt
in
options
.
keys
(
):
from_file
.
add_command
(
opt
,
label
=
options
[
opt
])
from_file
.
add_command
(
opt
,
label
=
options
[
opt
])
to_file
.
add_command
(
opt
,
label
=
options
[
opt
])
to_file
.
add_command
(
opt
,
label
=
options
[
opt
])
...
...
Demo/tkinter/guido/AttrDialog.py
View file @
1e8ce58f
...
@@ -112,7 +112,7 @@ class Dialog:
...
@@ -112,7 +112,7 @@ class Dialog:
def
addchoices
(
self
):
def
addchoices
(
self
):
self
.
choices
=
{}
self
.
choices
=
{}
list
=
[]
list
=
[]
for
k
,
dc
in
list
(
self
.
options
.
items
()
):
for
k
,
dc
in
self
.
options
.
items
(
):
list
.
append
((
k
,
dc
))
list
.
append
((
k
,
dc
))
list
.
sort
()
list
.
sort
()
for
k
,
(
d
,
c
)
in
list
:
for
k
,
(
d
,
c
)
in
list
:
...
@@ -260,7 +260,7 @@ class WidgetDialog(Dialog):
...
@@ -260,7 +260,7 @@ class WidgetDialog(Dialog):
classes
=
{}
classes
=
{}
for
c
in
(
self
.
classes
,
for
c
in
(
self
.
classes
,
self
.
addclasses
[
self
.
klass
]):
self
.
addclasses
[
self
.
klass
]):
for
k
in
list
(
c
.
keys
()
):
for
k
in
c
.
keys
(
):
classes
[
k
]
=
c
[
k
]
classes
[
k
]
=
c
[
k
]
self
.
classes
=
classes
self
.
classes
=
classes
...
@@ -273,7 +273,7 @@ class WidgetDialog(Dialog):
...
@@ -273,7 +273,7 @@ class WidgetDialog(Dialog):
def
update
(
self
):
def
update
(
self
):
self
.
current
=
{}
self
.
current
=
{}
self
.
options
=
{}
self
.
options
=
{}
for
k
,
v
in
list
(
self
.
configuration
.
items
()
):
for
k
,
v
in
self
.
configuration
.
items
(
):
if
len
(
v
)
>
4
:
if
len
(
v
)
>
4
:
self
.
current
[
k
]
=
v
[
4
]
self
.
current
[
k
]
=
v
[
4
]
self
.
options
[
k
]
=
v
[
3
],
v
[
2
]
# default, klass
self
.
options
[
k
]
=
v
[
3
],
v
[
2
]
# default, klass
...
...
Demo/xml/elem_count.py
View file @
1e8ce58f
...
@@ -15,7 +15,7 @@ class FancyCounter(handler.ContentHandler):
...
@@ -15,7 +15,7 @@ class FancyCounter(handler.ContentHandler):
self
.
_attrs
=
self
.
_attrs
+
len
(
attrs
)
self
.
_attrs
=
self
.
_attrs
+
len
(
attrs
)
self
.
_elem_types
[
name
]
=
self
.
_elem_types
.
get
(
name
,
0
)
+
1
self
.
_elem_types
[
name
]
=
self
.
_elem_types
.
get
(
name
,
0
)
+
1
for
name
in
list
(
attrs
.
keys
()
):
for
name
in
attrs
.
keys
(
):
self
.
_attr_types
[
name
]
=
self
.
_attr_types
.
get
(
name
,
0
)
+
1
self
.
_attr_types
[
name
]
=
self
.
_attr_types
.
get
(
name
,
0
)
+
1
def
endDocument
(
self
):
def
endDocument
(
self
):
...
@@ -23,11 +23,11 @@ class FancyCounter(handler.ContentHandler):
...
@@ -23,11 +23,11 @@ class FancyCounter(handler.ContentHandler):
print
(
"There were"
,
self
.
_attrs
,
"attributes."
)
print
(
"There were"
,
self
.
_attrs
,
"attributes."
)
print
(
"---ELEMENT TYPES"
)
print
(
"---ELEMENT TYPES"
)
for
pair
in
list
(
self
.
_elem_types
.
items
()
):
for
pair
in
self
.
_elem_types
.
items
(
):
print
(
"%20s %d"
%
pair
)
print
(
"%20s %d"
%
pair
)
print
(
"---ATTRIBUTE TYPES"
)
print
(
"---ATTRIBUTE TYPES"
)
for
pair
in
list
(
self
.
_attr_types
.
items
()
):
for
pair
in
self
.
_attr_types
.
items
(
):
print
(
"%20s %d"
%
pair
)
print
(
"%20s %d"
%
pair
)
...
...
Demo/xml/roundtrip.py
View file @
1e8ce58f
...
@@ -22,7 +22,7 @@ class ContentGenerator(handler.ContentHandler):
...
@@ -22,7 +22,7 @@ class ContentGenerator(handler.ContentHandler):
def
startElement
(
self
,
name
,
attrs
):
def
startElement
(
self
,
name
,
attrs
):
self
.
_out
.
write
(
'<'
+
name
)
self
.
_out
.
write
(
'<'
+
name
)
for
(
name
,
value
)
in
list
(
attrs
.
items
()
):
for
(
name
,
value
)
in
attrs
.
items
(
):
self
.
_out
.
write
(
' %s="%s"'
%
(
name
,
saxutils
.
escape
(
value
)))
self
.
_out
.
write
(
' %s="%s"'
%
(
name
,
saxutils
.
escape
(
value
)))
self
.
_out
.
write
(
'>'
)
self
.
_out
.
write
(
'>'
)
...
...
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