@@ -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.
@@ -244,8 +247,9 @@ def from_uuid(cls, uuid, uuid_representation=UuidRepresentation.STANDARD):
244
247
raise TypeError ("uuid must be an instance of uuid.UUID" )
245
248
246
249
if uuid_representation not in ALL_UUID_REPRESENTATIONS :
247
- raise ValueError ("uuid_representation must be a value "
248
- "from bson.binary.UuidRepresentation" )
250
+ raise ValueError (
251
+ "uuid_representation must be a value " "from bson.binary.UuidRepresentation"
252
+ )
249
253
250
254
if uuid_representation == UuidRepresentation .UNSPECIFIED :
251
255
raise ValueError (
@@ -254,7 +258,8 @@ def from_uuid(cls, uuid, uuid_representation=UuidRepresentation.STANDARD):
254
258
"converted to bson.Binary instances using "
255
259
"bson.Binary.from_uuid() or a different UuidRepresentation "
256
260
"can be configured. See the documentation for "
257
- "UuidRepresentation for more information." )
261
+ "UuidRepresentation for more information."
262
+ )
258
263
259
264
subtype = OLD_UUID_SUBTYPE
260
265
if uuid_representation == UuidRepresentation .PYTHON_LEGACY :
@@ -289,12 +294,12 @@ def as_uuid(self, uuid_representation=UuidRepresentation.STANDARD):
289
294
.. versionadded:: 3.11
290
295
"""
291
296
if self .subtype not in ALL_UUID_SUBTYPES :
292
- raise ValueError ("cannot decode subtype %s as a uuid" % (
293
- self .subtype ,))
297
+ raise ValueError ("cannot decode subtype %s as a uuid" % (self .subtype ,))
294
298
295
299
if uuid_representation not in ALL_UUID_REPRESENTATIONS :
296
- raise ValueError ("uuid_representation must be a value from "
297
- "bson.binary.UuidRepresentation" )
300
+ raise ValueError (
301
+ "uuid_representation must be a value from " "bson.binary.UuidRepresentation"
302
+ )
298
303
299
304
if uuid_representation == UuidRepresentation .UNSPECIFIED :
300
305
raise ValueError ("uuid_representation cannot be UNSPECIFIED" )
@@ -312,26 +317,26 @@ def as_uuid(self, uuid_representation=UuidRepresentation.STANDARD):
312
317
if self .subtype == UUID_SUBTYPE :
313
318
return UUID (bytes = self )
314
319
315
- raise ValueError ("cannot decode subtype %s to %s" % (
316
- self .subtype , UUID_REPRESENTATION_NAMES [uuid_representation ]))
320
+ raise ValueError (
321
+ "cannot decode subtype %s to %s"
322
+ % (self .subtype , UUID_REPRESENTATION_NAMES [uuid_representation ])
323
+ )
317
324
318
325
@property
319
326
def subtype (self ):
320
- """Subtype of this binary data.
321
- """
327
+ """Subtype of this binary data."""
322
328
return self .__subtype
323
329
324
330
def __getnewargs__ (self ):
325
331
# Work around http://bugs.python.org/issue7382
326
332
data = super (Binary , self ).__getnewargs__ ()[0 ]
327
333
if not isinstance (data , bytes ):
328
- data = data .encode (' latin-1' )
334
+ data = data .encode (" latin-1" )
329
335
return data , self .__subtype
330
336
331
337
def __eq__ (self , other ):
332
338
if isinstance (other , Binary ):
333
- return ((self .__subtype , bytes (self )) ==
334
- (other .subtype , bytes (other )))
339
+ return (self .__subtype , bytes (self )) == (other .subtype , bytes (other ))
335
340
# We don't return NotImplemented here because if we did then
336
341
# Binary("foo") == "foo" would return True, since Binary is a
337
342
# subclass of str...
0 commit comments