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
be7a7553
Commit
be7a7553
authored
Jul 04, 2010
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove old and unsafe Dbm demo class.
parent
74135d0a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
66 deletions
+0
-66
Demo/classes/Dbm.py
Demo/classes/Dbm.py
+0
-66
No files found.
Demo/classes/Dbm.py
deleted
100644 → 0
View file @
74135d0a
# A wrapper around the (optional) built-in class dbm, supporting keys
# and values of almost any type instead of just string.
# (Actually, this works only for keys and values that can be read back
# correctly after being converted to a string.)
class
Dbm
:
def
__init__
(
self
,
filename
,
mode
,
perm
):
import
dbm.ndbm
self
.
db
=
dbm
.
ndbm
.
open
(
filename
,
mode
,
perm
)
def
__repr__
(
self
):
s
=
''
for
key
in
self
.
keys
():
t
=
repr
(
key
)
+
': '
+
repr
(
self
[
key
])
if
s
:
t
=
', '
+
t
s
=
s
+
t
return
'{'
+
s
+
'}'
def
__len__
(
self
):
return
len
(
self
.
db
)
def
__getitem__
(
self
,
key
):
return
eval
(
self
.
db
[
repr
(
key
)])
def
__setitem__
(
self
,
key
,
value
):
self
.
db
[
repr
(
key
)]
=
repr
(
value
)
def
__delitem__
(
self
,
key
):
del
self
.
db
[
repr
(
key
)]
def
keys
(
self
):
res
=
[]
for
key
in
self
.
db
.
keys
():
res
.
append
(
eval
(
key
))
return
res
def
has_key
(
self
,
key
):
return
repr
(
key
)
in
self
.
db
def
test
():
d
=
Dbm
(
'@dbm'
,
'rw'
,
0o600
)
print
(
d
)
while
1
:
try
:
key
=
eval
(
input
(
'key: '
))
if
key
in
d
:
value
=
d
[
key
]
print
(
'currently:'
,
value
)
value
=
eval
(
input
(
'value: '
))
if
value
is
None
:
del
d
[
key
]
else
:
d
[
key
]
=
value
except
KeyboardInterrupt
:
print
(
''
)
print
(
d
)
except
EOFError
:
print
(
'[eof]'
)
break
print
(
d
)
test
()
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