[Zope-dev] DirectoryStorage 0.04
Petru Paler
ppetru@coltronix.com
Sat, 10 Jun 2000 00:27:32 +0300 (EEST)
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.
---1463811836-743019727-960586052=:19838
Content-Type: TEXT/PLAIN; charset=US-ASCII
Changelog:
0.04:
- added missing binary flags to open() calls to make it work on NT.
- added flush() calls after file writing
- added close() method to the DirectoryStorage class
0.03:
- don't die if posix.fsync is not available
- base class renamed to DirectoryStorage
- added directory (re)creation and locking
- added a 'magic' file
- last oid file open/close bug
- moved serials to an gdbm database
0.02:
- converted to using os.path.join
0.01:
- initial release
-Petru
---1463811836-743019727-960586052=:19838
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="DirectoryStorage.py"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.10.10006100027320.19838@oliver.local.coltronix.com>
Content-Description:
Content-Disposition: attachment; filename="DirectoryStorage.py"
IyBDb3B5cmlnaHQgKGMpIDIwMDAgUGV0cnUgUGFsZXIgKHBwZXRydUBjb2x0
cm9uaXguY29tKSBBbGwgcmlnaHRzIHJlc2VydmVkLg0KDQoNCiMgVG8tZG8g
bGlzdDoNCiMgQ3JpdGljYWw6DQojICAgIC0gTW9zdCBJL08gb3BlcmF0aW9u
cyBhcmUgbm90IGF0b21pYy4gVGhpcyBtZWFucyB0aGF0IEkvTyBlcnJvcnMg
KGFuZCwgZm9yDQojICAgIHRoYXQgbWF0dGVyLCBhbnkgZXhjZXB0aW9ucyBv
Y2N1cmVkIGluIF9maW5pc2gpIGxlYXZlIHRoZSBzdG9yYWdlIGluIGFuDQoj
ICAgIHVuZGVmaW5lZCBzdGF0ZQ0KIw0KIyBOb3QgY3JpdGljYWw6DQojICAg
IC0gUGVyZm9ybWFuY2UgdHVuaW5nIC0tIGFkZCBjYWNoZXMgd2hlcmUgYXBy
b3BpYXRlDQojICAgIC0gbWFrZSBzdXJlIGxvY2tp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