From 72cab9356df056edaa650654ff4c95f85ab4e6e6 Mon Sep 17 00:00:00 2001 From: Nikolai Matiushev Date: Tue, 15 May 2018 23:20:03 +0100 Subject: [PATCH] PYTHON-1556 Fix compatibility issues with Python >= 3.6 (#352) Use raw strings to avoid invalid escape sequence warnings in Python >= 3.6 --- pymongo/database.py | 4 ++-- test/test_cursor.py | 2 +- tools/benchmark.py | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pymongo/database.py b/pymongo/database.py index 0505064ec..b3abe6923 100644 --- a/pymongo/database.py +++ b/pymongo/database.py @@ -34,8 +34,8 @@ from pymongo.son_manipulator import SONManipulator from pymongo.write_concern import WriteConcern -_INDEX_REGEX = {"name": {"$regex": "^(?!.*\$)"}} -_SYSTEM_FILTER = {"filter": {"name": {"$regex": "^(?!system\.)"}}} +_INDEX_REGEX = {"name": {"$regex": r"^(?!.*\$)"}} +_SYSTEM_FILTER = {"filter": {"name": {"$regex": r"^(?!system\.)"}}} def _check_name(name): diff --git a/test/test_cursor.py b/test/test_cursor.py index 25b6ad472..737cfc438 100644 --- a/test/test_cursor.py +++ b/test/test_cursor.py @@ -1217,7 +1217,7 @@ class TestCursor(IntegrationTest): raise SkipTest("SERVER-4754 - This test uses profiling.") # MongoDB 3.1.5 changed the ns for commands. - regex = {'$regex': 'pymongo_test.(\$cmd|test)'} + regex = {'$regex': r'pymongo_test.(\$cmd|test)'} if client_context.version.at_least(3, 5, 8, -1): query_key = "command.comment" diff --git a/tools/benchmark.py b/tools/benchmark.py index 2bf2e6093..a0fc74a12 100644 --- a/tools/benchmark.py +++ b/tools/benchmark.py @@ -13,6 +13,7 @@ # limitations under the License. """MongoDB benchmarking suite.""" +from __future__ import print_function import time import sys @@ -87,7 +88,7 @@ def timed(name, function, args=[], setup=None): function(*args) times.append(time.time() - start) best_time = min(times) - print "%s%d" % (name + (60 - len(name)) * ".", per_trial / best_time) + print("{0:s}{1:d}".format(name + (60 - len(name)) * ".", per_trial / best_time)) return best_time