<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 Field , RegexField , Select <EOL> from django . utils . encoding import smart_str <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from . nz_councils import NORTH_ISLAND_COUNCIL_CHOICES , SOUTH_ISLAND_COUNCIL_CHOICES <EOL> from . nz_provinces import PROVINCE_CHOICES <EOL> from . nz_regions import REGION_CHOICES <EOL> PHONE_08_RE = re . compile ( r'<STR_LIT>' ) <EOL> PHONE_IN_RE = re . compile ( r'<STR_LIT>' ) <EOL> PHONE_NZ_RE = re . compile ( r'<STR_LIT>' ) <EOL> BANK_ACCOUNT_NUMBER_RE = re . compile ( r'<STR_LIT>' ) <EOL> class NZRegionSelect ( Select ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , attrs = None ) : <EOL> super ( NZRegionSelect , self ) . __init__ ( attrs , choices = REGION_CHOICES ) <EOL> class NZProvinceSelect ( Select ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , attrs = None ) : <EOL> super ( NZProvinceSelect , self ) . __init__ ( attrs , choices = PROVINCE_CHOICES ) <EOL> class NZNorthIslandCouncilSelect ( Select ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , attrs = None ) : <EOL> super ( NZNorthIslandCouncilSelect , self ) . __init__ ( attrs , choices = NORTH_ISLAND_COUNCIL_CHOICES ) <EOL> class NZSouthIslandCouncilSelect ( Select ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , attrs = None ) : <EOL> super ( NZSouthIslandCouncilSelect , self ) . __init__ ( attrs , choices = SOUTH_ISLAND_COUNCIL_CHOICES ) <EOL> class NZPostCodeField ( RegexField ) : <EOL> """<STR_LIT>""" <EOL> default_error_messages = { <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) , <EOL> } <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( NZPostCodeField , self ) . __init__ ( r'<STR_LIT>' , <EOL> * args , ** kwargs ) <EOL> class NZPhoneNumberField ( Field ) : <EOL> """<STR_LIT>""" <EOL> default_error_messages = { '<STR_LIT>' : _ ( '<STR_LIT>' ) } <EOL> def clean ( self , value ) : <EOL> super ( NZPhoneNumberField , self ) . clean ( value ) <EOL> if value in EMPTY_VALUES : <EOL> return '<STR_LIT>' <EOL> value = re . sub ( '<STR_LIT>' , '<STR_LIT>' , smart_str ( value ) ) <EOL> value = re . sub ( '<STR_LIT>' , '<STR_LIT>' , smart_str ( value ) ) <EOL> value = re . sub ( '<STR_LIT>' , '<STR_LIT>' , smart_str ( value ) ) <EOL> phone_08_match = PHONE_08_RE . search ( value ) <EOL> if phone_08_match : <EOL> return '<STR_LIT:%s>' % phone_08_match . group ( <NUM_LIT:0> ) <EOL> phone_nz_match = PHONE_NZ_RE . search ( value ) <EOL> if phone_nz_match : <EOL> return '<STR_LIT:%s>' % phone_nz_match . group ( <NUM_LIT:0> ) <EOL> phone_in_match = PHONE_IN_RE . search ( value ) <EOL> if phone_in_match : <EOL> return '<STR_LIT:%s>' % phone_in_match . group ( <NUM_LIT:0> ) <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> class NZBankAccountNumberField ( Field ) : <EOL> """<STR_LIT>""" <EOL> default_error_messages = { <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) , <EOL> } <EOL> def clean ( self , value ) : <EOL> super ( NZBankAccountNumberField , self ) . clean ( value ) <EOL> if value in EMPTY_VALUES : <EOL> return '<STR_LIT>' <EOL> value = re . sub ( '<STR_LIT>' , '<STR_LIT>' , smart_str ( value ) ) <EOL> match = BANK_ACCOUNT_NUMBER_RE . search ( value ) <EOL> if match : <EOL> last = '<STR_LIT>' % match . group ( <NUM_LIT:4> ) if len ( match . group ( <NUM_LIT:4> ) ) == <NUM_LIT:2> else match . group ( <NUM_LIT:4> ) <EOL> return '<STR_LIT>' % ( match . group ( <NUM_LIT:1> ) , <EOL> match . group ( <NUM_LIT:2> ) , match . group ( <NUM_LIT:3> ) , last ) <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) </s>
