1995-08-10 16:29:28 -03:00
|
|
|
"""A dumb and slow but simple dbm clone.
|
|
|
|
|
|
|
|
For database spam, spam.dir contains the index (a text file),
|
|
|
|
spam.bak *may* contain a backup of the index (also a text file),
|
|
|
|
while spam.dat contains the data (a binary file).
|
|
|
|
|
|
|
|
XXX TO DO:
|
|
|
|
|
|
|
|
- seems to contain a bug when updating...
|
|
|
|
|
|
|
|
- reclaim free space (currently, space once occupied by deleted or expanded
|
|
|
|
items is never reused)
|
|
|
|
|
|
|
|
- support concurrent access (currently, if two processes take turns making
|
|
|
|
updates, they can mess up the index)
|
|
|
|
|
|
|
|
- support efficient access to large databases (currently, the whole index
|
|
|
|
is read when the database is opened, and some updates rewrite the whole index)
|
|
|
|
|
|
|
|
- support opening for read-only (flag = 'm')
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2015-02-15 18:30:43 -04:00
|
|
|
import ast as _ast
|
2007-05-23 17:51:02 -03:00
|
|
|
import io as _io
|
2001-07-19 07:06:39 -03:00
|
|
|
import os as _os
|
2017-04-24 03:05:00 -03:00
|
|
|
import collections.abc
|
1995-08-10 16:29:28 -03:00
|
|
|
|
2008-05-26 07:29:35 -03:00
|
|
|
__all__ = ["error", "open"]
|
|
|
|
|
1995-08-10 16:29:28 -03:00
|
|
|
_BLOCKSIZE = 512
|
|
|
|
|
2012-12-25 10:47:37 -04:00
|
|
|
error = OSError
|
1996-05-28 19:58:40 -03:00
|
|
|
|
2017-04-24 03:05:00 -03:00
|
|
|
class _Database(collections.abc.MutableMapping):
|
1995-08-10 16:29:28 -03:00
|
|
|
|
2003-07-12 23:22:03 -03:00
|
|
|
# The on-disk directory and data files can remain in mutually
|
|
|
|
# inconsistent states for an arbitrarily long time (see comments
|
|
|
|
# at the end of __setitem__). This is only repaired when _commit()
|
|
|
|
# gets called. One place _commit() gets called is from __del__(),
|
|
|
|
# and if that occurs at program shutdown time, module globals may
|
|
|
|
# already have gotten rebound to None. Since it's crucial that
|
2003-07-12 23:37:05 -03:00
|
|
|
# _commit() finish successfully, we can't ignore shutdown races
|
2003-07-12 23:22:03 -03:00
|
|
|
# here, and _commit() must not reference any globals.
|
|
|
|
_os = _os # for _commit()
|
2007-05-23 17:51:02 -03:00
|
|
|
_io = _io # for _commit()
|
2003-07-12 23:22:03 -03:00
|
|
|
|
2014-06-10 15:16:00 -03:00
|
|
|
def __init__(self, filebasename, mode, flag='c'):
|
2001-12-07 17:54:46 -04:00
|
|
|
self._mode = mode
|
2016-07-06 06:21:58 -03:00
|
|
|
self._readonly = (flag == 'r')
|
2003-07-12 17:11:25 -03:00
|
|
|
|
|
|
|
# The directory file is a text file. Each line looks like
|
|
|
|
# "%r, (%d, %d)\n" % (key, pos, siz)
|
|
|
|
# where key is the string key, pos is the offset into the dat
|
|
|
|
# file of the associated value's first byte, and siz is the number
|
|
|
|
# of bytes in the associated value.
|
2007-08-16 11:35:24 -03:00
|
|
|
self._dirfile = filebasename + '.dir'
|
2003-07-12 17:11:25 -03:00
|
|
|
|
|
|
|
# The data file is a binary file pointed into by the directory
|
|
|
|
# file, and holds the values associated with keys. Each value
|
|
|
|
# begins at a _BLOCKSIZE-aligned byte offset, and is a raw
|
|
|
|
# binary 8-bit string value.
|
2007-08-16 11:35:24 -03:00
|
|
|
self._datfile = filebasename + '.dat'
|
|
|
|
self._bakfile = filebasename + '.bak'
|
2003-07-12 17:11:25 -03:00
|
|
|
|
|
|
|
# The index is an in-memory dict, mirroring the directory file.
|
|
|
|
self._index = None # maps keys to (pos, siz) pairs
|
|
|
|
|
2014-06-10 15:16:00 -03:00
|
|
|
# Handle the creation
|
|
|
|
self._create(flag)
|
2016-12-07 05:11:12 -04:00
|
|
|
self._update(flag)
|
2014-06-10 15:16:00 -03:00
|
|
|
|
|
|
|
def _create(self, flag):
|
|
|
|
if flag == 'n':
|
|
|
|
for filename in (self._datfile, self._bakfile, self._dirfile):
|
|
|
|
try:
|
|
|
|
_os.remove(filename)
|
|
|
|
except OSError:
|
|
|
|
pass
|
2001-01-14 19:36:06 -04:00
|
|
|
# Mod by Jack: create data file if needed
|
|
|
|
try:
|
2008-11-24 17:09:58 -04:00
|
|
|
f = _io.open(self._datfile, 'r', encoding="Latin-1")
|
2012-12-25 10:47:37 -04:00
|
|
|
except OSError:
|
2016-07-06 06:21:58 -03:00
|
|
|
if flag not in ('c', 'n'):
|
2018-02-05 16:47:31 -04:00
|
|
|
raise
|
2014-06-25 14:35:31 -03:00
|
|
|
with _io.open(self._datfile, 'w', encoding="Latin-1") as f:
|
|
|
|
self._chmod(self._datfile)
|
|
|
|
else:
|
|
|
|
f.close()
|
2001-01-14 19:36:06 -04:00
|
|
|
|
2003-07-12 17:11:25 -03:00
|
|
|
# Read directory file into the in-memory index dict.
|
2016-12-07 05:11:12 -04:00
|
|
|
def _update(self, flag):
|
2018-02-05 16:47:31 -04:00
|
|
|
self._modified = False
|
2001-01-14 19:36:06 -04:00
|
|
|
self._index = {}
|
|
|
|
try:
|
2008-11-24 17:09:58 -04:00
|
|
|
f = _io.open(self._dirfile, 'r', encoding="Latin-1")
|
2012-12-25 10:47:37 -04:00
|
|
|
except OSError:
|
2016-12-07 05:11:12 -04:00
|
|
|
if flag not in ('c', 'n'):
|
2018-02-05 16:47:31 -04:00
|
|
|
raise
|
|
|
|
self._modified = True
|
2001-01-14 19:36:06 -04:00
|
|
|
else:
|
2014-06-25 14:35:31 -03:00
|
|
|
with f:
|
|
|
|
for line in f:
|
|
|
|
line = line.rstrip()
|
2015-02-15 18:30:43 -04:00
|
|
|
key, pos_and_siz_pair = _ast.literal_eval(line)
|
2014-06-25 14:35:31 -03:00
|
|
|
key = key.encode('Latin-1')
|
|
|
|
self._index[key] = pos_and_siz_pair
|
2001-01-14 19:36:06 -04:00
|
|
|
|
2003-07-12 17:11:25 -03:00
|
|
|
# Write the index dict to the directory file. The original directory
|
|
|
|
# file (if any) is renamed with a .bak extension first. If a .bak
|
|
|
|
# file currently exists, it's deleted.
|
2001-01-14 19:36:06 -04:00
|
|
|
def _commit(self):
|
2003-07-12 23:22:03 -03:00
|
|
|
# CAUTION: It's vital that _commit() succeed, and _commit() can
|
|
|
|
# be called from __del__(). Therefore we must never reference a
|
|
|
|
# global in this routine.
|
2016-12-07 04:56:39 -04:00
|
|
|
if self._index is None or not self._modified:
|
2003-07-13 14:21:10 -03:00
|
|
|
return # nothing to do
|
|
|
|
|
2003-07-12 17:11:25 -03:00
|
|
|
try:
|
2003-07-12 23:22:03 -03:00
|
|
|
self._os.unlink(self._bakfile)
|
2012-12-18 16:02:39 -04:00
|
|
|
except OSError:
|
2003-07-12 17:11:25 -03:00
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
2003-07-12 23:22:03 -03:00
|
|
|
self._os.rename(self._dirfile, self._bakfile)
|
2012-12-18 16:02:39 -04:00
|
|
|
except OSError:
|
2003-07-12 17:11:25 -03:00
|
|
|
pass
|
|
|
|
|
2014-06-25 14:35:31 -03:00
|
|
|
with self._io.open(self._dirfile, 'w', encoding="Latin-1") as f:
|
|
|
|
self._chmod(self._dirfile)
|
|
|
|
for key, pos_and_siz_pair in self._index.items():
|
|
|
|
# Use Latin-1 since it has no qualms with any value in any
|
|
|
|
# position; UTF-8, though, does care sometimes.
|
|
|
|
entry = "%r, %r\n" % (key.decode('Latin-1'), pos_and_siz_pair)
|
|
|
|
f.write(entry)
|
2001-01-14 19:36:06 -04:00
|
|
|
|
2003-07-14 09:15:15 -03:00
|
|
|
sync = _commit
|
|
|
|
|
2014-04-26 17:56:52 -03:00
|
|
|
def _verify_open(self):
|
|
|
|
if self._index is None:
|
|
|
|
raise error('DBM object has already been closed')
|
|
|
|
|
2001-01-14 19:36:06 -04:00
|
|
|
def __getitem__(self, key):
|
2008-11-20 20:17:53 -04:00
|
|
|
if isinstance(key, str):
|
|
|
|
key = key.encode('utf-8')
|
2014-04-26 17:56:52 -03:00
|
|
|
self._verify_open()
|
2001-01-14 19:36:06 -04:00
|
|
|
pos, siz = self._index[key] # may raise KeyError
|
2014-06-25 14:35:31 -03:00
|
|
|
with _io.open(self._datfile, 'rb') as f:
|
|
|
|
f.seek(pos)
|
|
|
|
dat = f.read(siz)
|
2001-01-14 19:36:06 -04:00
|
|
|
return dat
|
|
|
|
|
2003-07-12 17:11:25 -03:00
|
|
|
# Append val to the data file, starting at a _BLOCKSIZE-aligned
|
|
|
|
# offset. The data file is first padded with NUL bytes (if needed)
|
|
|
|
# to get to an aligned offset. Return pair
|
|
|
|
# (starting offset of val, len(val))
|
2001-01-14 19:36:06 -04:00
|
|
|
def _addval(self, val):
|
2014-06-25 14:35:31 -03:00
|
|
|
with _io.open(self._datfile, 'rb+') as f:
|
|
|
|
f.seek(0, 2)
|
|
|
|
pos = int(f.tell())
|
|
|
|
npos = ((pos + _BLOCKSIZE - 1) // _BLOCKSIZE) * _BLOCKSIZE
|
|
|
|
f.write(b'\0'*(npos-pos))
|
|
|
|
pos = npos
|
|
|
|
f.write(val)
|
2001-01-14 19:36:06 -04:00
|
|
|
return (pos, len(val))
|
|
|
|
|
2003-07-12 17:11:25 -03:00
|
|
|
# Write val to the data file, starting at offset pos. The caller
|
|
|
|
# is responsible for ensuring that there's enough room starting at
|
|
|
|
# pos to hold val, without overwriting some other value. Return
|
|
|
|
# pair (pos, len(val)).
|
2001-01-14 19:36:06 -04:00
|
|
|
def _setval(self, pos, val):
|
2014-06-25 14:35:31 -03:00
|
|
|
with _io.open(self._datfile, 'rb+') as f:
|
|
|
|
f.seek(pos)
|
|
|
|
f.write(val)
|
2001-01-14 19:36:06 -04:00
|
|
|
return (pos, len(val))
|
|
|
|
|
2003-07-12 17:11:25 -03:00
|
|
|
# key is a new key whose associated value starts in the data file
|
2003-07-12 23:05:47 -03:00
|
|
|
# at offset pos and with length siz. Add an index record to
|
|
|
|
# the in-memory index dict, and append one to the directory file.
|
2003-07-12 17:11:25 -03:00
|
|
|
def _addkey(self, key, pos_and_siz_pair):
|
|
|
|
self._index[key] = pos_and_siz_pair
|
2014-06-25 14:35:31 -03:00
|
|
|
with _io.open(self._dirfile, 'a', encoding="Latin-1") as f:
|
|
|
|
self._chmod(self._dirfile)
|
|
|
|
f.write("%r, %r\n" % (key.decode("Latin-1"), pos_and_siz_pair))
|
2001-01-14 19:36:06 -04:00
|
|
|
|
|
|
|
def __setitem__(self, key, val):
|
2016-07-06 06:21:58 -03:00
|
|
|
if self._readonly:
|
2018-02-05 16:47:31 -04:00
|
|
|
raise ValueError('The database is opened for reading only')
|
2008-11-20 20:17:53 -04:00
|
|
|
if isinstance(key, str):
|
|
|
|
key = key.encode('utf-8')
|
|
|
|
elif not isinstance(key, (bytes, bytearray)):
|
|
|
|
raise TypeError("keys must be bytes or strings")
|
2008-11-24 17:09:58 -04:00
|
|
|
if isinstance(val, str):
|
|
|
|
val = val.encode('utf-8')
|
|
|
|
elif not isinstance(val, (bytes, bytearray)):
|
|
|
|
raise TypeError("values must be bytes or strings")
|
2014-04-26 17:56:52 -03:00
|
|
|
self._verify_open()
|
2016-12-07 04:56:39 -04:00
|
|
|
self._modified = True
|
2003-07-12 17:11:25 -03:00
|
|
|
if key not in self._index:
|
|
|
|
self._addkey(key, self._addval(val))
|
2001-01-14 19:36:06 -04:00
|
|
|
else:
|
2003-07-12 17:11:25 -03:00
|
|
|
# See whether the new value is small enough to fit in the
|
|
|
|
# (padded) space currently occupied by the old value.
|
2001-01-14 19:36:06 -04:00
|
|
|
pos, siz = self._index[key]
|
2003-07-11 01:09:55 -03:00
|
|
|
oldblocks = (siz + _BLOCKSIZE - 1) // _BLOCKSIZE
|
|
|
|
newblocks = (len(val) + _BLOCKSIZE - 1) // _BLOCKSIZE
|
2001-01-14 19:36:06 -04:00
|
|
|
if newblocks <= oldblocks:
|
2003-07-12 17:11:25 -03:00
|
|
|
self._index[key] = self._setval(pos, val)
|
2001-01-14 19:36:06 -04:00
|
|
|
else:
|
2003-07-12 17:11:25 -03:00
|
|
|
# The new value doesn't fit in the (padded) space used
|
|
|
|
# by the old value. The blocks used by the old value are
|
|
|
|
# forever lost.
|
|
|
|
self._index[key] = self._addval(val)
|
|
|
|
|
|
|
|
# Note that _index may be out of synch with the directory
|
|
|
|
# file now: _setval() and _addval() don't update the directory
|
2003-07-12 23:05:47 -03:00
|
|
|
# file. This also means that the on-disk directory and data
|
|
|
|
# files are in a mutually inconsistent state, and they'll
|
|
|
|
# remain that way until _commit() is called. Note that this
|
|
|
|
# is a disaster (for the database) if the program crashes
|
|
|
|
# (so that _commit() never gets called).
|
2001-01-14 19:36:06 -04:00
|
|
|
|
|
|
|
def __delitem__(self, key):
|
2016-07-06 06:21:58 -03:00
|
|
|
if self._readonly:
|
2018-02-05 16:47:31 -04:00
|
|
|
raise ValueError('The database is opened for reading only')
|
2008-11-20 20:17:53 -04:00
|
|
|
if isinstance(key, str):
|
|
|
|
key = key.encode('utf-8')
|
2014-04-26 17:56:52 -03:00
|
|
|
self._verify_open()
|
2016-12-07 04:56:39 -04:00
|
|
|
self._modified = True
|
2003-07-12 17:11:25 -03:00
|
|
|
# The blocks used by the associated value are lost.
|
2001-01-14 19:36:06 -04:00
|
|
|
del self._index[key]
|
2003-07-12 17:11:25 -03:00
|
|
|
# XXX It's unclear why we do a _commit() here (the code always
|
2010-12-04 05:14:36 -04:00
|
|
|
# XXX has, so I'm not changing it). __setitem__ doesn't try to
|
2003-07-12 17:11:25 -03:00
|
|
|
# XXX keep the directory file in synch. Why should we? Or
|
|
|
|
# XXX why shouldn't __setitem__?
|
2001-01-14 19:36:06 -04:00
|
|
|
self._commit()
|
|
|
|
|
|
|
|
def keys(self):
|
2014-05-28 12:49:52 -03:00
|
|
|
try:
|
|
|
|
return list(self._index)
|
|
|
|
except TypeError:
|
|
|
|
raise error('DBM object has already been closed') from None
|
2007-08-27 21:09:54 -03:00
|
|
|
|
|
|
|
def items(self):
|
2014-04-26 17:56:52 -03:00
|
|
|
self._verify_open()
|
2008-11-20 20:17:53 -04:00
|
|
|
return [(key, self[key]) for key in self._index.keys()]
|
2001-01-14 19:36:06 -04:00
|
|
|
|
2001-05-03 01:55:47 -03:00
|
|
|
def __contains__(self, key):
|
2008-11-20 20:17:53 -04:00
|
|
|
if isinstance(key, str):
|
|
|
|
key = key.encode('utf-8')
|
2014-05-28 12:49:52 -03:00
|
|
|
try:
|
|
|
|
return key in self._index
|
|
|
|
except TypeError:
|
|
|
|
if self._index is None:
|
|
|
|
raise error('DBM object has already been closed') from None
|
|
|
|
else:
|
|
|
|
raise
|
2001-05-03 01:55:47 -03:00
|
|
|
|
|
|
|
def iterkeys(self):
|
2014-05-28 12:49:52 -03:00
|
|
|
try:
|
|
|
|
return iter(self._index)
|
|
|
|
except TypeError:
|
|
|
|
raise error('DBM object has already been closed') from None
|
2001-05-03 01:55:47 -03:00
|
|
|
__iter__ = iterkeys
|
|
|
|
|
2001-01-14 19:36:06 -04:00
|
|
|
def __len__(self):
|
2014-05-28 12:49:52 -03:00
|
|
|
try:
|
|
|
|
return len(self._index)
|
|
|
|
except TypeError:
|
|
|
|
raise error('DBM object has already been closed') from None
|
2001-01-14 19:36:06 -04:00
|
|
|
|
|
|
|
def close(self):
|
2015-04-10 07:24:41 -03:00
|
|
|
try:
|
|
|
|
self._commit()
|
|
|
|
finally:
|
|
|
|
self._index = self._datfile = self._dirfile = self._bakfile = None
|
1995-08-10 16:29:28 -03:00
|
|
|
|
2003-07-13 14:21:10 -03:00
|
|
|
__del__ = close
|
2002-02-16 03:34:19 -04:00
|
|
|
|
2010-12-04 05:14:36 -04:00
|
|
|
def _chmod(self, file):
|
Merged revisions 53005-53303 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r53012 | walter.doerwald | 2006-12-12 22:55:31 +0100 (Tue, 12 Dec 2006) | 2 lines
Fix typo.
........
r53023 | brett.cannon | 2006-12-13 23:31:37 +0100 (Wed, 13 Dec 2006) | 2 lines
Remove an unneeded import of 'warnings'.
........
r53025 | brett.cannon | 2006-12-14 00:02:38 +0100 (Thu, 14 Dec 2006) | 2 lines
Remove unneeded imports of 'warnings'.
........
r53026 | brett.cannon | 2006-12-14 00:09:53 +0100 (Thu, 14 Dec 2006) | 4 lines
Add test.test_support.guard_warnings_filter . This function returns a context
manager that protects warnings.filter from being modified once the context is
exited.
........
r53029 | george.yoshida | 2006-12-14 03:22:44 +0100 (Thu, 14 Dec 2006) | 2 lines
Note that guard_warnings_filter was added in 2.6
........
r53031 | vinay.sajip | 2006-12-14 09:53:55 +0100 (Thu, 14 Dec 2006) | 1 line
Added news on recent changes to logging
........
r53032 | andrew.kuchling | 2006-12-14 19:57:53 +0100 (Thu, 14 Dec 2006) | 1 line
[Patch #1599256 from David Watson] check that os.fsync is available before using it
........
r53042 | kurt.kaiser | 2006-12-15 06:13:11 +0100 (Fri, 15 Dec 2006) | 6 lines
1. Avoid hang when encountering a duplicate in a completion list. Bug 1571112.
2. Duplicate some old entries from Python's NEWS to IDLE's NEWS.txt
M AutoCompleteWindow.py
M NEWS.txt
........
r53048 | andrew.kuchling | 2006-12-18 18:12:31 +0100 (Mon, 18 Dec 2006) | 1 line
[Bug #1618083] Add missing word; make a few grammar fixes
........
r53050 | andrew.kuchling | 2006-12-18 18:16:05 +0100 (Mon, 18 Dec 2006) | 1 line
Bump version
........
r53051 | andrew.kuchling | 2006-12-18 18:22:07 +0100 (Mon, 18 Dec 2006) | 1 line
[Bug #1616726] Fix description of generator.close(); if you raise some random exception, the exception is raised and doesn't trigger a RuntimeError
........
r53052 | andrew.kuchling | 2006-12-18 18:38:14 +0100 (Mon, 18 Dec 2006) | 1 line
Describe new methods in Queue module
........
r53053 | andrew.kuchling | 2006-12-18 20:22:24 +0100 (Mon, 18 Dec 2006) | 1 line
[Patch #1615868 by Lars Gustaebel] Use Py_off_t to fix BZ2File.seek() for offsets > 2Gb
........
r53057 | andrew.kuchling | 2006-12-18 22:29:07 +0100 (Mon, 18 Dec 2006) | 1 line
Fix markup
........
r53063 | thomas.wouters | 2006-12-19 09:17:50 +0100 (Tue, 19 Dec 2006) | 5 lines
Make sre's SubPattern objects accept slice objects like it already accepts
simple slices.
........
r53065 | andrew.kuchling | 2006-12-19 15:13:05 +0100 (Tue, 19 Dec 2006) | 6 lines
[Patch #1618455 by Ben Maurer] Improve speed of HMAC by using str.translate()
instead of a more general XOR that has to construct a list.
Slightly modified from Maurer's patch: the _strxor() function is no longer
necessary at all.
........
r53066 | andrew.kuchling | 2006-12-19 15:28:23 +0100 (Tue, 19 Dec 2006) | 9 lines
[Bug #1613651] Document socket.recv_into, socket.recvfrom_into
Also, the text for recvfrom told you to read recv() for an explanation of the
'flags' argument, but recv() just pointed you at the man page. Copied the
man-page text to recvfrom(), recvfrom_into, recv_into to avoid the pointless
redirection.
I don't have LaTeX on this machine; hope my markup is OK.
........
r53067 | andrew.kuchling | 2006-12-19 15:29:04 +0100 (Tue, 19 Dec 2006) | 1 line
Comment typo
........
r53068 | andrew.kuchling | 2006-12-19 16:11:41 +0100 (Tue, 19 Dec 2006) | 1 line
[Patch #1617413 from Dug Song] Fix HTTP Basic authentication via HTTPS
........
r53071 | andrew.kuchling | 2006-12-19 16:18:12 +0100 (Tue, 19 Dec 2006) | 1 line
[Patch #1600491 from Jim Jewett] Describe how to build help files on Windows
........
r53073 | andrew.kuchling | 2006-12-19 16:43:10 +0100 (Tue, 19 Dec 2006) | 6 lines
[Patch #1587139 by kxroberto] Protect lock acquisition/release with
try...finally to ensure the lock is always released. This could use
the 'with' statement, but the patch uses 'finally'.
2.5 backport candidate.
........
r53074 | vinay.sajip | 2006-12-19 19:29:11 +0100 (Tue, 19 Dec 2006) | 1 line
Updated documentation for findCaller() to indicate that a 3-tuple is now returned, rather than a 2-tuple.
........
r53090 | georg.brandl | 2006-12-19 23:06:46 +0100 (Tue, 19 Dec 2006) | 3 lines
Patch #1484695: The tarfile module now raises a HeaderError exception
if a buffer given to frombuf() is invalid.
........
r53099 | raymond.hettinger | 2006-12-20 07:42:06 +0100 (Wed, 20 Dec 2006) | 5 lines
Bug #1590891: random.randrange don't return correct value for big number
Needs to be backported.
........
r53106 | georg.brandl | 2006-12-20 12:55:16 +0100 (Wed, 20 Dec 2006) | 3 lines
Testcase for patch #1484695.
........
r53110 | andrew.kuchling | 2006-12-20 20:48:20 +0100 (Wed, 20 Dec 2006) | 17 lines
[Apply length-checking.diff from bug #1599254]
Add length checking to single-file mailbox formats: before doing a
flush() on a mailbox, seek to the end and verify its length is
unchanged, raising ExternalClashError if the file's length has
changed.
This fix avoids potential data loss if some other process appends to
the mailbox file after the table of contents has been generated;
instead of overwriting the modified file, you'll get the exception.
I also noticed that the self._lookup() call in self.flush() wasn't
necessary (everything that sets self._pending to True also calls
self.lookup()), and replaced it by an assertion.
2.5 backport candidate.
........
r53112 | andrew.kuchling | 2006-12-20 20:57:10 +0100 (Wed, 20 Dec 2006) | 1 line
[Bug #1619674] Make sum() use the term iterable, not sequence
........
r53113 | andrew.kuchling | 2006-12-20 20:58:11 +0100 (Wed, 20 Dec 2006) | 1 line
Two grammar fixes
........
r53115 | andrew.kuchling | 2006-12-20 21:11:12 +0100 (Wed, 20 Dec 2006) | 5 lines
Some other built-in functions are described with 'sequence' arguments
that should really be 'iterable'; this commit changes them.
Did I miss any? Did I introduce any errors?
........
r53117 | andrew.kuchling | 2006-12-20 21:20:42 +0100 (Wed, 20 Dec 2006) | 1 line
[Bug #1619680] in_dll() arguments are documented in the wrong order
........
r53120 | neal.norwitz | 2006-12-21 05:38:00 +0100 (Thu, 21 Dec 2006) | 1 line
Lars asked for permission on on python-dev for work on tarfile.py
........
r53125 | andrew.kuchling | 2006-12-21 14:40:29 +0100 (Thu, 21 Dec 2006) | 1 line
Mention the os.SEEK_* constants
........
r53129 | walter.doerwald | 2006-12-21 19:06:30 +0100 (Thu, 21 Dec 2006) | 2 lines
Fix typo.
........
r53131 | thomas.heller | 2006-12-21 19:30:56 +0100 (Thu, 21 Dec 2006) | 3 lines
Fix wrong markup of an argument in a method signature.
Will backport.
........
r53137 | andrew.kuchling | 2006-12-22 01:50:56 +0100 (Fri, 22 Dec 2006) | 1 line
Typo fix
........
r53139 | andrew.kuchling | 2006-12-22 14:25:02 +0100 (Fri, 22 Dec 2006) | 1 line
[Bug #737202; fix from Titus Brown] Make CGIHTTPServer work for scripts in sub-directories
........
r53141 | andrew.kuchling | 2006-12-22 16:04:45 +0100 (Fri, 22 Dec 2006) | 6 lines
[Bug #802128] Make the mode argument of dumbdbm actually work the way it's
described, and add a test for it.
2.5 bugfix candidate, maybe; arguably this patch changes the API of
dumbdbm and shouldn't be added in a point-release.
........
r53142 | andrew.kuchling | 2006-12-22 16:16:58 +0100 (Fri, 22 Dec 2006) | 6 lines
[Bug #802128 continued] Modify mode depending on the process umask.
Is there really no other way to read the umask than to set it?
Hope this works on Windows...
........
r53145 | andrew.kuchling | 2006-12-22 17:43:26 +0100 (Fri, 22 Dec 2006) | 1 line
[Bug #776202] Apply Walter Doerwald's patch to use text mode for encoded files
........
r53146 | andrew.kuchling | 2006-12-22 19:41:42 +0100 (Fri, 22 Dec 2006) | 9 lines
[Patch #783050 from Patrick Lynch] The emulation of forkpty() is incorrect;
the master should close the slave fd.
Added a test to test_pty.py that reads from the master_fd after doing
a pty.fork(); without the fix it hangs forever instead of raising an
exception. (<crossing fingers for the buildbots>)
2.5 backport candidate.
........
r53147 | andrew.kuchling | 2006-12-22 20:06:16 +0100 (Fri, 22 Dec 2006) | 1 line
[Patch #827559 from Chris Gonnerman] Make SimpleHTTPServer redirect when a directory URL is missing the trailing slash; this lets relative links work.
........
r53149 | andrew.kuchling | 2006-12-22 20:21:27 +0100 (Fri, 22 Dec 2006) | 1 line
Darn; this test works when you run test_pty.py directly, but fails when regrtest runs it (the os.read() raises os.error). I can't figure out the cause, so am commenting out the test.
........
r53150 | andrew.kuchling | 2006-12-22 22:48:19 +0100 (Fri, 22 Dec 2006) | 1 line
Frak; this test also fails
........
r53153 | lars.gustaebel | 2006-12-23 17:40:13 +0100 (Sat, 23 Dec 2006) | 5 lines
Patch #1230446: tarfile.py: fix ExFileObject so that read() and tell()
work correctly together with readline().
Will backport to 2.5.
........
r53155 | lars.gustaebel | 2006-12-23 18:57:23 +0100 (Sat, 23 Dec 2006) | 5 lines
Patch #1262036: Prevent TarFiles from being added to themselves under
certain conditions.
Will backport to 2.5.
........
r53159 | andrew.kuchling | 2006-12-27 04:25:31 +0100 (Wed, 27 Dec 2006) | 4 lines
[Part of patch #1182394] Move the HMAC blocksize to be a class-level
constant; this allows changing it in a subclass. To accommodate this,
copy() now uses __class__. Also add some text to a comment.
........
r53160 | andrew.kuchling | 2006-12-27 04:31:24 +0100 (Wed, 27 Dec 2006) | 1 line
[Rest of patch #1182394] Add ._current() method so that we can use the written-in-C .hexdigest() method
........
r53161 | lars.gustaebel | 2006-12-27 11:30:46 +0100 (Wed, 27 Dec 2006) | 4 lines
Patch #1504073: Fix tarfile.open() for mode "r" with a fileobj argument.
Will backport to 2.5.
........
r53165 | neal.norwitz | 2006-12-28 05:39:20 +0100 (Thu, 28 Dec 2006) | 1 line
Remove a stray (old) macro name left around (I guess)
........
r53188 | neal.norwitz | 2006-12-29 04:01:53 +0100 (Fri, 29 Dec 2006) | 1 line
SF bug #1623890, fix argument name in docstring
........
r53200 | raymond.hettinger | 2006-12-30 05:01:17 +0100 (Sat, 30 Dec 2006) | 1 line
For sets with cyclical reprs, emit an ellipsis instead of infinitely recursing.
........
r53232 | brett.cannon | 2007-01-04 01:23:49 +0100 (Thu, 04 Jan 2007) | 3 lines
Add EnvironmentVarGuard to test.test_support. Provides a context manager to
temporarily set or unset environment variables.
........
r53235 | neal.norwitz | 2007-01-04 07:25:31 +0100 (Thu, 04 Jan 2007) | 1 line
SF #1627373, fix typo in CarbonEvt.
........
r53244 | raymond.hettinger | 2007-01-04 18:53:34 +0100 (Thu, 04 Jan 2007) | 1 line
Fix stability of heapq's nlargest() and nsmallest().
........
r53249 | martin.v.loewis | 2007-01-04 22:06:12 +0100 (Thu, 04 Jan 2007) | 3 lines
Bug #1566280: Explicitly invoke threading._shutdown from Py_Main,
to avoid relying on atexit.
Will backport to 2.5.
........
r53252 | gregory.p.smith | 2007-01-05 02:59:42 +0100 (Fri, 05 Jan 2007) | 3 lines
Support linking of the bsddb module against BerkeleyDB 4.5.x
(will backport to 2.5)
........
r53253 | gregory.p.smith | 2007-01-05 03:06:17 +0100 (Fri, 05 Jan 2007) | 2 lines
bump module version to match supported berkeleydb version
........
r53255 | neal.norwitz | 2007-01-05 06:25:22 +0100 (Fri, 05 Jan 2007) | 6 lines
Prevent crash on shutdown which can occur if we are finalizing
and the module dict has been cleared already and some object
raises a warning (like in a __del__).
Will backport.
........
r53258 | gregory.p.smith | 2007-01-05 08:21:35 +0100 (Fri, 05 Jan 2007) | 2 lines
typo fix
........
r53260 | neal.norwitz | 2007-01-05 09:06:43 +0100 (Fri, 05 Jan 2007) | 1 line
Add Collin Winter for access to update PEP 3107
........
r53262 | andrew.kuchling | 2007-01-05 15:22:17 +0100 (Fri, 05 Jan 2007) | 1 line
[Bug #1622533] Make docstrings raw strings because they contain control characters (\0, \1)
........
r53264 | andrew.kuchling | 2007-01-05 16:51:24 +0100 (Fri, 05 Jan 2007) | 1 line
[Patch #1520904] Fix bsddb tests to write to the temp directory instead of the Lib/bsddb/test directory
........
r53279 | brett.cannon | 2007-01-05 22:45:09 +0100 (Fri, 05 Jan 2007) | 3 lines
Silence a warning from gcc 4.0.1 by specifying a function's parameter list is
'void' instead of just a set of empty parentheses.
........
r53285 | raymond.hettinger | 2007-01-06 02:14:41 +0100 (Sat, 06 Jan 2007) | 2 lines
SF# 1409443: Expand comment to cover the interaction between f->f_lasti and the PREDICT macros.
........
r53286 | anthony.baxter | 2007-01-06 05:45:54 +0100 (Sat, 06 Jan 2007) | 1 line
update to (c) years to include 2007
........
r53291 | neal.norwitz | 2007-01-06 22:24:35 +0100 (Sat, 06 Jan 2007) | 1 line
Add Josiah to SF for maintaining asyncore/asynchat
........
r53293 | peter.astrand | 2007-01-07 09:53:46 +0100 (Sun, 07 Jan 2007) | 1 line
Re-implemented fix for #1531862 once again, in a way that works with Python 2.2. Fixes bug #1603424.
........
r53295 | peter.astrand | 2007-01-07 15:34:16 +0100 (Sun, 07 Jan 2007) | 1 line
Avoid O(N**2) bottleneck in _communicate_(). Fixes #1598181.
........
r53300 | raymond.hettinger | 2007-01-08 19:09:20 +0100 (Mon, 08 Jan 2007) | 1 line
Fix zero-length corner case for iterating over a mutating deque.
........
r53301 | vinay.sajip | 2007-01-08 19:50:32 +0100 (Mon, 08 Jan 2007) | 4 lines
Bare except clause removed from SMTPHandler.emit(). Now, only ImportError is trapped.
Bare except clause removed from SocketHandler.createSocket(). Now, only socket.error is trapped.
(SF #411881)
........
r53302 | vinay.sajip | 2007-01-08 19:51:46 +0100 (Mon, 08 Jan 2007) | 2 lines
Bare except clause removed from LogRecord.__init__. Now, only ValueError, TypeError and AttributeError are trapped.
(SF #411881)
........
r53303 | vinay.sajip | 2007-01-08 19:52:36 +0100 (Mon, 08 Jan 2007) | 1 line
Added entries about removal of some bare except clauses from logging.
........
2007-01-09 19:18:33 -04:00
|
|
|
if hasattr(self._os, 'chmod'):
|
|
|
|
self._os.chmod(file, self._mode)
|
2001-12-21 01:13:37 -04:00
|
|
|
|
2013-11-17 01:59:51 -04:00
|
|
|
def __enter__(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __exit__(self, *args):
|
|
|
|
self.close()
|
|
|
|
|
1995-08-10 16:29:28 -03:00
|
|
|
|
2014-06-10 15:16:00 -03:00
|
|
|
def open(file, flag='c', mode=0o666):
|
2002-05-29 13:18:42 -03:00
|
|
|
"""Open the database file, filename, and return corresponding object.
|
|
|
|
|
|
|
|
The flag argument, used to control how the database is opened in the
|
2014-06-10 15:16:00 -03:00
|
|
|
other DBM implementations, supports only the semantics of 'c' and 'n'
|
|
|
|
values. Other values will default to the semantics of 'c' value:
|
|
|
|
the database will always opened for update and will be created if it
|
|
|
|
does not exist.
|
2002-05-29 13:18:42 -03:00
|
|
|
|
|
|
|
The optional mode argument is the UNIX mode of the file, used only when
|
Merged revisions 55817-55961 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
................
r55837 | guido.van.rossum | 2007-06-08 16:04:42 -0700 (Fri, 08 Jun 2007) | 2 lines
PEP 3119 -- the abc module.
................
r55838 | guido.van.rossum | 2007-06-08 17:38:55 -0700 (Fri, 08 Jun 2007) | 2 lines
Implement part of PEP 3119 -- One Trick Ponies.
................
r55847 | guido.van.rossum | 2007-06-09 08:28:06 -0700 (Sat, 09 Jun 2007) | 2 lines
Different way to do one trick ponies, allowing registration (per PEP strawman).
................
r55849 | guido.van.rossum | 2007-06-09 18:06:38 -0700 (Sat, 09 Jun 2007) | 3 lines
Make sure that the magic looking for __hash__ (etc.) doesn't apply to
real subclasses of Hashable.
................
r55852 | guido.van.rossum | 2007-06-10 08:29:51 -0700 (Sun, 10 Jun 2007) | 2 lines
Add some more examples, e.g. generators and dict views.
................
r55853 | guido.van.rossum | 2007-06-10 08:31:59 -0700 (Sun, 10 Jun 2007) | 2 lines
keys() and items() *are* containers -- just values() isn't.
................
r55864 | georg.brandl | 2007-06-10 15:29:40 -0700 (Sun, 10 Jun 2007) | 2 lines
PEP 3127: new octal literals, binary literals.
................
r55865 | georg.brandl | 2007-06-10 15:31:37 -0700 (Sun, 10 Jun 2007) | 2 lines
Some octal literal fixes in Tools.
................
r55866 | georg.brandl | 2007-06-10 15:37:43 -0700 (Sun, 10 Jun 2007) | 2 lines
Tokenizer changes for PEP 3127.
................
r55867 | georg.brandl | 2007-06-10 15:37:55 -0700 (Sun, 10 Jun 2007) | 2 lines
Some docs for PEP 3127.
................
r55868 | georg.brandl | 2007-06-10 15:44:39 -0700 (Sun, 10 Jun 2007) | 2 lines
Missed a place in intobject.c. Is that used anymore anyway?
................
r55871 | neal.norwitz | 2007-06-10 18:31:49 -0700 (Sun, 10 Jun 2007) | 182 lines
Merged revisions 55729-55868 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r55731 | neal.norwitz | 2007-06-01 00:29:12 -0700 (Fri, 01 Jun 2007) | 7 lines
SF 1668596/1720897: distutils now copies data files
even if package_dir is empty.
This needs to be backported. I'm too tired tonight. It would be great
if someone backports this if the buildbots are ok with it. Otherwise,
I will try to get to it tomorrow.
........
r55732 | georg.brandl | 2007-06-01 04:33:33 -0700 (Fri, 01 Jun 2007) | 2 lines
Bug #1722484: remove docstrings again when running with -OO.
........
r55735 | georg.brandl | 2007-06-01 12:20:27 -0700 (Fri, 01 Jun 2007) | 2 lines
Fix wrong issue number.
........
r55739 | brett.cannon | 2007-06-01 20:02:29 -0700 (Fri, 01 Jun 2007) | 3 lines
Have configure raise an error when building on AtheOS. Code specific to AtheOS
will be removed in Python 2.7.
........
r55746 | neal.norwitz | 2007-06-02 11:33:53 -0700 (Sat, 02 Jun 2007) | 1 line
Update expected birthday of 2.6
........
r55751 | neal.norwitz | 2007-06-03 13:32:50 -0700 (Sun, 03 Jun 2007) | 10 lines
Backout the original 'fix' to 1721309 which had no effect.
Different versions of Berkeley DB handle this differently.
The comments and bug report should have the details. Memory is allocated
in 4.4 (and presumably earlier), but not in 4.5. Thus
4.5 has the free error, but not earlier versions.
Mostly update comments, plus make the free conditional.
This fix was already applied to the 2.5 branch.
........
r55752 | brett.cannon | 2007-06-03 16:13:41 -0700 (Sun, 03 Jun 2007) | 6 lines
Make _strptime.TimeRE().pattern() use ``\s+`` for matching whitespace instead
of ``\s*``. This prevents patterns from "stealing" bits from other patterns in
order to make a match work.
Closes bug #1730389. Will be backported.
........
r55766 | hyeshik.chang | 2007-06-05 11:16:52 -0700 (Tue, 05 Jun 2007) | 4 lines
Fix build on FreeBSD. Bluetooth HCI API in FreeBSD is quite different
from Linux's. Just fix the build for now but the code doesn't
support the complete capability of HCI on FreeBSD yet.
........
r55770 | hyeshik.chang | 2007-06-05 11:58:51 -0700 (Tue, 05 Jun 2007) | 4 lines
Bug #1728403: Fix a bug that CJKCodecs StreamReader hangs when it
reads a file that ends with incomplete sequence and sizehint argument
for .read() is specified.
........
r55775 | hyeshik.chang | 2007-06-05 12:28:15 -0700 (Tue, 05 Jun 2007) | 2 lines
Fix for Windows: close a temporary file before trying to delete it.
........
r55783 | guido.van.rossum | 2007-06-05 14:24:47 -0700 (Tue, 05 Jun 2007) | 2 lines
Patch by Tim Delany (missing DECREF). SF #1731330.
........
r55785 | collin.winter | 2007-06-05 17:17:35 -0700 (Tue, 05 Jun 2007) | 3 lines
Patch #1731049: make threading.py use a proper "raise" when checking internal state, rather than assert statements (which get stripped out by -O).
........
r55786 | facundo.batista | 2007-06-06 08:13:37 -0700 (Wed, 06 Jun 2007) | 4 lines
FTP.ntransfercmd method now uses create_connection when passive,
using the timeout received in connection time.
........
r55792 | facundo.batista | 2007-06-06 10:15:23 -0700 (Wed, 06 Jun 2007) | 7 lines
Added an optional timeout parameter to function urllib2.urlopen,
with tests in test_urllib2net.py (must have network resource
enabled to execute them). Also modified test_urllib2.py because
testing mock classes must take it into acount. Docs are also
updated.
........
r55793 | thomas.heller | 2007-06-06 13:19:19 -0700 (Wed, 06 Jun 2007) | 1 line
Build _ctypes and _ctypes_test in the ReleaseAMD64 configuration.
........
r55802 | georg.brandl | 2007-06-07 06:23:24 -0700 (Thu, 07 Jun 2007) | 3 lines
Disallow function calls like foo(None=1).
Backport from py3k rev. 55708 by Guido.
........
r55804 | georg.brandl | 2007-06-07 06:30:24 -0700 (Thu, 07 Jun 2007) | 2 lines
Make reindent.py executable.
........
r55805 | georg.brandl | 2007-06-07 06:34:10 -0700 (Thu, 07 Jun 2007) | 2 lines
Patch #1667860: Fix UnboundLocalError in urllib2.
........
r55821 | kristjan.jonsson | 2007-06-07 16:53:49 -0700 (Thu, 07 Jun 2007) | 1 line
Fixing changes to getbuildinfo.c that broke linux builds
........
r55828 | thomas.heller | 2007-06-08 09:10:27 -0700 (Fri, 08 Jun 2007) | 1 line
Make this test work with older Python releases where struct has no 't' format character.
........
r55829 | martin.v.loewis | 2007-06-08 10:29:20 -0700 (Fri, 08 Jun 2007) | 3 lines
Bug #1733488: Fix compilation of bufferobject.c on AIX.
Will backport to 2.5.
........
r55831 | thomas.heller | 2007-06-08 11:20:09 -0700 (Fri, 08 Jun 2007) | 2 lines
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
with small modifications.
........
r55832 | thomas.heller | 2007-06-08 12:01:06 -0700 (Fri, 08 Jun 2007) | 1 line
Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls.
........
r55833 | thomas.heller | 2007-06-08 12:08:31 -0700 (Fri, 08 Jun 2007) | 2 lines
Fix wrong documentation, and correct the punktuation.
Closes [1700455].
........
r55834 | thomas.heller | 2007-06-08 12:14:23 -0700 (Fri, 08 Jun 2007) | 1 line
Fix warnings by using proper function prototype.
........
r55839 | neal.norwitz | 2007-06-08 20:36:34 -0700 (Fri, 08 Jun 2007) | 7 lines
Prevent expandtabs() on string and unicode objects from causing a segfault when
a large width is passed on 32-bit platforms. Found by Google.
It would be good for people to review this especially carefully and verify
I don't have an off by one error and there is no other way to cause overflow.
........
r55841 | neal.norwitz | 2007-06-08 21:48:22 -0700 (Fri, 08 Jun 2007) | 1 line
Use macro version of GET_SIZE to avoid Coverity warning (#150) about a possible error.
........
r55842 | martin.v.loewis | 2007-06-09 00:42:52 -0700 (Sat, 09 Jun 2007) | 3 lines
Patch #1733960: Allow T_LONGLONG to accept ints.
Will backport to 2.5.
........
r55843 | martin.v.loewis | 2007-06-09 00:58:05 -0700 (Sat, 09 Jun 2007) | 2 lines
Fix Windows build.
........
r55845 | martin.v.loewis | 2007-06-09 03:10:26 -0700 (Sat, 09 Jun 2007) | 2 lines
Provide LLONG_MAX for S390.
........
r55854 | thomas.heller | 2007-06-10 08:59:17 -0700 (Sun, 10 Jun 2007) | 4 lines
First version of build scripts for Windows/AMD64 (no external
components are built yet, and 'kill_python' is disabled).
........
r55855 | thomas.heller | 2007-06-10 10:55:51 -0700 (Sun, 10 Jun 2007) | 3 lines
For now, disable the _bsddb, _sqlite3, _ssl, _testcapi, _tkinter
modules in the ReleaseAMD64 configuration because they do not compile.
........
r55856 | thomas.heller | 2007-06-10 11:27:54 -0700 (Sun, 10 Jun 2007) | 1 line
Need to set the environment variables, otherwise devenv.com is not found.
........
r55860 | thomas.heller | 2007-06-10 14:01:17 -0700 (Sun, 10 Jun 2007) | 1 line
Revert commit 55855.
........
................
r55880 | neal.norwitz | 2007-06-10 22:07:36 -0700 (Sun, 10 Jun 2007) | 5 lines
Fix the refleak counter on test_collections. The ABC metaclass creates
a registry which must be cleared on each run. Otherwise, there *seem*
to be refleaks when there really aren't any. (The class is held within
the registry even though it's no longer needed.)
................
r55884 | neal.norwitz | 2007-06-10 22:46:33 -0700 (Sun, 10 Jun 2007) | 1 line
These tests have been removed, so they are no longer needed here
................
r55886 | georg.brandl | 2007-06-11 00:26:37 -0700 (Mon, 11 Jun 2007) | 3 lines
Optimize access to True and False in the compiler (if True)
and the peepholer (LOAD_NAME True).
................
r55905 | georg.brandl | 2007-06-11 10:02:26 -0700 (Mon, 11 Jun 2007) | 5 lines
Remove __oct__ and __hex__ and use __index__ for converting
non-ints before formatting in a base.
Add a bin() builtin.
................
r55906 | georg.brandl | 2007-06-11 10:04:44 -0700 (Mon, 11 Jun 2007) | 2 lines
int(x, 0) does not "guess".
................
r55907 | georg.brandl | 2007-06-11 10:05:47 -0700 (Mon, 11 Jun 2007) | 2 lines
Add a comment to explain that nb_oct and nb_hex are nonfunctional.
................
r55908 | guido.van.rossum | 2007-06-11 10:49:18 -0700 (Mon, 11 Jun 2007) | 2 lines
Get rid of unused imports and comment.
................
r55910 | guido.van.rossum | 2007-06-11 13:05:17 -0700 (Mon, 11 Jun 2007) | 2 lines
_Abstract.__new__ now requires either no arguments or __init__ overridden.
................
r55911 | guido.van.rossum | 2007-06-11 13:07:49 -0700 (Mon, 11 Jun 2007) | 7 lines
Move the collections ABCs to a separate file, _abcoll.py, in order to avoid
needing to import _collections.so during the bootstrap (this will become
apparent in the next submit of os.py).
Add (plain and mutable) ABCs for Set, Mapping, Sequence.
................
r55912 | guido.van.rossum | 2007-06-11 13:09:31 -0700 (Mon, 11 Jun 2007) | 2 lines
Rewrite the _Environ class to use the new collections ABCs.
................
r55913 | guido.van.rossum | 2007-06-11 13:59:45 -0700 (Mon, 11 Jun 2007) | 72 lines
Merged revisions 55869-55912 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r55869 | neal.norwitz | 2007-06-10 17:42:11 -0700 (Sun, 10 Jun 2007) | 1 line
Add Atul Varma for patch # 1667860
........
r55870 | neal.norwitz | 2007-06-10 18:22:03 -0700 (Sun, 10 Jun 2007) | 1 line
Ignore valgrind problems on Ubuntu from ld
........
r55872 | neal.norwitz | 2007-06-10 18:48:46 -0700 (Sun, 10 Jun 2007) | 2 lines
Ignore config.status.lineno which seems new (new autoconf?)
........
r55873 | neal.norwitz | 2007-06-10 19:14:39 -0700 (Sun, 10 Jun 2007) | 1 line
Prevent these tests from running on Win64 since they don\'t apply there either
........
r55874 | neal.norwitz | 2007-06-10 19:16:10 -0700 (Sun, 10 Jun 2007) | 5 lines
Fix a bug when there was a newline in the string expandtabs was called on.
This also catches another condition that can overflow.
Will backport.
........
r55879 | neal.norwitz | 2007-06-10 21:52:37 -0700 (Sun, 10 Jun 2007) | 1 line
Prevent hang if the port cannot be opened.
........
r55881 | neal.norwitz | 2007-06-10 22:28:45 -0700 (Sun, 10 Jun 2007) | 4 lines
Add all of the distuils modules that don't seem to have explicit tests. :-(
Move an import in mworkscompiler so that this module can be imported on
any platform. Hopefully this works on all platforms.
........
r55882 | neal.norwitz | 2007-06-10 22:35:10 -0700 (Sun, 10 Jun 2007) | 4 lines
SF #1734732, lower case the module names per PEP 8.
Will backport.
........
r55885 | neal.norwitz | 2007-06-10 23:16:48 -0700 (Sun, 10 Jun 2007) | 4 lines
Not sure why this only fails sometimes on Unix machines. Better
to disable it and only import msvccompiler on Windows since that's
the only place it can work anyways.
........
r55887 | neal.norwitz | 2007-06-11 00:29:43 -0700 (Mon, 11 Jun 2007) | 4 lines
Bug #1734723: Fix repr.Repr() so it doesn't ignore the maxtuple attribute.
Will backport
........
r55889 | neal.norwitz | 2007-06-11 00:36:24 -0700 (Mon, 11 Jun 2007) | 1 line
Reflow long line
........
r55896 | thomas.heller | 2007-06-11 08:58:33 -0700 (Mon, 11 Jun 2007) | 3 lines
Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
or "K" codes.
........
r55901 | facundo.batista | 2007-06-11 09:27:08 -0700 (Mon, 11 Jun 2007) | 5 lines
Added versionchanged flag to all the methods which received
a new optional timeout parameter, and a versionadded flag to
the socket.create_connection function.
........
................
r55914 | guido.van.rossum | 2007-06-11 14:19:50 -0700 (Mon, 11 Jun 2007) | 3 lines
New super() implementation, for PEP 3135 (though the PEP is not yet updated
to this design, and small tweaks may still be made later).
................
r55923 | guido.van.rossum | 2007-06-11 21:15:24 -0700 (Mon, 11 Jun 2007) | 4 lines
I'm guessing this module broke when Neal ripped out the types module --
it used 'list' both as a local variable and as the built-in list type.
Renamed the local variable since that was easier.
................
r55924 | guido.van.rossum | 2007-06-11 21:20:05 -0700 (Mon, 11 Jun 2007) | 5 lines
Change all occurrences of super(<thisclass>, <firstarg>) to super().
Seems to have worked, all the tests still pass.
Exception: test_descr and test_descrtut, which have tons of these
and are there to test the various usages.
................
r55939 | collin.winter | 2007-06-12 13:57:33 -0700 (Tue, 12 Jun 2007) | 1 line
Patch #1735485: remove StandardError from the exception hierarchy.
................
r55954 | neal.norwitz | 2007-06-12 21:56:32 -0700 (Tue, 12 Jun 2007) | 51 lines
Merged revisions 55913-55950 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r55926 | marc-andre.lemburg | 2007-06-12 02:09:58 -0700 (Tue, 12 Jun 2007) | 3 lines
Apply patch #1734945 to support TurboLinux as distribution.
........
r55927 | marc-andre.lemburg | 2007-06-12 02:26:49 -0700 (Tue, 12 Jun 2007) | 3 lines
Add patch #1726668: Windows Vista support.
........
r55929 | thomas.heller | 2007-06-12 08:36:22 -0700 (Tue, 12 Jun 2007) | 1 line
Checkout, but do not yet try to build, exernal sources.
........
r55930 | thomas.heller | 2007-06-12 09:08:27 -0700 (Tue, 12 Jun 2007) | 6 lines
Add bufferoverflowU.lib to the libraries needed by _ssl (is this the
right thing to do?).
Set the /XP64 /RETAIL build enviroment in the makefile when building
ReleaseAMD64.
........
r55931 | thomas.heller | 2007-06-12 09:23:19 -0700 (Tue, 12 Jun 2007) | 5 lines
Revert this change, since it breaks the win32 build:
Add bufferoverflowU.lib to the libraries needed by _ssl (is this the
right thing to do?).
........
r55934 | thomas.heller | 2007-06-12 10:28:31 -0700 (Tue, 12 Jun 2007) | 3 lines
Specify the bufferoverflowU.lib to the makefile on the command line
(for ReleaseAMD64 builds).
........
r55937 | thomas.heller | 2007-06-12 12:02:59 -0700 (Tue, 12 Jun 2007) | 3 lines
Add bufferoverflowU.lib to PCBuild\_bsddb.vcproj.
Build sqlite3.dll and bsddb.
........
r55938 | thomas.heller | 2007-06-12 12:56:12 -0700 (Tue, 12 Jun 2007) | 2 lines
Don't rebuild Berkeley DB if not needed (this was committed by accident).
........
r55948 | martin.v.loewis | 2007-06-12 20:42:19 -0700 (Tue, 12 Jun 2007) | 3 lines
Provide PY_LLONG_MAX on all systems having long long.
Will backport to 2.5.
........
................
r55959 | guido.van.rossum | 2007-06-13 09:22:41 -0700 (Wed, 13 Jun 2007) | 2 lines
Fix a compilation warning.
................
2007-06-13 15:07:49 -03:00
|
|
|
the database has to be created. It defaults to octal code 0o666 (and
|
2002-05-29 13:18:42 -03:00
|
|
|
will be modified by the prevailing umask).
|
|
|
|
|
|
|
|
"""
|
Merged revisions 53005-53303 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r53012 | walter.doerwald | 2006-12-12 22:55:31 +0100 (Tue, 12 Dec 2006) | 2 lines
Fix typo.
........
r53023 | brett.cannon | 2006-12-13 23:31:37 +0100 (Wed, 13 Dec 2006) | 2 lines
Remove an unneeded import of 'warnings'.
........
r53025 | brett.cannon | 2006-12-14 00:02:38 +0100 (Thu, 14 Dec 2006) | 2 lines
Remove unneeded imports of 'warnings'.
........
r53026 | brett.cannon | 2006-12-14 00:09:53 +0100 (Thu, 14 Dec 2006) | 4 lines
Add test.test_support.guard_warnings_filter . This function returns a context
manager that protects warnings.filter from being modified once the context is
exited.
........
r53029 | george.yoshida | 2006-12-14 03:22:44 +0100 (Thu, 14 Dec 2006) | 2 lines
Note that guard_warnings_filter was added in 2.6
........
r53031 | vinay.sajip | 2006-12-14 09:53:55 +0100 (Thu, 14 Dec 2006) | 1 line
Added news on recent changes to logging
........
r53032 | andrew.kuchling | 2006-12-14 19:57:53 +0100 (Thu, 14 Dec 2006) | 1 line
[Patch #1599256 from David Watson] check that os.fsync is available before using it
........
r53042 | kurt.kaiser | 2006-12-15 06:13:11 +0100 (Fri, 15 Dec 2006) | 6 lines
1. Avoid hang when encountering a duplicate in a completion list. Bug 1571112.
2. Duplicate some old entries from Python's NEWS to IDLE's NEWS.txt
M AutoCompleteWindow.py
M NEWS.txt
........
r53048 | andrew.kuchling | 2006-12-18 18:12:31 +0100 (Mon, 18 Dec 2006) | 1 line
[Bug #1618083] Add missing word; make a few grammar fixes
........
r53050 | andrew.kuchling | 2006-12-18 18:16:05 +0100 (Mon, 18 Dec 2006) | 1 line
Bump version
........
r53051 | andrew.kuchling | 2006-12-18 18:22:07 +0100 (Mon, 18 Dec 2006) | 1 line
[Bug #1616726] Fix description of generator.close(); if you raise some random exception, the exception is raised and doesn't trigger a RuntimeError
........
r53052 | andrew.kuchling | 2006-12-18 18:38:14 +0100 (Mon, 18 Dec 2006) | 1 line
Describe new methods in Queue module
........
r53053 | andrew.kuchling | 2006-12-18 20:22:24 +0100 (Mon, 18 Dec 2006) | 1 line
[Patch #1615868 by Lars Gustaebel] Use Py_off_t to fix BZ2File.seek() for offsets > 2Gb
........
r53057 | andrew.kuchling | 2006-12-18 22:29:07 +0100 (Mon, 18 Dec 2006) | 1 line
Fix markup
........
r53063 | thomas.wouters | 2006-12-19 09:17:50 +0100 (Tue, 19 Dec 2006) | 5 lines
Make sre's SubPattern objects accept slice objects like it already accepts
simple slices.
........
r53065 | andrew.kuchling | 2006-12-19 15:13:05 +0100 (Tue, 19 Dec 2006) | 6 lines
[Patch #1618455 by Ben Maurer] Improve speed of HMAC by using str.translate()
instead of a more general XOR that has to construct a list.
Slightly modified from Maurer's patch: the _strxor() function is no longer
necessary at all.
........
r53066 | andrew.kuchling | 2006-12-19 15:28:23 +0100 (Tue, 19 Dec 2006) | 9 lines
[Bug #1613651] Document socket.recv_into, socket.recvfrom_into
Also, the text for recvfrom told you to read recv() for an explanation of the
'flags' argument, but recv() just pointed you at the man page. Copied the
man-page text to recvfrom(), recvfrom_into, recv_into to avoid the pointless
redirection.
I don't have LaTeX on this machine; hope my markup is OK.
........
r53067 | andrew.kuchling | 2006-12-19 15:29:04 +0100 (Tue, 19 Dec 2006) | 1 line
Comment typo
........
r53068 | andrew.kuchling | 2006-12-19 16:11:41 +0100 (Tue, 19 Dec 2006) | 1 line
[Patch #1617413 from Dug Song] Fix HTTP Basic authentication via HTTPS
........
r53071 | andrew.kuchling | 2006-12-19 16:18:12 +0100 (Tue, 19 Dec 2006) | 1 line
[Patch #1600491 from Jim Jewett] Describe how to build help files on Windows
........
r53073 | andrew.kuchling | 2006-12-19 16:43:10 +0100 (Tue, 19 Dec 2006) | 6 lines
[Patch #1587139 by kxroberto] Protect lock acquisition/release with
try...finally to ensure the lock is always released. This could use
the 'with' statement, but the patch uses 'finally'.
2.5 backport candidate.
........
r53074 | vinay.sajip | 2006-12-19 19:29:11 +0100 (Tue, 19 Dec 2006) | 1 line
Updated documentation for findCaller() to indicate that a 3-tuple is now returned, rather than a 2-tuple.
........
r53090 | georg.brandl | 2006-12-19 23:06:46 +0100 (Tue, 19 Dec 2006) | 3 lines
Patch #1484695: The tarfile module now raises a HeaderError exception
if a buffer given to frombuf() is invalid.
........
r53099 | raymond.hettinger | 2006-12-20 07:42:06 +0100 (Wed, 20 Dec 2006) | 5 lines
Bug #1590891: random.randrange don't return correct value for big number
Needs to be backported.
........
r53106 | georg.brandl | 2006-12-20 12:55:16 +0100 (Wed, 20 Dec 2006) | 3 lines
Testcase for patch #1484695.
........
r53110 | andrew.kuchling | 2006-12-20 20:48:20 +0100 (Wed, 20 Dec 2006) | 17 lines
[Apply length-checking.diff from bug #1599254]
Add length checking to single-file mailbox formats: before doing a
flush() on a mailbox, seek to the end and verify its length is
unchanged, raising ExternalClashError if the file's length has
changed.
This fix avoids potential data loss if some other process appends to
the mailbox file after the table of contents has been generated;
instead of overwriting the modified file, you'll get the exception.
I also noticed that the self._lookup() call in self.flush() wasn't
necessary (everything that sets self._pending to True also calls
self.lookup()), and replaced it by an assertion.
2.5 backport candidate.
........
r53112 | andrew.kuchling | 2006-12-20 20:57:10 +0100 (Wed, 20 Dec 2006) | 1 line
[Bug #1619674] Make sum() use the term iterable, not sequence
........
r53113 | andrew.kuchling | 2006-12-20 20:58:11 +0100 (Wed, 20 Dec 2006) | 1 line
Two grammar fixes
........
r53115 | andrew.kuchling | 2006-12-20 21:11:12 +0100 (Wed, 20 Dec 2006) | 5 lines
Some other built-in functions are described with 'sequence' arguments
that should really be 'iterable'; this commit changes them.
Did I miss any? Did I introduce any errors?
........
r53117 | andrew.kuchling | 2006-12-20 21:20:42 +0100 (Wed, 20 Dec 2006) | 1 line
[Bug #1619680] in_dll() arguments are documented in the wrong order
........
r53120 | neal.norwitz | 2006-12-21 05:38:00 +0100 (Thu, 21 Dec 2006) | 1 line
Lars asked for permission on on python-dev for work on tarfile.py
........
r53125 | andrew.kuchling | 2006-12-21 14:40:29 +0100 (Thu, 21 Dec 2006) | 1 line
Mention the os.SEEK_* constants
........
r53129 | walter.doerwald | 2006-12-21 19:06:30 +0100 (Thu, 21 Dec 2006) | 2 lines
Fix typo.
........
r53131 | thomas.heller | 2006-12-21 19:30:56 +0100 (Thu, 21 Dec 2006) | 3 lines
Fix wrong markup of an argument in a method signature.
Will backport.
........
r53137 | andrew.kuchling | 2006-12-22 01:50:56 +0100 (Fri, 22 Dec 2006) | 1 line
Typo fix
........
r53139 | andrew.kuchling | 2006-12-22 14:25:02 +0100 (Fri, 22 Dec 2006) | 1 line
[Bug #737202; fix from Titus Brown] Make CGIHTTPServer work for scripts in sub-directories
........
r53141 | andrew.kuchling | 2006-12-22 16:04:45 +0100 (Fri, 22 Dec 2006) | 6 lines
[Bug #802128] Make the mode argument of dumbdbm actually work the way it's
described, and add a test for it.
2.5 bugfix candidate, maybe; arguably this patch changes the API of
dumbdbm and shouldn't be added in a point-release.
........
r53142 | andrew.kuchling | 2006-12-22 16:16:58 +0100 (Fri, 22 Dec 2006) | 6 lines
[Bug #802128 continued] Modify mode depending on the process umask.
Is there really no other way to read the umask than to set it?
Hope this works on Windows...
........
r53145 | andrew.kuchling | 2006-12-22 17:43:26 +0100 (Fri, 22 Dec 2006) | 1 line
[Bug #776202] Apply Walter Doerwald's patch to use text mode for encoded files
........
r53146 | andrew.kuchling | 2006-12-22 19:41:42 +0100 (Fri, 22 Dec 2006) | 9 lines
[Patch #783050 from Patrick Lynch] The emulation of forkpty() is incorrect;
the master should close the slave fd.
Added a test to test_pty.py that reads from the master_fd after doing
a pty.fork(); without the fix it hangs forever instead of raising an
exception. (<crossing fingers for the buildbots>)
2.5 backport candidate.
........
r53147 | andrew.kuchling | 2006-12-22 20:06:16 +0100 (Fri, 22 Dec 2006) | 1 line
[Patch #827559 from Chris Gonnerman] Make SimpleHTTPServer redirect when a directory URL is missing the trailing slash; this lets relative links work.
........
r53149 | andrew.kuchling | 2006-12-22 20:21:27 +0100 (Fri, 22 Dec 2006) | 1 line
Darn; this test works when you run test_pty.py directly, but fails when regrtest runs it (the os.read() raises os.error). I can't figure out the cause, so am commenting out the test.
........
r53150 | andrew.kuchling | 2006-12-22 22:48:19 +0100 (Fri, 22 Dec 2006) | 1 line
Frak; this test also fails
........
r53153 | lars.gustaebel | 2006-12-23 17:40:13 +0100 (Sat, 23 Dec 2006) | 5 lines
Patch #1230446: tarfile.py: fix ExFileObject so that read() and tell()
work correctly together with readline().
Will backport to 2.5.
........
r53155 | lars.gustaebel | 2006-12-23 18:57:23 +0100 (Sat, 23 Dec 2006) | 5 lines
Patch #1262036: Prevent TarFiles from being added to themselves under
certain conditions.
Will backport to 2.5.
........
r53159 | andrew.kuchling | 2006-12-27 04:25:31 +0100 (Wed, 27 Dec 2006) | 4 lines
[Part of patch #1182394] Move the HMAC blocksize to be a class-level
constant; this allows changing it in a subclass. To accommodate this,
copy() now uses __class__. Also add some text to a comment.
........
r53160 | andrew.kuchling | 2006-12-27 04:31:24 +0100 (Wed, 27 Dec 2006) | 1 line
[Rest of patch #1182394] Add ._current() method so that we can use the written-in-C .hexdigest() method
........
r53161 | lars.gustaebel | 2006-12-27 11:30:46 +0100 (Wed, 27 Dec 2006) | 4 lines
Patch #1504073: Fix tarfile.open() for mode "r" with a fileobj argument.
Will backport to 2.5.
........
r53165 | neal.norwitz | 2006-12-28 05:39:20 +0100 (Thu, 28 Dec 2006) | 1 line
Remove a stray (old) macro name left around (I guess)
........
r53188 | neal.norwitz | 2006-12-29 04:01:53 +0100 (Fri, 29 Dec 2006) | 1 line
SF bug #1623890, fix argument name in docstring
........
r53200 | raymond.hettinger | 2006-12-30 05:01:17 +0100 (Sat, 30 Dec 2006) | 1 line
For sets with cyclical reprs, emit an ellipsis instead of infinitely recursing.
........
r53232 | brett.cannon | 2007-01-04 01:23:49 +0100 (Thu, 04 Jan 2007) | 3 lines
Add EnvironmentVarGuard to test.test_support. Provides a context manager to
temporarily set or unset environment variables.
........
r53235 | neal.norwitz | 2007-01-04 07:25:31 +0100 (Thu, 04 Jan 2007) | 1 line
SF #1627373, fix typo in CarbonEvt.
........
r53244 | raymond.hettinger | 2007-01-04 18:53:34 +0100 (Thu, 04 Jan 2007) | 1 line
Fix stability of heapq's nlargest() and nsmallest().
........
r53249 | martin.v.loewis | 2007-01-04 22:06:12 +0100 (Thu, 04 Jan 2007) | 3 lines
Bug #1566280: Explicitly invoke threading._shutdown from Py_Main,
to avoid relying on atexit.
Will backport to 2.5.
........
r53252 | gregory.p.smith | 2007-01-05 02:59:42 +0100 (Fri, 05 Jan 2007) | 3 lines
Support linking of the bsddb module against BerkeleyDB 4.5.x
(will backport to 2.5)
........
r53253 | gregory.p.smith | 2007-01-05 03:06:17 +0100 (Fri, 05 Jan 2007) | 2 lines
bump module version to match supported berkeleydb version
........
r53255 | neal.norwitz | 2007-01-05 06:25:22 +0100 (Fri, 05 Jan 2007) | 6 lines
Prevent crash on shutdown which can occur if we are finalizing
and the module dict has been cleared already and some object
raises a warning (like in a __del__).
Will backport.
........
r53258 | gregory.p.smith | 2007-01-05 08:21:35 +0100 (Fri, 05 Jan 2007) | 2 lines
typo fix
........
r53260 | neal.norwitz | 2007-01-05 09:06:43 +0100 (Fri, 05 Jan 2007) | 1 line
Add Collin Winter for access to update PEP 3107
........
r53262 | andrew.kuchling | 2007-01-05 15:22:17 +0100 (Fri, 05 Jan 2007) | 1 line
[Bug #1622533] Make docstrings raw strings because they contain control characters (\0, \1)
........
r53264 | andrew.kuchling | 2007-01-05 16:51:24 +0100 (Fri, 05 Jan 2007) | 1 line
[Patch #1520904] Fix bsddb tests to write to the temp directory instead of the Lib/bsddb/test directory
........
r53279 | brett.cannon | 2007-01-05 22:45:09 +0100 (Fri, 05 Jan 2007) | 3 lines
Silence a warning from gcc 4.0.1 by specifying a function's parameter list is
'void' instead of just a set of empty parentheses.
........
r53285 | raymond.hettinger | 2007-01-06 02:14:41 +0100 (Sat, 06 Jan 2007) | 2 lines
SF# 1409443: Expand comment to cover the interaction between f->f_lasti and the PREDICT macros.
........
r53286 | anthony.baxter | 2007-01-06 05:45:54 +0100 (Sat, 06 Jan 2007) | 1 line
update to (c) years to include 2007
........
r53291 | neal.norwitz | 2007-01-06 22:24:35 +0100 (Sat, 06 Jan 2007) | 1 line
Add Josiah to SF for maintaining asyncore/asynchat
........
r53293 | peter.astrand | 2007-01-07 09:53:46 +0100 (Sun, 07 Jan 2007) | 1 line
Re-implemented fix for #1531862 once again, in a way that works with Python 2.2. Fixes bug #1603424.
........
r53295 | peter.astrand | 2007-01-07 15:34:16 +0100 (Sun, 07 Jan 2007) | 1 line
Avoid O(N**2) bottleneck in _communicate_(). Fixes #1598181.
........
r53300 | raymond.hettinger | 2007-01-08 19:09:20 +0100 (Mon, 08 Jan 2007) | 1 line
Fix zero-length corner case for iterating over a mutating deque.
........
r53301 | vinay.sajip | 2007-01-08 19:50:32 +0100 (Mon, 08 Jan 2007) | 4 lines
Bare except clause removed from SMTPHandler.emit(). Now, only ImportError is trapped.
Bare except clause removed from SocketHandler.createSocket(). Now, only socket.error is trapped.
(SF #411881)
........
r53302 | vinay.sajip | 2007-01-08 19:51:46 +0100 (Mon, 08 Jan 2007) | 2 lines
Bare except clause removed from LogRecord.__init__. Now, only ValueError, TypeError and AttributeError are trapped.
(SF #411881)
........
r53303 | vinay.sajip | 2007-01-08 19:52:36 +0100 (Mon, 08 Jan 2007) | 1 line
Added entries about removal of some bare except clauses from logging.
........
2007-01-09 19:18:33 -04:00
|
|
|
|
|
|
|
# Modify mode depending on the umask
|
|
|
|
try:
|
|
|
|
um = _os.umask(0)
|
|
|
|
_os.umask(um)
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
# Turn off any bits that are set in the umask
|
|
|
|
mode = mode & (~um)
|
2016-07-06 06:21:58 -03:00
|
|
|
if flag not in ('r', 'w', 'c', 'n'):
|
2018-02-05 16:47:31 -04:00
|
|
|
raise ValueError("Flag must be one of 'r', 'w', 'c', or 'n'")
|
2014-06-10 15:16:00 -03:00
|
|
|
return _Database(file, mode, flag=flag)
|