#NEWLINE# def validate_domain( self , value ) : #NEWLINE# #INDENT# '\n        Check that the hostname is valid\n        ' #NEWLINE# if ( len ( value ) > 255 ) : #NEWLINE# #INDENT# raise serializers . ValidationError ( 'Hostname must be 255 characters or less.' ) #NEWLINE# #UNINDENT# if ( value [ ( - 1 ) : ] == '.' ) : #NEWLINE# #INDENT# value = value [ : ( - 1 ) ] #NEWLINE# #UNINDENT# labels = value . split ( '.' ) #NEWLINE# if ( 'xip.io' in value ) : #NEWLINE# #INDENT# return value #NEWLINE# #UNINDENT# if ( labels [ 0 ] == '*' ) : #NEWLINE# #INDENT# raise serializers . ValidationError ( 'Adding a wildcard subdomain is currently not supported.' ) #NEWLINE# #UNINDENT# allowed = re . compile ( '^(?!-)[a-z0-9-]{1,63}(?<!-)$' , re . IGNORECASE ) #NEWLINE# for label in labels : #NEWLINE# #INDENT# match = allowed . match ( label ) #NEWLINE# if ( ( not match ) or ( '--' in allowed ) or label . isdigit ( ) or ( ( len ( labels ) == 1 ) and any ( ( char . isdigit ( ) for char in label ) ) ) ) : #NEWLINE# #INDENT# raise serializers . ValidationError ( 'Hostname does not look valid.' ) #NEWLINE# #UNINDENT# #UNINDENT# if models . Domain . objects . filter ( domain = value ) . exists ( ) : #NEWLINE# #INDENT# raise serializers . ValidationError ( 'The domain {} is already in use by another app' . format ( value ) ) #NEWLINE# #UNINDENT# return value