<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> import re <EOL> from django . forms import ValidationError <EOL> from django . forms . fields import CharField , Select <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from . gb_regions import GB_NATIONS_CHOICES , GB_REGION_CHOICES <EOL> class GBPostcodeField ( CharField ) : <EOL> """<STR_LIT>""" <EOL> default_error_messages = { <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) , <EOL> } <EOL> outcode_pattern = '<STR_LIT>' <EOL> incode_pattern = '<STR_LIT>' <EOL> postcode_regex = re . compile ( r'<STR_LIT>' % ( outcode_pattern , incode_pattern ) ) <EOL> space_regex = re . compile ( r'<STR_LIT>' % incode_pattern ) <EOL> def clean ( self , value ) : <EOL> value = super ( GBPostcodeField , self ) . clean ( value ) <EOL> if value == '<STR_LIT>' : <EOL> return value <EOL> postcode = value . upper ( ) . strip ( ) <EOL> postcode = self . space_regex . sub ( r'<STR_LIT>' , postcode ) <EOL> if not self . postcode_regex . search ( postcode ) : <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> return postcode <EOL> class GBCountySelect ( Select ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , attrs = None ) : <EOL> super ( GBCountySelect , self ) . __init__ ( attrs , choices = GB_REGION_CHOICES ) <EOL> class GBNationSelect ( Select ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , attrs = None ) : <EOL> super ( GBNationSelect , self ) . __init__ ( attrs , choices = GB_NATIONS_CHOICES ) </s>
