@@ -153,17 +153,20 @@ class UuidRepresentation:
153153"""
154154
155155ALL_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+ )
161163UUID_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+ }
167170
168171MD5_SUBTYPE = 5
169172"""BSON binary subtype for an MD5 hash.
@@ -244,8 +247,9 @@ def from_uuid(cls, uuid, uuid_representation=UuidRepresentation.STANDARD):
244247 raise TypeError ("uuid must be an instance of uuid.UUID" )
245248
246249 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+ )
249253
250254 if uuid_representation == UuidRepresentation .UNSPECIFIED :
251255 raise ValueError (
@@ -254,7 +258,8 @@ def from_uuid(cls, uuid, uuid_representation=UuidRepresentation.STANDARD):
254258 "converted to bson.Binary instances using "
255259 "bson.Binary.from_uuid() or a different UuidRepresentation "
256260 "can be configured. See the documentation for "
257- "UuidRepresentation for more information." )
261+ "UuidRepresentation for more information."
262+ )
258263
259264 subtype = OLD_UUID_SUBTYPE
260265 if uuid_representation == UuidRepresentation .PYTHON_LEGACY :
@@ -289,12 +294,12 @@ def as_uuid(self, uuid_representation=UuidRepresentation.STANDARD):
289294 .. versionadded:: 3.11
290295 """
291296 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 ,))
294298
295299 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+ )
298303
299304 if uuid_representation == UuidRepresentation .UNSPECIFIED :
300305 raise ValueError ("uuid_representation cannot be UNSPECIFIED" )
@@ -312,26 +317,26 @@ def as_uuid(self, uuid_representation=UuidRepresentation.STANDARD):
312317 if self .subtype == UUID_SUBTYPE :
313318 return UUID (bytes = self )
314319
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+ )
317324
318325 @property
319326 def subtype (self ):
320- """Subtype of this binary data.
321- """
327+ """Subtype of this binary data."""
322328 return self .__subtype
323329
324330 def __getnewargs__ (self ):
325331 # Work around http://bugs.python.org/issue7382
326332 data = super (Binary , self ).__getnewargs__ ()[0 ]
327333 if not isinstance (data , bytes ):
328- data = data .encode (' latin-1' )
334+ data = data .encode (" latin-1" )
329335 return data , self .__subtype
330336
331337 def __eq__ (self , other ):
332338 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 ))
335340 # We don't return NotImplemented here because if we did then
336341 # Binary("foo") == "foo" would return True, since Binary is a
337342 # subclass of str...
0 commit comments