#NEWLINE# def parse_address( netloc , default_port = 8000 ) : #NEWLINE# #INDENT# if netloc . startswith ( 'unix:' ) : #NEWLINE# #INDENT# return netloc . split ( 'unix:' ) [ 1 ] #NEWLINE# #UNINDENT# if ( ( '[' in netloc ) and ( ']' in netloc ) ) : #NEWLINE# #INDENT# host = netloc . split ( ']' ) [ 0 ] [ 1 : ] . lower ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ':' in netloc ) : #NEWLINE# #INDENT# host = netloc . split ( ':' ) [ 0 ] . lower ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( netloc == '' ) : #NEWLINE# #INDENT# host = '0.0.0.0' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# host = netloc . lower ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# netloc = netloc . split ( ']' ) [ ( - 1 ) ] #NEWLINE# if ( ':' in netloc ) : #NEWLINE# #INDENT# port = netloc . split ( ':' , 1 ) [ 1 ] #NEWLINE# if ( not port . isdigit ( ) ) : #NEWLINE# #INDENT# raise RuntimeError ( ( '%r is not a valid port number.' % port ) ) #NEWLINE# #UNINDENT# port = int ( port ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# port = default_port #NEWLINE# #UNINDENT# return ( host , port )