Building a tree-based readline completer

2013-11-18 Thread roey . katz
Hello all, for my project[1] I am trying to build a replacement completer for 
python's Cmd class which accepts a tree of command and option names[2].  I've 
been trying all sorts of approaches (like the ARLCompleter mention here: 
https://sites.google.com/site/xiangyangsite/home/technical-tips/software-development/python/python-readline-completions),
 but so far am up for a loss as to how to get this done.  

Can anyone help me out here?  I've placed a bounty on this with BountySource:  
https://www.bountysource.com/issues/1319877-implement-a-generalized-completer-function-validator-and-filename-completer.

Thanks!
- Roey Katz
Bywaf developer 


(1) Bywaf, a command-line tool and framework for bypassing web application 
firewalls and more:  https://www.owasp.org/index.php/OWASP_Bywaf_Project

(2) What I'm looking for is a completer which accepts a tree of commands and 
option names.  Option names complete with a '=', and commands and sub-commands 
complete with a ' ', as in this hypothetical example:

> com
command com2
> comm
> command 
> command OPT
OPTION_1 OPTION_2
> command OPTION_1
> command OPTION_1=
> command OPTION_1=


Ideally, I'd like to be able to pass in a dictionary tree of commands and 
options, for example:

params_tree = { 
  'command': {
  'OPTION_1=':None,
  'OPTION_2=':None,
  }
  'com2': None,
}

Where '=' indicates an option name.   An example of a more general tree, with 
more special symbols, would look like this:


# dictionary passed into the general completer function
params_tree = {

   # tab-complete 'quit'
   'quit':None,

   # tab-complete "TARGET_IP", and allow any string as its value
'TARGET_IP=': '*',  

# tab-complete "drive".  
'drive': {

# tab-complete "car", "truck", "bike" and also allow any other string.
'VEHICLE=': ('car', 'truck, 'bike', '*'),  

   # tab-complete "hard disk", "sd card" and "remote share".
'SAVE=': ('hard disk', 'sd card', 'remote share') 
},

# tab-complete "eat"
'eat': {

# tab-complete "FRUIT=", then tab-complete 'apple' or 'pear'.  At the 
end of a successful completion, an additonal  results in an offer to 
insert a comma and complete additional items
'FRUIT=+': ('apple', 'pear'),   

# tab-complete "FRUIT=", then tab-complete 'water' or 'juice'.  At the 
end of a successful completion, an additonal  results in an offer to 
insert a comma and complete additional items
'DRINK=+': ('water', 'juice')
},

# tab-complete "cat", then tab-complete filenames.  At the end of a 
successful completion, close the quote, then upon another , offer to 
complete with a comma, allowing for completion of additional items
'cat': 'FILE=/+'  
}

Notes:

An element in this dictionary can take None, a string, a tuple or a dictionary 
of more elements.

  *  "=' indicates that this is a plugin option.
  *  "/' indicates this plugin option should complete beginning with the path 
specified after the =, provided that this path meets security guidelines (i.e. 
it resolves to a path under a specific directory). A plugin option named 
"FILENAME" marked in this way shall complete to FILENAME=" instead of FILENAME=.
  *  "+" indicates that this option can be specified more than once. Multiple 
values will be collected into a list instead of a string.
  *  a "*" indicates that this option accepts any single value. User can 
specify any number of options, but only one of command from the same level


Additionally, the tree completer should should support escaping characters and 
nested quoted strings (alternating single- and double-quotes), and all in 
Unicode.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Building a tree-based readline completer

2013-11-18 Thread roey . katz
Thank you.  In looking over these classes, I see though that even them, I would 
run against the same limitations, though.  

- Roey 

On Monday, November 18, 2013 11:41:20 AM UTC-5, xDog Walker wrote:
> On Monday 2013 November 18 07:47, roey wrote:
> 
> > I am trying to build a replacement completer for python's Cmd class
> 
> 
> 
> These related packages may be of interest:
> 
> 
> 
>  http://pypi.python.org/pypi/rl
> 
>  http://pypi.python.org/pypi/kmd
> 
> 
> 
> -- 
> 
> Yonder nor sorghum stenches shut ladle gulls stopper torque wet 
> 
> strainers.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Building a tree-based readline completer

2013-11-18 Thread roey . katz
On Monday, November 18, 2013 11:54:43 AM UTC-5, roey  wrote:
> Thank you.  In looking over these classes, I see though that even them, I 
> would run against the same limitations, though.  
> 
> 
> 
> - Roey 
> 
> 
> 
> On Monday, November 18, 2013 11:41:20 AM UTC-5, xDog Walker wrote:
> 
> > On Monday 2013 November 18 07:47, roey wrote:
> 
> > 
> 
> > > I am trying to build a replacement completer for python's Cmd class
> 
> > 
> 
> > 
> 
> > 
> 
> > These related packages may be of interest:
> 
> > 
> 
> > 
> 
> > 
> 
> >  http://pypi.python.org/pypi/rl
> 
> > 
> 
> >  http://pypi.python.org/pypi/kmd
> 
> > 
> 
> > 
> 
> > 
> 
> > -- 
> 
> > 
> 
> > Yonder nor sorghum stenches shut ladle gulls stopper torque wet 
> 
> > 
> 
> > strainers.

*even with them
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Building a tree-based readline completer

2013-11-18 Thread roey . katz
> On Mon, 18 Nov 2013 08:55:05 -0800 (PST), roey.k...@gmail.com wrote:
> > On Monday, November 18, 2013 11:54:43 AM UTC-5, roey  wrote:
> > > Thank you.  In looking over these classes, I see though that even 
> them, I would run against the same limitations, though.
> Please don't double space your quotes. And if googlegarbage is doing 
> it for you, then use a less buggy way of posting.
> -- 
> DaveA

Alright.  Now, after the past three emails of going around my question, can 
anyone actually address it?

Thanks again!
- Roey
-- 
https://mail.python.org/mailman/listinfo/python-list