PYTHON-2133 Remove u prefixes from code
This commit is contained in:
parent
02abb6d584
commit
e17299ab2e
@ -54,12 +54,6 @@ _WRITE_CONCERN_ERROR = 64
|
||||
_COMMANDS = ('insert', 'update', 'delete')
|
||||
|
||||
|
||||
# These string literals are used when we create fake server return
|
||||
# documents client side. We use unicode literals in python 2.x to
|
||||
# match the actual return values from the server.
|
||||
_UOP = u"op"
|
||||
|
||||
|
||||
class _Run(object):
|
||||
"""Represents a batch of write operations.
|
||||
"""
|
||||
@ -123,7 +117,7 @@ def _merge_command(run, full_result, offset, result):
|
||||
idx = doc["index"] + offset
|
||||
replacement["index"] = run.index(idx)
|
||||
# Add the failed operation to the error document.
|
||||
replacement[_UOP] = run.ops[idx]
|
||||
replacement["op"] = run.ops[idx]
|
||||
full_result["writeErrors"].append(replacement)
|
||||
|
||||
wc_error = result.get("writeConcernError")
|
||||
|
||||
@ -52,7 +52,6 @@ from pymongo.results import (BulkWriteResult,
|
||||
UpdateResult)
|
||||
from pymongo.write_concern import WriteConcern
|
||||
|
||||
_UJOIN = u"%s.%s"
|
||||
_FIND_AND_MODIFY_DOC_FIELDS = {'value': 1}
|
||||
_HAYSTACK_MSG = (
|
||||
"geoHaystack indexes are deprecated as of MongoDB 4.4."
|
||||
@ -179,7 +178,7 @@ class Collection(common.BaseObject):
|
||||
|
||||
self.__database = database
|
||||
self.__name = name
|
||||
self.__full_name = _UJOIN % (self.__database.name, self.__name)
|
||||
self.__full_name = "%s.%s" % (self.__database.name, self.__name)
|
||||
if create or kwargs or collation:
|
||||
self.__create(kwargs, collation, session)
|
||||
|
||||
@ -272,7 +271,7 @@ class Collection(common.BaseObject):
|
||||
- `name`: the name of the collection to get
|
||||
"""
|
||||
if name.startswith('_'):
|
||||
full_name = _UJOIN % (self.__name, name)
|
||||
full_name = "%s.%s" % (self.__name, name)
|
||||
raise AttributeError(
|
||||
"Collection has no attribute %r. To access the %s"
|
||||
" collection, use database['%s']." % (
|
||||
@ -281,7 +280,7 @@ class Collection(common.BaseObject):
|
||||
|
||||
def __getitem__(self, name):
|
||||
return Collection(self.__database,
|
||||
_UJOIN % (self.__name, name),
|
||||
"%s.%s" % (self.__name, name),
|
||||
False,
|
||||
self.codec_options,
|
||||
self.read_preference,
|
||||
|
||||
@ -53,12 +53,11 @@ _RETRYABLE_ERROR_CODES = _NOT_MASTER_CODES | frozenset([
|
||||
9001, # SocketException
|
||||
262, # ExceededTimeLimit
|
||||
])
|
||||
_UUNDER = u"_"
|
||||
|
||||
|
||||
def _gen_index_name(keys):
|
||||
"""Generate an index name from the set of fields it is over."""
|
||||
return _UUNDER.join(["%s_%s" % item for item in keys])
|
||||
return "_".join(["%s_%s" % item for item in keys])
|
||||
|
||||
|
||||
def _index_list(key_or_list, direction=None):
|
||||
|
||||
@ -81,8 +81,6 @@ _FIELD_MAP = {
|
||||
'delete': 'deletes'
|
||||
}
|
||||
|
||||
_UJOIN = u"%s.%s"
|
||||
|
||||
_UNICODE_REPLACE_CODEC_OPTIONS = CodecOptions(
|
||||
unicode_decode_error_handler='replace')
|
||||
|
||||
@ -263,7 +261,7 @@ class _Query(object):
|
||||
self._as_command = None
|
||||
|
||||
def namespace(self):
|
||||
return _UJOIN % (self.db, self.coll)
|
||||
return "%s.%s" % (self.db, self.coll)
|
||||
|
||||
def use_command(self, sock_info, exhaust):
|
||||
use_find_cmd = False
|
||||
@ -346,7 +344,7 @@ class _Query(object):
|
||||
set_slave_ok, False, self.codec_options,
|
||||
ctx=sock_info.compression_context)
|
||||
return request_id, msg, size
|
||||
ns = _UJOIN % (self.db, "$cmd")
|
||||
ns = "%s.%s" % (self.db, "$cmd")
|
||||
ntoreturn = -1 # All DB commands return 1 document
|
||||
else:
|
||||
# OP_QUERY treats ntoreturn of -1 and 1 the same, return
|
||||
@ -393,7 +391,7 @@ class _GetMore(object):
|
||||
self._as_command = None
|
||||
|
||||
def namespace(self):
|
||||
return _UJOIN % (self.db, self.coll)
|
||||
return "%s.%s" % (self.db, self.coll)
|
||||
|
||||
def use_command(self, sock_info, exhaust):
|
||||
sock_info.validate_session(self.client, self.session)
|
||||
@ -435,7 +433,7 @@ class _GetMore(object):
|
||||
False, False, self.codec_options,
|
||||
ctx=sock_info.compression_context)
|
||||
return request_id, msg, size
|
||||
ns = _UJOIN % (self.db, "$cmd")
|
||||
ns = "%s.%s" % (self.db, "$cmd")
|
||||
return query(0, ns, 0, -1, spec, None, self.codec_options, ctx=ctx)
|
||||
|
||||
return get_more(ns, self.ntoreturn, self.cursor_id, ctx)
|
||||
|
||||
@ -24,7 +24,7 @@ except ImportError:
|
||||
if isinstance(data, str):
|
||||
raise TypeError(
|
||||
"The stringprep module is not available. Usernames and "
|
||||
"passwords must be ASCII strings.")
|
||||
"passwords must be instances of bytes.")
|
||||
return data
|
||||
else:
|
||||
HAVE_STRINGPREP = True
|
||||
@ -74,8 +74,8 @@ else:
|
||||
# commonly mapped to nothing characters to, well, nothing.
|
||||
in_table_c12 = stringprep.in_table_c12
|
||||
in_table_b1 = stringprep.in_table_b1
|
||||
data = u"".join(
|
||||
[u"\u0020" if in_table_c12(elt) else elt
|
||||
data = "".join(
|
||||
["\u0020" if in_table_c12(elt) else elt
|
||||
for elt in data if not in_table_b1(elt)])
|
||||
|
||||
# RFC3454 section 2, step 2 - Normalize
|
||||
|
||||
@ -83,7 +83,7 @@ def gen_unichar():
|
||||
|
||||
|
||||
def gen_unicode(gen_length):
|
||||
return lambda: u"".join([x for x in
|
||||
return lambda: "".join([x for x in
|
||||
gen_list(gen_unichar(), gen_length)() if
|
||||
x not in ".$"])
|
||||
|
||||
@ -116,7 +116,7 @@ def gen_regexp(gen_length):
|
||||
# TODO our patterns only consist of one letter.
|
||||
# this is because of a bug in CPython's regex equality testing,
|
||||
# which I haven't quite tracked down, so I'm just ignoring it...
|
||||
pattern = lambda: u"".join(gen_list(choose_lifted(u"a"), gen_length)())
|
||||
pattern = lambda: "".join(gen_list(choose_lifted("a"), gen_length)())
|
||||
|
||||
def gen_flags():
|
||||
flags = 0
|
||||
|
||||
@ -100,7 +100,7 @@ class TestBinary(unittest.TestCase):
|
||||
if platform.python_implementation() != "Jython":
|
||||
# Jython's memoryview accepts unicode strings...
|
||||
# https://bugs.jython.org/issue2784
|
||||
self.assertRaises(TypeError, Binary, u"hello")
|
||||
self.assertRaises(TypeError, Binary, "hello")
|
||||
|
||||
def test_subtype(self):
|
||||
one = Binary(b"hello")
|
||||
|
||||
@ -132,17 +132,17 @@ class TestBSON(unittest.TestCase):
|
||||
self.assertEqual(doc, decoder(encoder(doc)))
|
||||
|
||||
helper({})
|
||||
helper({"test": u"hello"})
|
||||
helper({"test": "hello"})
|
||||
self.assertTrue(isinstance(decoder(encoder(
|
||||
{"hello": "world"}))["hello"], str))
|
||||
helper({"mike": -10120})
|
||||
helper({"long": Int64(10)})
|
||||
helper({"really big long": 2147483648})
|
||||
helper({u"hello": 0.0013109})
|
||||
helper({"hello": 0.0013109})
|
||||
helper({"something": True})
|
||||
helper({"false": False})
|
||||
helper({"an array": [1, True, 3.8, u"world"]})
|
||||
helper({"an object": doc_class({"test": u"something"})})
|
||||
helper({"an array": [1, True, 3.8, "world"]})
|
||||
helper({"an object": doc_class({"test": "something"})})
|
||||
helper({"a binary": Binary(b"test", 100)})
|
||||
helper({"a binary": Binary(b"test", 128)})
|
||||
helper({"a binary": Binary(b"test", 254)})
|
||||
@ -191,7 +191,7 @@ class TestBSON(unittest.TestCase):
|
||||
|
||||
def test_basic_validation(self):
|
||||
self.assertRaises(TypeError, is_valid, 100)
|
||||
self.assertRaises(TypeError, is_valid, u"test")
|
||||
self.assertRaises(TypeError, is_valid, "test")
|
||||
self.assertRaises(TypeError, is_valid, 10.4)
|
||||
|
||||
self.assertInvalid(b"test")
|
||||
@ -277,22 +277,22 @@ class TestBSON(unittest.TestCase):
|
||||
qcheck.gen_string(qcheck.gen_range(0, 40)))
|
||||
|
||||
def test_basic_decode(self):
|
||||
self.assertEqual({"test": u"hello world"},
|
||||
self.assertEqual({"test": "hello world"},
|
||||
decode(b"\x1B\x00\x00\x00\x0E\x74\x65\x73\x74\x00\x0C"
|
||||
b"\x00\x00\x00\x68\x65\x6C\x6C\x6F\x20\x77\x6F"
|
||||
b"\x72\x6C\x64\x00\x00"))
|
||||
self.assertEqual([{"test": u"hello world"}, {}],
|
||||
self.assertEqual([{"test": "hello world"}, {}],
|
||||
decode_all(b"\x1B\x00\x00\x00\x0E\x74\x65\x73\x74"
|
||||
b"\x00\x0C\x00\x00\x00\x68\x65\x6C\x6C"
|
||||
b"\x6f\x20\x77\x6F\x72\x6C\x64\x00\x00"
|
||||
b"\x05\x00\x00\x00\x00"))
|
||||
self.assertEqual([{"test": u"hello world"}, {}],
|
||||
self.assertEqual([{"test": "hello world"}, {}],
|
||||
list(decode_iter(
|
||||
b"\x1B\x00\x00\x00\x0E\x74\x65\x73\x74"
|
||||
b"\x00\x0C\x00\x00\x00\x68\x65\x6C\x6C"
|
||||
b"\x6f\x20\x77\x6F\x72\x6C\x64\x00\x00"
|
||||
b"\x05\x00\x00\x00\x00")))
|
||||
self.assertEqual([{"test": u"hello world"}, {}],
|
||||
self.assertEqual([{"test": "hello world"}, {}],
|
||||
list(decode_file_iter(BytesIO(
|
||||
b"\x1B\x00\x00\x00\x0E\x74\x65\x73\x74"
|
||||
b"\x00\x0C\x00\x00\x00\x68\x65\x6C\x6C"
|
||||
@ -380,11 +380,11 @@ class TestBSON(unittest.TestCase):
|
||||
|
||||
self.assertEqual(encode({}), BSON(b"\x05\x00\x00\x00\x00"))
|
||||
self.assertEqual(encode({}), b"\x05\x00\x00\x00\x00")
|
||||
self.assertEqual(encode({"test": u"hello world"}),
|
||||
self.assertEqual(encode({"test": "hello world"}),
|
||||
b"\x1B\x00\x00\x00\x02\x74\x65\x73\x74\x00\x0C\x00"
|
||||
b"\x00\x00\x68\x65\x6C\x6C\x6F\x20\x77\x6F\x72\x6C"
|
||||
b"\x64\x00\x00")
|
||||
self.assertEqual(encode({u"mike": 100}),
|
||||
self.assertEqual(encode({"mike": 100}),
|
||||
b"\x0F\x00\x00\x00\x10\x6D\x69\x6B\x65\x00\x64\x00"
|
||||
b"\x00\x00\x00")
|
||||
self.assertEqual(encode({"hello": 1.5}),
|
||||
@ -433,7 +433,7 @@ class TestBSON(unittest.TestCase):
|
||||
b"=\x00\x00\x00\x0f$field\x000\x00\x00\x00\x1f\x00"
|
||||
b"\x00\x00return function(){ return x; }\x00\t\x00"
|
||||
b"\x00\x00\x08x\x00\x00\x00\x00")
|
||||
unicode_empty_scope = Code(u"function(){ return 'héllo';}", {})
|
||||
unicode_empty_scope = Code("function(){ return 'héllo';}", {})
|
||||
self.assertEqual(encode({'$field': unicode_empty_scope}),
|
||||
b"8\x00\x00\x00\x0f$field\x00+\x00\x00\x00\x1e\x00"
|
||||
b"\x00\x00function(){ return 'h\xc3\xa9llo';}\x00\x05"
|
||||
@ -660,10 +660,10 @@ class TestBSON(unittest.TestCase):
|
||||
self.assertRaises(InvalidDocument, encode, {8.9: "test"})
|
||||
|
||||
def test_utf8(self):
|
||||
w = {u"aéあ": u"aéあ"}
|
||||
w = {"aéあ": "aéあ"}
|
||||
self.assertEqual(w, decode(encode(w)))
|
||||
|
||||
# b'a\xe9' == u"aé".encode("iso-8859-1")
|
||||
# b'a\xe9' == "aé".encode("iso-8859-1")
|
||||
iso8859_bytes = b'a\xe9'
|
||||
y = {"hello": iso8859_bytes}
|
||||
# Stored as BSON binary subtype 0.
|
||||
@ -678,16 +678,16 @@ class TestBSON(unittest.TestCase):
|
||||
# This test doesn't make much sense in Python2
|
||||
# since {'a': '\x00'} == {'a': u'\x00'}.
|
||||
# Decoding here actually returns {'a': '\x00'}
|
||||
doc = {"a": u"\x00"}
|
||||
doc = {"a": "\x00"}
|
||||
self.assertEqual(doc, decode(encode(doc)))
|
||||
|
||||
self.assertRaises(InvalidDocument, encode, {b"\x00": "a"})
|
||||
self.assertRaises(InvalidDocument, encode, {u"\x00": "a"})
|
||||
self.assertRaises(InvalidDocument, encode, {"\x00": "a"})
|
||||
|
||||
self.assertRaises(InvalidDocument, encode,
|
||||
{"a": re.compile(b"ab\x00c")})
|
||||
self.assertRaises(InvalidDocument, encode,
|
||||
{"a": re.compile(u"ab\x00c")})
|
||||
{"a": re.compile("ab\x00c")})
|
||||
|
||||
def test_move_id(self):
|
||||
self.assertEqual(b"\x19\x00\x00\x00\x02_id\x00\x02\x00\x00\x00a\x00"
|
||||
@ -996,11 +996,11 @@ class TestCodecOptions(unittest.TestCase):
|
||||
|
||||
dec = decode(invalid_key,
|
||||
CodecOptions(unicode_decode_error_handler="replace"))
|
||||
self.assertEqual(dec, {replaced_key: u"foobar"})
|
||||
self.assertEqual(dec, {replaced_key: "foobar"})
|
||||
|
||||
dec = decode(invalid_key,
|
||||
CodecOptions(unicode_decode_error_handler="ignore"))
|
||||
self.assertEqual(dec, {ignored_key: u"foobar"})
|
||||
self.assertEqual(dec, {ignored_key: "foobar"})
|
||||
|
||||
self.assertRaises(InvalidBSON, decode, invalid_key, CodecOptions(
|
||||
unicode_decode_error_handler="strict"))
|
||||
@ -1014,11 +1014,11 @@ class TestCodecOptions(unittest.TestCase):
|
||||
|
||||
dec = decode(invalid_val,
|
||||
CodecOptions(unicode_decode_error_handler="replace"))
|
||||
self.assertEqual(dec, {u"keystr": replaced_val})
|
||||
self.assertEqual(dec, {"keystr": replaced_val})
|
||||
|
||||
dec = decode(invalid_val,
|
||||
CodecOptions(unicode_decode_error_handler="ignore"))
|
||||
self.assertEqual(dec, {u"keystr": ignored_val})
|
||||
self.assertEqual(dec, {"keystr": ignored_val})
|
||||
|
||||
self.assertRaises(InvalidBSON, decode, invalid_val, CodecOptions(
|
||||
unicode_decode_error_handler="strict"))
|
||||
|
||||
@ -712,8 +712,8 @@ class TestClient(IntegrationTest):
|
||||
self.assertEqual(["name"], list(doc))
|
||||
|
||||
def test_list_database_names(self):
|
||||
self.client.pymongo_test.test.insert_one({"dummy": u"object"})
|
||||
self.client.pymongo_test_mike.test.insert_one({"dummy": u"object"})
|
||||
self.client.pymongo_test.test.insert_one({"dummy": "object"})
|
||||
self.client.pymongo_test_mike.test.insert_one({"dummy": "object"})
|
||||
cmd_docs = self.client.admin.command("listDatabases")["databases"]
|
||||
cmd_names = [doc["name"] for doc in cmd_docs]
|
||||
|
||||
@ -726,8 +726,8 @@ class TestClient(IntegrationTest):
|
||||
self.assertRaises(TypeError, self.client.drop_database, 5)
|
||||
self.assertRaises(TypeError, self.client.drop_database, None)
|
||||
|
||||
self.client.pymongo_test.test.insert_one({"dummy": u"object"})
|
||||
self.client.pymongo_test2.test.insert_one({"dummy": u"object"})
|
||||
self.client.pymongo_test.test.insert_one({"dummy": "object"})
|
||||
self.client.pymongo_test2.test.insert_one({"dummy": "object"})
|
||||
dbs = self.client.list_database_names()
|
||||
self.assertIn("pymongo_test", dbs)
|
||||
self.assertIn("pymongo_test2", dbs)
|
||||
@ -1134,8 +1134,8 @@ class TestClient(IntegrationTest):
|
||||
uri += '/?replicaSet=' + client_context.replica_set_name
|
||||
|
||||
client = rs_or_single_client_noauth(uri)
|
||||
client.pymongo_test.test.insert_one({"dummy": u"object"})
|
||||
client.pymongo_test_bernie.test.insert_one({"dummy": u"object"})
|
||||
client.pymongo_test.test.insert_one({"dummy": "object"})
|
||||
client.pymongo_test_bernie.test.insert_one({"dummy": "object"})
|
||||
|
||||
dbs = client.list_database_names()
|
||||
self.assertTrue("pymongo_test" in dbs)
|
||||
|
||||
@ -28,11 +28,8 @@ class TestCode(unittest.TestCase):
|
||||
self.assertRaises(TypeError, Code, 5)
|
||||
self.assertRaises(TypeError, Code, None)
|
||||
self.assertRaises(TypeError, Code, "aoeu", 5)
|
||||
self.assertRaises(TypeError, Code, u"aoeu", 5)
|
||||
self.assertTrue(Code("aoeu"))
|
||||
self.assertTrue(Code(u"aoeu"))
|
||||
self.assertTrue(Code("aoeu", {}))
|
||||
self.assertTrue(Code(u"aoeu", {}))
|
||||
|
||||
def test_read_only(self):
|
||||
c = Code("blah")
|
||||
|
||||
@ -1197,7 +1197,7 @@ class TestCollection(IntegrationTest):
|
||||
self.assertEqual(obj["_id"], numeric)
|
||||
|
||||
for x in db.test.find():
|
||||
self.assertEqual(x["hello"], u"world")
|
||||
self.assertEqual(x["hello"], "world")
|
||||
self.assertTrue("_id" in x)
|
||||
|
||||
def test_invalid_key_names(self):
|
||||
@ -2085,11 +2085,11 @@ class TestCollection(IntegrationTest):
|
||||
def test_messages_with_unicode_collection_names(self):
|
||||
db = self.db
|
||||
|
||||
db[u"Employés"].insert_one({"x": 1})
|
||||
db[u"Employés"].replace_one({"x": 1}, {"x": 2})
|
||||
db[u"Employés"].delete_many({})
|
||||
db[u"Employés"].find_one()
|
||||
list(db[u"Employés"].find())
|
||||
db["Employés"].insert_one({"x": 1})
|
||||
db["Employés"].replace_one({"x": 1}, {"x": 2})
|
||||
db["Employés"].delete_many({})
|
||||
db["Employés"].find_one()
|
||||
list(db["Employés"].find())
|
||||
|
||||
def test_drop_indexes_non_existent(self):
|
||||
self.db.drop_collection("test")
|
||||
|
||||
@ -75,7 +75,7 @@ class TestDatabaseNoConnect(unittest.TestCase):
|
||||
self.assertRaises(InvalidName, Database, self.client, 'my"db')
|
||||
self.assertRaises(InvalidName, Database, self.client, "my\x00db")
|
||||
self.assertRaises(InvalidName, Database,
|
||||
self.client, u"my\u0000db")
|
||||
self.client, "my\u0000db")
|
||||
self.assertEqual("name", Database(self.client, "name").name)
|
||||
|
||||
def test_get_collection(self):
|
||||
@ -133,7 +133,7 @@ class TestDatabase(IntegrationTest):
|
||||
def test_repr(self):
|
||||
self.assertEqual(repr(Database(self.client, "pymongo_test")),
|
||||
"Database(%r, %s)" % (self.client,
|
||||
repr(u"pymongo_test")))
|
||||
repr("pymongo_test")))
|
||||
|
||||
def test_create_collection(self):
|
||||
db = Database(self.client, "pymongo_test")
|
||||
@ -148,19 +148,19 @@ class TestDatabase(IntegrationTest):
|
||||
self.assertRaises(InvalidName, db.create_collection, "coll..ection")
|
||||
|
||||
test = db.create_collection("test")
|
||||
self.assertTrue(u"test" in db.list_collection_names())
|
||||
test.insert_one({"hello": u"world"})
|
||||
self.assertTrue("test" in db.list_collection_names())
|
||||
test.insert_one({"hello": "world"})
|
||||
self.assertEqual(db.test.find_one()["hello"], "world")
|
||||
|
||||
db.drop_collection("test.foo")
|
||||
db.create_collection("test.foo")
|
||||
self.assertTrue(u"test.foo" in db.list_collection_names())
|
||||
self.assertTrue("test.foo" in db.list_collection_names())
|
||||
self.assertRaises(CollectionInvalid, db.create_collection, "test.foo")
|
||||
|
||||
def test_list_collection_names(self):
|
||||
db = Database(self.client, "pymongo_test")
|
||||
db.test.insert_one({"dummy": u"object"})
|
||||
db.test.mike.insert_one({"dummy": u"object"})
|
||||
db.test.insert_one({"dummy": "object"})
|
||||
db.test.mike.insert_one({"dummy": "object"})
|
||||
|
||||
colls = db.list_collection_names()
|
||||
self.assertTrue("test" in colls)
|
||||
@ -220,8 +220,8 @@ class TestDatabase(IntegrationTest):
|
||||
def test_list_collections(self):
|
||||
self.client.drop_database("pymongo_test")
|
||||
db = Database(self.client, "pymongo_test")
|
||||
db.test.insert_one({"dummy": u"object"})
|
||||
db.test.mike.insert_one({"dummy": u"object"})
|
||||
db.test.insert_one({"dummy": "object"})
|
||||
db.test.mike.insert_one({"dummy": "object"})
|
||||
|
||||
results = db.list_collections()
|
||||
colls = [result["name"] for result in results]
|
||||
@ -308,22 +308,22 @@ class TestDatabase(IntegrationTest):
|
||||
self.assertRaises(TypeError, db.drop_collection, 5)
|
||||
self.assertRaises(TypeError, db.drop_collection, None)
|
||||
|
||||
db.test.insert_one({"dummy": u"object"})
|
||||
db.test.insert_one({"dummy": "object"})
|
||||
self.assertTrue("test" in db.list_collection_names())
|
||||
db.drop_collection("test")
|
||||
self.assertFalse("test" in db.list_collection_names())
|
||||
|
||||
db.test.insert_one({"dummy": u"object"})
|
||||
db.test.insert_one({"dummy": "object"})
|
||||
self.assertTrue("test" in db.list_collection_names())
|
||||
db.drop_collection(u"test")
|
||||
db.drop_collection("test")
|
||||
self.assertFalse("test" in db.list_collection_names())
|
||||
|
||||
db.test.insert_one({"dummy": u"object"})
|
||||
db.test.insert_one({"dummy": "object"})
|
||||
self.assertTrue("test" in db.list_collection_names())
|
||||
db.drop_collection(db.test)
|
||||
self.assertFalse("test" in db.list_collection_names())
|
||||
|
||||
db.test.insert_one({"dummy": u"object"})
|
||||
db.test.insert_one({"dummy": "object"})
|
||||
self.assertTrue("test" in db.list_collection_names())
|
||||
db.test.drop()
|
||||
self.assertFalse("test" in db.list_collection_names())
|
||||
@ -343,7 +343,7 @@ class TestDatabase(IntegrationTest):
|
||||
self.assertRaises(TypeError, db.validate_collection, 5)
|
||||
self.assertRaises(TypeError, db.validate_collection, None)
|
||||
|
||||
db.test.insert_one({"dummy": u"object"})
|
||||
db.test.insert_one({"dummy": "object"})
|
||||
|
||||
self.assertRaises(OperationFailure, db.validate_collection,
|
||||
"test.doesnotexist")
|
||||
@ -360,7 +360,7 @@ class TestDatabase(IntegrationTest):
|
||||
@client_context.require_version_min(4, 3, 3)
|
||||
def test_validate_collection_background(self):
|
||||
db = self.client.pymongo_test
|
||||
db.test.insert_one({"dummy": u"object"})
|
||||
db.test.insert_one({"dummy": "object"})
|
||||
coll = db.test
|
||||
self.assertTrue(db.validate_collection(coll, background=False))
|
||||
# The inMemory storage engine does not support background=True.
|
||||
@ -509,11 +509,9 @@ class TestDatabase(IntegrationTest):
|
||||
self.assertTrue(isinstance(auth._password_digest("mike", "password"),
|
||||
str))
|
||||
self.assertEqual(auth._password_digest("mike", "password"),
|
||||
u"cd7e45b3b2767dc2fa9b6b548457ed00")
|
||||
self.assertEqual(auth._password_digest("mike", "password"),
|
||||
auth._password_digest(u"mike", u"password"))
|
||||
self.assertEqual(auth._password_digest("Gustave", u"Dor\xe9"),
|
||||
u"81e0e2364499209f466e75926a162d73")
|
||||
"cd7e45b3b2767dc2fa9b6b548457ed00")
|
||||
self.assertEqual(auth._password_digest("Gustave", "Dor\xe9"),
|
||||
"81e0e2364499209f466e75926a162d73")
|
||||
|
||||
@client_context.require_auth
|
||||
def test_authenticate_add_remove_user(self):
|
||||
@ -559,7 +557,7 @@ class TestDatabase(IntegrationTest):
|
||||
|
||||
if not client_context.version.at_least(3, 7, 2) or HAVE_STRINGPREP:
|
||||
# Unicode name and password.
|
||||
check_auth(u"mike", u"password")
|
||||
check_auth("mike", "password")
|
||||
|
||||
auth_db.remove_user("mike")
|
||||
self.assertRaises(
|
||||
@ -567,15 +565,15 @@ class TestDatabase(IntegrationTest):
|
||||
|
||||
# Add / authenticate / change password
|
||||
self.assertRaises(
|
||||
OperationFailure, check_auth, "Gustave", u"Dor\xe9")
|
||||
auth_db.add_user("Gustave", u"Dor\xe9", roles=["read"])
|
||||
check_auth("Gustave", u"Dor\xe9")
|
||||
OperationFailure, check_auth, "Gustave", "Dor\xe9")
|
||||
auth_db.add_user("Gustave", "Dor\xe9", roles=["read"])
|
||||
check_auth("Gustave", "Dor\xe9")
|
||||
|
||||
# Change password.
|
||||
auth_db.add_user("Gustave", "password", roles=["read"])
|
||||
self.assertRaises(
|
||||
OperationFailure, check_auth, "Gustave", u"Dor\xe9")
|
||||
check_auth("Gustave", u"password")
|
||||
OperationFailure, check_auth, "Gustave", "Dor\xe9")
|
||||
check_auth("Gustave", "password")
|
||||
|
||||
@client_context.require_auth
|
||||
@ignore_deprecations
|
||||
@ -796,18 +794,18 @@ class TestDatabase(IntegrationTest):
|
||||
db = self.client.pymongo_test
|
||||
db.test.drop()
|
||||
|
||||
a_doc = SON({"hello": u"world"})
|
||||
a_doc = SON({"hello": "world"})
|
||||
a_key = db.test.insert_one(a_doc).inserted_id
|
||||
self.assertTrue(isinstance(a_doc["_id"], ObjectId))
|
||||
self.assertEqual(a_doc["_id"], a_key)
|
||||
self.assertEqual(a_doc, db.test.find_one({"_id": a_doc["_id"]}))
|
||||
self.assertEqual(a_doc, db.test.find_one(a_key))
|
||||
self.assertEqual(None, db.test.find_one(ObjectId()))
|
||||
self.assertEqual(a_doc, db.test.find_one({"hello": u"world"}))
|
||||
self.assertEqual(None, db.test.find_one({"hello": u"test"}))
|
||||
self.assertEqual(a_doc, db.test.find_one({"hello": "world"}))
|
||||
self.assertEqual(None, db.test.find_one({"hello": "test"}))
|
||||
|
||||
b = db.test.find_one()
|
||||
b["hello"] = u"mike"
|
||||
b["hello"] = "mike"
|
||||
db.test.replace_one({"_id": b["_id"]}, b)
|
||||
|
||||
self.assertNotEqual(a_doc, db.test.find_one(a_key))
|
||||
|
||||
@ -36,9 +36,8 @@ class TestDBRef(unittest.TestCase):
|
||||
self.assertRaises(TypeError, DBRef, None, a)
|
||||
self.assertRaises(TypeError, DBRef, "coll", a, 5)
|
||||
self.assertTrue(DBRef("coll", a))
|
||||
self.assertTrue(DBRef(u"coll", a))
|
||||
self.assertTrue(DBRef(u"coll", 5))
|
||||
self.assertTrue(DBRef(u"coll", 5, "database"))
|
||||
self.assertTrue(DBRef("coll", 5))
|
||||
self.assertTrue(DBRef("coll", 5, "database"))
|
||||
|
||||
def test_read_only(self):
|
||||
a = DBRef("coll", ObjectId())
|
||||
@ -59,7 +58,7 @@ class TestDBRef(unittest.TestCase):
|
||||
self.assertEqual(repr(DBRef("coll",
|
||||
ObjectId("1234567890abcdef12345678"))),
|
||||
"DBRef('coll', ObjectId('1234567890abcdef12345678'))")
|
||||
self.assertEqual(repr(DBRef(u"coll",
|
||||
self.assertEqual(repr(DBRef("coll",
|
||||
ObjectId("1234567890abcdef12345678"))),
|
||||
"DBRef(%s, ObjectId('1234567890abcdef12345678'))"
|
||||
% (repr(u'coll'),)
|
||||
@ -75,23 +74,21 @@ class TestDBRef(unittest.TestCase):
|
||||
obj_id = ObjectId("1234567890abcdef12345678")
|
||||
|
||||
self.assertEqual(DBRef('foo', 5), DBRef('foo', 5))
|
||||
self.assertEqual(DBRef("coll", obj_id), DBRef(u"coll", obj_id))
|
||||
self.assertEqual(DBRef("coll", obj_id), DBRef("coll", obj_id))
|
||||
self.assertNotEqual(DBRef("coll", obj_id),
|
||||
DBRef(u"coll", obj_id, "foo"))
|
||||
DBRef("coll", obj_id, "foo"))
|
||||
self.assertNotEqual(DBRef("coll", obj_id), DBRef("col", obj_id))
|
||||
self.assertNotEqual(DBRef("coll", obj_id),
|
||||
DBRef("coll", ObjectId(b"123456789011")))
|
||||
self.assertNotEqual(DBRef("coll", obj_id), 4)
|
||||
self.assertEqual(DBRef("coll", obj_id, "foo"),
|
||||
DBRef(u"coll", obj_id, "foo"))
|
||||
self.assertNotEqual(DBRef("coll", obj_id, "foo"),
|
||||
DBRef(u"coll", obj_id, "bar"))
|
||||
DBRef("coll", obj_id, "bar"))
|
||||
|
||||
# Explicitly test inequality
|
||||
self.assertFalse(DBRef('foo', 5) != DBRef('foo', 5))
|
||||
self.assertFalse(DBRef("coll", obj_id) != DBRef(u"coll", obj_id))
|
||||
self.assertFalse(DBRef("coll", obj_id) != DBRef("coll", obj_id))
|
||||
self.assertFalse(DBRef("coll", obj_id, "foo") !=
|
||||
DBRef(u"coll", obj_id, "foo"))
|
||||
DBRef("coll", obj_id, "foo"))
|
||||
|
||||
def test_kwargs(self):
|
||||
self.assertEqual(DBRef("coll", 5, foo="bar"),
|
||||
|
||||
@ -506,21 +506,21 @@ Bye"""))
|
||||
|
||||
def test_write_unicode(self):
|
||||
f = GridIn(self.db.fs)
|
||||
self.assertRaises(TypeError, f.write, u"foo")
|
||||
self.assertRaises(TypeError, f.write, "foo")
|
||||
|
||||
f = GridIn(self.db.fs, encoding="utf-8")
|
||||
f.write(u"foo")
|
||||
f.write("foo")
|
||||
f.close()
|
||||
|
||||
g = GridOut(self.db.fs, f._id)
|
||||
self.assertEqual(b"foo", g.read())
|
||||
|
||||
f = GridIn(self.db.fs, encoding="iso-8859-1")
|
||||
f.write(u"aé")
|
||||
f.write("aé")
|
||||
f.close()
|
||||
|
||||
g = GridOut(self.db.fs, f._id)
|
||||
self.assertEqual(u"aé".encode("iso-8859-1"), g.read())
|
||||
self.assertEqual("aé".encode("iso-8859-1"), g.read())
|
||||
|
||||
def test_set_after_close(self):
|
||||
f = GridIn(self.db.fs, _id="foo", bar="baz")
|
||||
|
||||
@ -385,14 +385,14 @@ class TestGridfs(IntegrationTest):
|
||||
self.assertFalse(self.fs.exists({"foo": {"$gt": 12}}))
|
||||
|
||||
def test_put_unicode(self):
|
||||
self.assertRaises(TypeError, self.fs.put, u"hello")
|
||||
self.assertRaises(TypeError, self.fs.put, "hello")
|
||||
|
||||
oid = self.fs.put(u"hello", encoding="utf-8")
|
||||
oid = self.fs.put("hello", encoding="utf-8")
|
||||
self.assertEqual(b"hello", self.fs.get(oid).read())
|
||||
self.assertEqual("utf-8", self.fs.get(oid).encoding)
|
||||
|
||||
oid = self.fs.put(u"aé", encoding="iso-8859-1")
|
||||
self.assertEqual(u"aé".encode("iso-8859-1"), self.fs.get(oid).read())
|
||||
oid = self.fs.put("aé", encoding="iso-8859-1")
|
||||
self.assertEqual("aé".encode("iso-8859-1"), self.fs.get(oid).read())
|
||||
self.assertEqual("iso-8859-1", self.fs.get(oid).encoding)
|
||||
|
||||
def test_missing_length_iter(self):
|
||||
|
||||
@ -131,7 +131,7 @@ class TestLegacy(IntegrationTest):
|
||||
db = self.db
|
||||
db.test.drop()
|
||||
self.assertEqual(0, len(list(db.test.find())))
|
||||
doc = {"hello": u"world"}
|
||||
doc = {"hello": "world"}
|
||||
_id = db.test.insert(doc)
|
||||
self.assertEqual(1, len(list(db.test.find())))
|
||||
self.assertEqual(doc, db.test.find_one())
|
||||
@ -167,13 +167,13 @@ class TestLegacy(IntegrationTest):
|
||||
# Tests legacy insert.
|
||||
db = self.db
|
||||
db.drop_collection("test")
|
||||
doc1 = {"hello": u"world"}
|
||||
doc2 = {"hello": u"mike"}
|
||||
doc1 = {"hello": "world"}
|
||||
doc2 = {"hello": "mike"}
|
||||
self.assertEqual(db.test.find().count(), 0)
|
||||
ids = db.test.insert([doc1, doc2])
|
||||
self.assertEqual(db.test.find().count(), 2)
|
||||
self.assertEqual(doc1, db.test.find_one({"hello": u"world"}))
|
||||
self.assertEqual(doc2, db.test.find_one({"hello": u"mike"}))
|
||||
self.assertEqual(doc1, db.test.find_one({"hello": "world"}))
|
||||
self.assertEqual(doc2, db.test.find_one({"hello": "mike"}))
|
||||
|
||||
self.assertEqual(2, len(ids))
|
||||
self.assertEqual(doc1["_id"], ids[0])
|
||||
@ -281,7 +281,7 @@ class TestLegacy(IntegrationTest):
|
||||
|
||||
db.drop_collection("test")
|
||||
self.assertEqual(db.test.find().count(), 0)
|
||||
db.test.insert(({"hello": u"world"}, {"hello": u"world"}))
|
||||
db.test.insert(({"hello": "world"}, {"hello": "world"}))
|
||||
self.assertEqual(db.test.find().count(), 2)
|
||||
|
||||
db.drop_collection("test")
|
||||
@ -1062,7 +1062,7 @@ class TestLegacy(IntegrationTest):
|
||||
db.test.b.remove({})
|
||||
db.test.c.remove({})
|
||||
|
||||
a = {"hello": u"world"}
|
||||
a = {"hello": "world"}
|
||||
db.test.a.save(a)
|
||||
|
||||
b = {"test": a}
|
||||
|
||||
@ -50,14 +50,11 @@ class TestObjectId(unittest.TestCase):
|
||||
def test_unicode(self):
|
||||
a = ObjectId()
|
||||
self.assertEqual(a, ObjectId(a))
|
||||
self.assertEqual(ObjectId("123456789012123456789012"),
|
||||
ObjectId(u"123456789012123456789012"))
|
||||
self.assertRaises(InvalidId, ObjectId, u"hello")
|
||||
self.assertRaises(InvalidId, ObjectId, "hello")
|
||||
|
||||
def test_from_hex(self):
|
||||
ObjectId("123456789012123456789012")
|
||||
self.assertRaises(InvalidId, ObjectId, "123456789012123456789G12")
|
||||
self.assertRaises(InvalidId, ObjectId, u"123456789012123456789G12")
|
||||
|
||||
def test_repr_str(self):
|
||||
self.assertEqual(repr(ObjectId("1234567890abcdef12345678")),
|
||||
|
||||
@ -13,7 +13,6 @@
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
sys.path[0:0] = [""]
|
||||
|
||||
@ -26,18 +25,18 @@ class TestSASLprep(unittest.TestCase):
|
||||
try:
|
||||
import stringprep
|
||||
except ImportError:
|
||||
self.assertRaises(TypeError, saslprep, u"anything...")
|
||||
self.assertRaises(TypeError, saslprep, "anything...")
|
||||
# Bytes strings are ignored.
|
||||
self.assertEqual(saslprep(b"user"), b"user")
|
||||
else:
|
||||
# Examples from RFC4013, Section 3.
|
||||
self.assertEqual(saslprep(u"I\u00ADX"), u"IX")
|
||||
self.assertEqual(saslprep(u"user"), u"user")
|
||||
self.assertEqual(saslprep(u"USER"), u"USER")
|
||||
self.assertEqual(saslprep(u"\u00AA"), u"a")
|
||||
self.assertEqual(saslprep(u"\u2168"), u"IX")
|
||||
self.assertRaises(ValueError, saslprep, u"\u0007")
|
||||
self.assertRaises(ValueError, saslprep, u"\u0627\u0031")
|
||||
self.assertEqual(saslprep("I\u00ADX"), "IX")
|
||||
self.assertEqual(saslprep("user"), "user")
|
||||
self.assertEqual(saslprep("USER"), "USER")
|
||||
self.assertEqual(saslprep("\u00AA"), "a")
|
||||
self.assertEqual(saslprep("\u2168"), "IX")
|
||||
self.assertRaises(ValueError, saslprep, "\u0007")
|
||||
self.assertRaises(ValueError, saslprep, "\u0627\u0031")
|
||||
|
||||
# Bytes strings are ignored.
|
||||
self.assertEqual(saslprep(b"user"), b"user")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user