예제 #1
0
 def validate(self, value, model_instance):
     try:
         hex_val = str(uuid.UUID(bytes=url_safe_b64_codec.decode(value)))
     except ValueError:
         raise ValidationError(_(u"This is not a valid UUID"))
     if int(hex_val[14], 16) != self.version or int(hex_val[19], 16) & 0xC != 8:
         raise ValidationError(_(u"This is not a valid UUID4"))
     super(ShortUUIDField, self).validate(value, model_instance)
예제 #2
0
 def validate(self, value, model_instance):
     try:
         hex_val = str(uuid.UUID(bytes=url_safe_b64_codec.decode(value)))
     except ValueError:
         raise ValidationError(_(u'This is not a valid UUID'))
     if int(hex_val[14], 16) != self.version \
             or int(hex_val[19], 16) & 0xc != 8:
         raise ValidationError(_(u'This is not a valid UUID4'))
     super(ShortUUIDField, self).validate(value, model_instance)
예제 #3
0
 def test_symmetry(self):
     original = uuid.uuid4().bytes
     encoded = url_safe_b64_codec.encode(original)
     decoded = url_safe_b64_codec.decode(encoded)
     self.assertEqual(original, decoded)
예제 #4
0
 def test_symmetry(self):
     original = uuid.uuid4().bytes
     encoded = url_safe_b64_codec.encode(original)
     decoded = url_safe_b64_codec.decode(encoded)
     self.assertEqual(original, decoded)