<s> from __future__ import absolute_import , unicode_literals , division <EOL> from . attribute import Attribute <EOL> from armet import exceptions <EOL> import uuid <EOL> try : <EOL> import shortuuid <EOL> except ImportError : <EOL> shortuuid = None <EOL> class UUIDAttribute ( Attribute ) : <EOL> type = uuid . UUID <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( UUIDAttribute , self ) . __init__ ( * args , ** kwargs ) <EOL> self . short = kwargs . get ( '<STR_LIT>' ) <EOL> if self . short is None or self . short : <EOL> if shortuuid is None : <EOL> if self . short is None : <EOL> self . short = False <EOL> return <EOL> else : <EOL> raise exceptions . ImproperlyConfigured ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . short = True <EOL> def prepare ( self , value ) : <EOL> if value is None : <EOL> return None <EOL> if self . short : <EOL> return shortuuid . encode ( value ) <EOL> return value . hex <EOL> def clean ( self , value ) : <EOL> if value is None : <EOL> return value <EOL> try : <EOL> try : <EOL> if self . short : <EOL> return shortuuid . decode ( value ) <EOL> except ValueError : <EOL> pass <EOL> return uuid . UUID ( value ) <EOL> except ValueError : <EOL> raise ValueError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) </s>
