Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions semidbm/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@


DATA_OPEN_FLAGS = os.O_RDWR | os.O_CREAT | os.O_APPEND
DATA_OPEN_FLAGS_READONLY = os.O_RDONLY
if sys.platform.startswith('win'):
# On windows we need to specify that we should be
# reading the file as a binary file so it doesn't
# change any line ending characters.
DATA_OPEN_FLAGS = DATA_OPEN_FLAGS | os.O_BINARY
DATA_OPEN_FLAGS_READONLY = DATA_OPEN_FLAGS_READONLY | os.O_BINARY
8 changes: 7 additions & 1 deletion semidbm/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@


class _SemiDBM(object):

_data_open_flags = compat.DATA_OPEN_FLAGS

"""

:param dbdir: The directory containing the dbm files. If the directory
Expand All @@ -46,7 +49,7 @@ def _create_db_dir(self):
def _load_db(self):
self._create_db_dir()
self._index = self._load_index(self._data_filename)
self._data_fd = os.open(self._data_filename, compat.DATA_OPEN_FLAGS)
self._data_fd = os.open(self._data_filename, self._data_open_flags)
self._current_offset = os.lseek(self._data_fd, 0, os.SEEK_END)

def _load_index(self, filename):
Expand Down Expand Up @@ -231,6 +234,9 @@ def compact(self):


class _SemiDBMReadOnly(_SemiDBM):

_data_open_flags = compat.DATA_OPEN_FLAGS_READONLY

def __delitem__(self, key):
self._method_not_allowed('delitem')

Expand Down