parameters: ()
return_statement: return options
docstring: Define and parse the command-line arguments.
docstring_summary: Define and parse the command-line arguments.
docstring_tokens: Define and parse the command - line arguments .
function: def _ParseArgs():
    """Define and parse the command-line arguments."""
    presets_string = '\n'.join(str(p) for p in _PRESETS)
    parser = NonStrippingEpilogOptionParser(epilog=(
        '\nAvailable presets:\n'
        '                              Bandwidth (kbps)                  Packet\n'
        'ID Name                       Receive     Send    Queue  Delay   loss \n'
        '-- ----                      ---------   -------- ----- ------- ------\n'
        '%s\n' % presets_string))
    parser.add_option('-p', '--preset', type='int', default=_DEFAULT_PRESET_ID,
                      help=('ConnectionConfig configuration, specified by ID. '
                            'Default: %default'))
    parser.add_option('-r', '--receive-bw', type='int',
                      default=_DEFAULT_PRESET.receive_bw_kbps,
                      help=('Receive bandwidth in kilobit/s. Default: %default'))
    parser.add_option('-s', '--send-bw', type='int',
                      default=_DEFAULT_PRESET.send_bw_kbps,
                      help=('Send bandwidth in kilobit/s. Default: %default'))
    parser.add_option('-d', '--delay', type='int',
                      default=_DEFAULT_PRESET.delay_ms,
                      help=('Delay in ms. Default: %default'))
    parser.add_option('-l', '--packet-loss', type='float',
                      default=_DEFAULT_PRESET.packet_loss_percent,
                      help=('Packet loss in %. Default: %default'))
    parser.add_option('-q', '--queue', type='int',
                      default=_DEFAULT_PRESET.queue_slots,
                      help=('Queue size as number of slots. Default: %default'))
    parser.add_option('--port-range', default='%s,%s' % _DEFAULT_PORT_RANGE,
                      help=('Range of ports for constrained network. Specify as '
                            'two comma separated integers. Default: %default'))
    parser.add_option('--target-ip', default=None,
                      help=('The interface IP address to apply the rules for. '
                            'Default: the external facing interface IP address.'))
    parser.add_option('-v', '--verbose', action='store_true', default=False,
                      help=('Turn on verbose output. Will print all \'ipfw\' '
                            'commands that are executed.'))
  
    options = parser.parse_args()[0]
  
    # Find preset by ID, if specified.
    if options.preset and not _PRESETS_DICT.has_key(options.preset):
      parser.error('Invalid preset: %s' % options.preset)
  
    # Simple validation of the IP address, if supplied.
    if options.target_ip:
      try:
        socket.inet_aton(options.target_ip)
      except socket.error:
        parser.error('Invalid IP address specified: %s' % options.target_ip)
  
    # Convert port range into the desired tuple format.
    try:
      if isinstance(options.port_range, str):
        options.port_range = tuple(int(port) for port in
                                   options.port_range.split(','))
        if len(options.port_range) != 2:
          parser.error('Invalid port range specified, please specify two '
                       'integers separated by a comma.')
    except ValueError:
      parser.error('Invalid port range specified.')
  
    _InitLogging(options.verbose)
    return options
function_tokens: def _ParseArgs ( ) : presets_string = '\n' . join ( str ( p ) for p in _PRESETS ) parser = NonStrippingEpilogOptionParser ( epilog = ( '\nAvailable presets:\n' '                              Bandwidth (kbps)                  Packet\n' 'ID Name                       Receive     Send    Queue  Delay   loss \n' '-- ----                      ---------   -------- ----- ------- ------\n' '%s\n' % presets_string ) ) parser . add_option ( '-p' , '--preset' , type = 'int' , default = _DEFAULT_PRESET_ID , help = ( 'ConnectionConfig configuration, specified by ID. ' 'Default: %default' ) ) parser . add_option ( '-r' , '--receive-bw' , type = 'int' , default = _DEFAULT_PRESET . receive_bw_kbps , help = ( 'Receive bandwidth in kilobit/s. Default: %default' ) ) parser . add_option ( '-s' , '--send-bw' , type = 'int' , default = _DEFAULT_PRESET . send_bw_kbps , help = ( 'Send bandwidth in kilobit/s. Default: %default' ) ) parser . add_option ( '-d' , '--delay' , type = 'int' , default = _DEFAULT_PRESET . delay_ms , help = ( 'Delay in ms. Default: %default' ) ) parser . add_option ( '-l' , '--packet-loss' , type = 'float' , default = _DEFAULT_PRESET . packet_loss_percent , help = ( 'Packet loss in %. Default: %default' ) ) parser . add_option ( '-q' , '--queue' , type = 'int' , default = _DEFAULT_PRESET . queue_slots , help = ( 'Queue size as number of slots. Default: %default' ) ) parser . add_option ( '--port-range' , default = '%s,%s' % _DEFAULT_PORT_RANGE , help = ( 'Range of ports for constrained network. Specify as ' 'two comma separated integers. Default: %default' ) ) parser . add_option ( '--target-ip' , default = None , help = ( 'The interface IP address to apply the rules for. ' 'Default: the external facing interface IP address.' ) ) parser . add_option ( '-v' , '--verbose' , action = 'store_true' , default = False , help = ( 'Turn on verbose output. Will print all \'ipfw\' ' 'commands that are executed.' ) ) options = parser . parse_args ( ) [ 0 ] # Find preset by ID, if specified. if options . preset and not _PRESETS_DICT . has_key ( options . preset ) : parser . error ( 'Invalid preset: %s' % options . preset ) # Simple validation of the IP address, if supplied. if options . target_ip : try : socket . inet_aton ( options . target_ip ) except socket . error : parser . error ( 'Invalid IP address specified: %s' % options . target_ip ) # Convert port range into the desired tuple format. try : if isinstance ( options . port_range , str ) : options . port_range = tuple ( int ( port ) for port in options . port_range . split ( ',' ) ) if len ( options . port_range ) != 2 : parser . error ( 'Invalid port range specified, please specify two ' 'integers separated by a comma.' ) except ValueError : parser . error ( 'Invalid port range specified.' ) _InitLogging ( options . verbose ) return options