<s> import unicodedata <EOL> from django . core . exceptions import ValidationError <EOL> from django . utils . deconstruct import deconstructible <EOL> from django . utils . encoding import force_text <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> @ deconstructible <EOL> class NoControlCharactersValidator ( object ) : <EOL> message = _ ( "<STR_LIT>" ) <EOL> code = "<STR_LIT>" <EOL> whitelist = None <EOL> def __init__ ( self , message = None , code = None , whitelist = None ) : <EOL> if message : <EOL> self . message = message <EOL> if code : <EOL> self . code = code <EOL> if whitelist : <EOL> self . whitelist = whitelist <EOL> def __call__ ( self , value ) : <EOL> value = force_text ( value ) <EOL> whitelist = self . whitelist <EOL> category = unicodedata . category <EOL> for character in value : <EOL> if whitelist and character in whitelist : <EOL> continue <EOL> if category ( character ) [ <NUM_LIT:0> ] == "<STR_LIT:C>" : <EOL> params = { '<STR_LIT:value>' : value , '<STR_LIT>' : whitelist } <EOL> raise ValidationError ( self . message , code = self . code , params = params ) <EOL> def __eq__ ( self , other ) : <EOL> return ( <EOL> isinstance ( other , NoControlCharactersValidator ) and <EOL> ( self . whitelist == other . whitelist ) and <EOL> ( self . message == other . message ) and <EOL> ( self . code == other . code ) <EOL> ) <EOL> @ deconstructible <EOL> class NoWhitespaceValidator ( object ) : <EOL> message = _ ( "<STR_LIT>" ) <EOL> code = "<STR_LIT>" <EOL> def __init__ ( self , message = None , code = None , whitelist = None ) : <EOL> if message : <EOL> self . message = message <EOL> if code : <EOL> self . code = code <EOL> def __call__ ( self , value ) : <EOL> value = force_text ( value ) <EOL> if value != value . strip ( ) : <EOL> params = { '<STR_LIT:value>' : value } <EOL> raise ValidationError ( self . message , code = self . code , params = params ) <EOL> def __eq__ ( self , other ) : <EOL> return ( <EOL> isinstance ( other , NoWhitespaceValidator ) and <EOL> ( self . message == other . message ) and <EOL> ( self . code == other . code ) <EOL> ) </s>
