diff --git a/semidbm/compat.py b/semidbm/compat.py index 3785353..f467673 100644 --- a/semidbm/compat.py +++ b/semidbm/compat.py @@ -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 diff --git a/semidbm/db.py b/semidbm/db.py index 5530508..650bedc 100644 --- a/semidbm/db.py +++ b/semidbm/db.py @@ -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 @@ -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): @@ -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')