summaryrefslogtreecommitdiffstats
path: root/Demo
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-07-04 07:25:18 (GMT)
committerGeorg Brandl <georg@python.org>2010-07-04 07:25:18 (GMT)
commitbe7a7553cda1268b1dd2cec105345b5e0534c93f (patch)
treec5f1da171403e2733b6a069e314551c7c5f59fd8 /Demo
parent74135d0ad9332752400291cd8e666f53d887d42d (diff)
downloadcpython-be7a7553cda1268b1dd2cec105345b5e0534c93f.zip
cpython-be7a7553cda1268b1dd2cec105345b5e0534c93f.tar.gz
cpython-be7a7553cda1268b1dd2cec105345b5e0534c93f.tar.bz2
Remove old and unsafe Dbm demo class.
Diffstat (limited to 'Demo')
-rw-r--r--Demo/classes/Dbm.py66
1 files changed, 0 insertions, 66 deletions
diff --git a/Demo/classes/Dbm.py b/Demo/classes/Dbm.py
deleted file mode 100644
index f931e93..0000000
--- a/Demo/classes/Dbm.py
+++ /dev/null
@@ -1,66 +0,0 @@
-# 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()