<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> import re <EOL> from django . core . validators import EMPTY_VALUES <EOL> from django . forms import ValidationError <EOL> from django . forms . fields import CharField , Field , RegexField , Select <EOL> from django . utils . encoding import force_text <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from . in_states import STATE_CHOICES , STATES_NORMALIZED <EOL> phone_digits_re = re . compile ( r"""<STR_LIT>""" , re . VERBOSE ) <EOL> aadhaar_re = re . compile ( r"<STR_LIT>" ) <EOL> class INZipCodeField ( RegexField ) : <EOL> """<STR_LIT>""" <EOL> default_error_messages = { <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) , <EOL> } <EOL> def __init__ ( self , max_length = None , min_length = None , * args , ** kwargs ) : <EOL> super ( INZipCodeField , self ) . __init__ ( r'<STR_LIT>' , <EOL> max_length , min_length , * args , ** kwargs ) <EOL> def clean ( self , value ) : <EOL> value = super ( INZipCodeField , self ) . clean ( value ) <EOL> if value in EMPTY_VALUES : <EOL> return '<STR_LIT>' <EOL> value = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , value ) <EOL> return value <EOL> class INStateField ( Field ) : <EOL> """<STR_LIT>""" <EOL> default_error_messages = { <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) , <EOL> } <EOL> def clean ( self , value ) : <EOL> value = super ( INStateField , self ) . clean ( value ) <EOL> if value in EMPTY_VALUES : <EOL> return '<STR_LIT>' <EOL> try : <EOL> value = value . strip ( ) . lower ( ) <EOL> except AttributeError : <EOL> pass <EOL> else : <EOL> try : <EOL> return force_text ( STATES_NORMALIZED [ value . strip ( ) . lower ( ) ] ) <EOL> except KeyError : <EOL> pass <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> class INAadhaarNumberField ( Field ) : <EOL> """<STR_LIT>""" <EOL> default_error_messages = { <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> } <EOL> def clean ( self , value ) : <EOL> value = super ( INAadhaarNumberField , self ) . clean ( value ) <EOL> if value in EMPTY_VALUES : <EOL> return '<STR_LIT>' <EOL> match = re . match ( aadhaar_re , value ) <EOL> if not match : <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> part1 , part2 , part3 = match . groupdict ( ) [ '<STR_LIT>' ] , match . groupdict ( ) [ '<STR_LIT>' ] , match . groupdict ( ) [ '<STR_LIT>' ] <EOL> if part1 == '<STR_LIT>' and part2 == '<STR_LIT>' and part3 == '<STR_LIT>' : <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> return '<STR_LIT>' % ( part1 , part2 , part3 ) <EOL> class INStateSelect ( Select ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , attrs = None ) : <EOL> super ( INStateSelect , self ) . __init__ ( attrs , choices = STATE_CHOICES ) <EOL> class INPhoneNumberField ( CharField ) : <EOL> """<STR_LIT>""" <EOL> default_error_messages = { <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) , <EOL> } <EOL> def clean ( self , value ) : <EOL> value = super ( INPhoneNumberField , self ) . clean ( value ) <EOL> if value in EMPTY_VALUES : <EOL> return '<STR_LIT>' <EOL> value = force_text ( value ) <EOL> m = phone_digits_re . match ( value ) <EOL> if m : <EOL> return '<STR_LIT:%s>' % ( value ) <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) </s>
