Fix PY2 error

This commit is contained in:
László Károlyi 2018-03-26 04:30:53 +02:00
parent 3c322a9552
commit f1861fc5e7
Signed by: karolyi
GPG Key ID: 2DCAF25E55735BFE
1 changed files with 6 additions and 1 deletions

View File

@ -29,6 +29,11 @@ except ImportError:
raise MissingDependency("The 'xapian' backend requires the installation of 'Xapian'. "
"Please refer to the documentation.")
if sys.version_info[0] == 2:
DirectoryExistsException = OSError
elif sys.version_info[0] == 3:
DirectoryExistsException = FileExistsError
class NotSupportedError(Exception):
"""
@ -196,7 +201,7 @@ class XapianSearchBackend(BaseSearchBackend):
if self.path != MEMORY_DB_NAME:
try:
os.makedirs(self.path)
except FileExistsError:
except DirectoryExistsException:
pass
self.flags = connection_options.get('FLAGS', DEFAULT_XAPIAN_FLAGS)