From c947bbaa46d5ea5860a42004d479b8144e45e8e5 Mon Sep 17 00:00:00 2001 From: David Lai Date: Wed, 28 Apr 2021 13:10:50 +0800 Subject: [PATCH] fix deprecation warnings --- montydb/base.py | 9 +++++---- montydb/client.py | 4 ++-- montydb/engine/queries.py | 5 ++++- montydb/engine/weighted.py | 5 ++++- montydb/utils/io.py | 2 +- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/montydb/base.py b/montydb/base.py index a10009b..c8737ac 100644 --- a/montydb/base.py +++ b/montydb/base.py @@ -18,11 +18,12 @@ # Assembling crucial classes and functions form pymongo module, # some of them may modified by needs. +try: + from collections.abc import MutableMapping +except ImportError: + from collections import MutableMapping -from collections import ( - OrderedDict, - MutableMapping, -) +from collections import OrderedDict from .types import ( abc, iteritems, diff --git a/montydb/client.py b/montydb/client.py index fceb812..3d3d898 100644 --- a/montydb/client.py +++ b/montydb/client.py @@ -128,9 +128,9 @@ def get_database(self, name): """ # verify database name if platform.system() == "Windows": - is_invaild = set('/\. "$*<>:|?').intersection(set(name)) + is_invaild = set(r'/\. "$*<>:|?').intersection(set(name)) else: - is_invaild = set('/\. "$').intersection(set(name)) + is_invaild = set(r'/\. "$').intersection(set(name)) if is_invaild or not name: raise errors.OperationFailure("Invaild database name.") diff --git a/montydb/engine/queries.py b/montydb/engine/queries.py index c209118..9aff0a5 100644 --- a/montydb/engine/queries.py +++ b/montydb/engine/queries.py @@ -2,7 +2,10 @@ import re from copy import deepcopy from datetime import datetime -from collections import Mapping +try: + from collections.abc import MutableMapping +except ImportError: + from collections import MutableMapping from ..errors import OperationFailure diff --git a/montydb/engine/weighted.py b/montydb/engine/weighted.py index bfed83f..68e8a7e 100644 --- a/montydb/engine/weighted.py +++ b/montydb/engine/weighted.py @@ -1,6 +1,9 @@ from datetime import datetime -from collections import Mapping +try: + from collections.abc import Mapping +except ImportError: + from collections import Mapping from ..types import ( integer_types, diff --git a/montydb/utils/io.py b/montydb/utils/io.py index f218b88..9d5731d 100644 --- a/montydb/utils/io.py +++ b/montydb/utils/io.py @@ -210,7 +210,7 @@ class MongoQueryRecorder(object): def __init__(self, mongodb, namespace=None, user=None): self._mongodb = mongodb - self._namespace = namespace or {"$regex": mongodb.name + "\..*"} + self._namespace = namespace or {"$regex": mongodb.name + r"\..*"} self._user = user self._epoch = datetime(1970, 1, 1)