Exemple #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)
Exemple #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)
Exemple #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)
 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)