@@ -153,17 +153,20 @@ class UuidRepresentation:
153
153
"""
154
154
155
155
ALL_UUID_SUBTYPES = (OLD_UUID_SUBTYPE , UUID_SUBTYPE )
156
- ALL_UUID_REPRESENTATIONS = (UuidRepresentation .UNSPECIFIED ,
157
- UuidRepresentation .STANDARD ,
158
- UuidRepresentation .PYTHON_LEGACY ,
159
- UuidRepresentation .JAVA_LEGACY ,
160
- UuidRepresentation .CSHARP_LEGACY )
156
+ ALL_UUID_REPRESENTATIONS = (
157
+ UuidRepresentation .UNSPECIFIED ,
158
+ UuidRepresentation .STANDARD ,
159
+ UuidRepresentation .PYTHON_LEGACY ,
160
+ UuidRepresentation .JAVA_LEGACY ,
161
+ UuidRepresentation .CSHARP_LEGACY ,
162
+ )
161
163
UUID_REPRESENTATION_NAMES = {
162
- UuidRepresentation .UNSPECIFIED : 'UuidRepresentation.UNSPECIFIED' ,
163
- UuidRepresentation .STANDARD : 'UuidRepresentation.STANDARD' ,
164
- UuidRepresentation .PYTHON_LEGACY : 'UuidRepresentation.PYTHON_LEGACY' ,
165
- UuidRepresentation .JAVA_LEGACY : 'UuidRepresentation.JAVA_LEGACY' ,
166
- UuidRepresentation .CSHARP_LEGACY : 'UuidRepresentation.CSHARP_LEGACY' }
164
+ UuidRepresentation .UNSPECIFIED : "UuidRepresentation.UNSPECIFIED" ,
165
+ UuidRepresentation .STANDARD : "UuidRepresentation.STANDARD" ,
166
+ UuidRepresentation .PYTHON_LEGACY : "UuidRepresentation.PYTHON_LEGACY" ,
167
+ UuidRepresentation .JAVA_LEGACY : "UuidRepresentation.JAVA_LEGACY" ,
168
+ UuidRepresentation .CSHARP_LEGACY : "UuidRepresentation.CSHARP_LEGACY" ,
169
+ }
167
170
168
171
MD5_SUBTYPE = 5
169
172
"""BSON binary subtype for an MD5 hash.
@@ -238,8 +241,9 @@ def from_uuid(cls, uuid, uuid_representation=UuidRepresentation.STANDARD):
238
241
raise TypeError ("uuid must be an instance of uuid.UUID" )
239
242
240
243
if uuid_representation not in ALL_UUID_REPRESENTATIONS :
241
- raise ValueError ("uuid_representation must be a value "
242
- "from bson.binary.UuidRepresentation" )
244
+ raise ValueError (
245
+ "uuid_representation must be a value " "from bson.binary.UuidRepresentation"
246
+ )
243
247
244
248
if uuid_representation == UuidRepresentation .UNSPECIFIED :
245
249
raise ValueError (
@@ -248,7 +252,8 @@ def from_uuid(cls, uuid, uuid_representation=UuidRepresentation.STANDARD):
248
252
"converted to bson.Binary instances using "
249
253
"bson.Binary.from_uuid() or a different UuidRepresentation "
250
254
"can be configured. See the documentation for "
251
- "UuidRepresentation for more information." )
255
+ "UuidRepresentation for more information."
256
+ )
252
257
253
258
subtype = OLD_UUID_SUBTYPE
254
259
if uuid_representation == UuidRepresentation .PYTHON_LEGACY :
@@ -283,12 +288,12 @@ def as_uuid(self, uuid_representation=UuidRepresentation.STANDARD):
283
288
.. versionadded:: 3.11
284
289
"""
285
290
if self .subtype not in ALL_UUID_SUBTYPES :
286
- raise ValueError ("cannot decode subtype %s as a uuid" % (
287
- self .subtype ,))
291
+ raise ValueError ("cannot decode subtype %s as a uuid" % (self .subtype ,))
288
292
289
293
if uuid_representation not in ALL_UUID_REPRESENTATIONS :
290
- raise ValueError ("uuid_representation must be a value from "
291
- "bson.binary.UuidRepresentation" )
294
+ raise ValueError (
295
+ "uuid_representation must be a value from " "bson.binary.UuidRepresentation"
296
+ )
292
297
293
298
if uuid_representation == UuidRepresentation .UNSPECIFIED :
294
299
raise ValueError ("uuid_representation cannot be UNSPECIFIED" )
@@ -306,26 +311,26 @@ def as_uuid(self, uuid_representation=UuidRepresentation.STANDARD):
306
311
if self .subtype == UUID_SUBTYPE :
307
312
return UUID (bytes = self )
308
313
309
- raise ValueError ("cannot decode subtype %s to %s" % (
310
- self .subtype , UUID_REPRESENTATION_NAMES [uuid_representation ]))
314
+ raise ValueError (
315
+ "cannot decode subtype %s to %s"
316
+ % (self .subtype , UUID_REPRESENTATION_NAMES [uuid_representation ])
317
+ )
311
318
312
319
@property
313
320
def subtype (self ):
314
- """Subtype of this binary data.
315
- """
321
+ """Subtype of this binary data."""
316
322
return self .__subtype
317
323
318
324
def __getnewargs__ (self ):
319
325
# Work around http://bugs.python.org/issue7382
320
326
data = super (Binary , self ).__getnewargs__ ()[0 ]
321
327
if PY3 and not isinstance (data , bytes ):
322
- data = data .encode (' latin-1' )
328
+ data = data .encode (" latin-1" )
323
329
return data , self .__subtype
324
330
325
331
def __eq__ (self , other ):
326
332
if isinstance (other , Binary ):
327
- return ((self .__subtype , bytes (self )) ==
328
- (other .subtype , bytes (other )))
333
+ return (self .__subtype , bytes (self )) == (other .subtype , bytes (other ))
329
334
# We don't return NotImplemented here because if we did then
330
335
# Binary("foo") == "foo" would return True, since Binary is a
331
336
# subclass of str...
@@ -409,7 +414,9 @@ def __new__(cls, obj):
409
414
"in PyMongo 4.0. Use the Binary.from_uuid() and Binary.to_uuid() "
410
415
"with the appropriate UuidRepresentation to handle "
411
416
"legacy-formatted UUIDs instead." ,
412
- DeprecationWarning , stacklevel = 2 )
417
+ DeprecationWarning ,
418
+ stacklevel = 2 ,
419
+ )
413
420
if not isinstance (obj , UUID ):
414
421
raise TypeError ("obj must be an instance of uuid.UUID" )
415
422
self = Binary .__new__ (cls , obj .bytes , OLD_UUID_SUBTYPE )
@@ -422,8 +429,7 @@ def __getnewargs__(self):
422
429
423
430
@property
424
431
def uuid (self ):
425
- """UUID instance wrapped by this UUIDLegacy instance.
426
- """
432
+ """UUID instance wrapped by this UUIDLegacy instance."""
427
433
return self .__uuid
428
434
429
435
def __repr__ (self ):
0 commit comments