#NEWLINE# def Port( port ) : #NEWLINE# #INDENT# 'Sanitize a port value.\n   \n  Args:\n    port: a port value\n\n  Returns:\n    port: a port value\n\n  Raises:\n    BadPortValue: port is not valid integer or string\n    BadPortRange: port is outside valid range\n  ' #NEWLINE# pval = ( - 1 ) #NEWLINE# try : #NEWLINE# #INDENT# pval = int ( port ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise BadPortValue ( ( 'port %s is not valid.' % port ) ) #NEWLINE# #UNINDENT# if ( ( pval < 0 ) or ( pval > 65535 ) ) : #NEWLINE# #INDENT# raise BadPortRange ( ( 'port %s is out of range 0-65535.' % port ) ) #NEWLINE# #UNINDENT# return pval