<s> from __future__ import absolute_import , division , unicode_literals <EOL> import six <EOL> from django . db . models import CharField <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django_mysql . compat import field_class <EOL> from _mysql import escape_string <EOL> class EnumField ( field_class ( CharField ) ) : <EOL> description = _ ( "<STR_LIT>" ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> if '<STR_LIT>' not in kwargs or len ( kwargs [ '<STR_LIT>' ] ) == <NUM_LIT:0> : <EOL> raise ValueError ( <EOL> '<STR_LIT>' <EOL> ) <EOL> choices = [ ] <EOL> for choice in kwargs [ '<STR_LIT>' ] : <EOL> if isinstance ( choice , tuple ) : <EOL> choices . append ( choice ) <EOL> elif isinstance ( choice , six . string_types ) : <EOL> choices . append ( ( choice , choice ) ) <EOL> else : <EOL> raise TypeError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( <EOL> choice = choice , <EOL> ) <EOL> ) <EOL> kwargs [ '<STR_LIT>' ] = choices <EOL> if '<STR_LIT:max_length>' in kwargs : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> kwargs [ '<STR_LIT:max_length>' ] = int ( <NUM_LIT:2> ** <NUM_LIT:32> ) <EOL> super ( EnumField , self ) . __init__ ( * args , ** kwargs ) <EOL> def deconstruct ( self ) : <EOL> name , path , args , kwargs = super ( EnumField , self ) . deconstruct ( ) <EOL> bad_paths = ( <EOL> '<STR_LIT>' + self . __class__ . __name__ , <EOL> '<STR_LIT>' + self . __class__ . __name__ <EOL> ) <EOL> if path in bad_paths : <EOL> path = '<STR_LIT>' + self . __class__ . __name__ <EOL> kwargs [ '<STR_LIT>' ] = self . choices <EOL> del kwargs [ '<STR_LIT:max_length>' ] <EOL> return name , path , args , kwargs <EOL> def db_type ( self , connection ) : <EOL> values = [ escape_string ( c ) for c , _ in self . flatchoices ] <EOL> return '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( <EOL> "<STR_LIT>" % v . decode ( '<STR_LIT:utf8>' ) for v in values <EOL> ) </s>
