Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #59880 > unrolled thread
| Started by | roey.katz@gmail.com |
|---|---|
| First post | 2013-11-18 07:47 -0800 |
| Last post | 2013-11-18 16:41 -0800 |
| Articles | 8 — 4 participants |
Back to article view | Back to comp.lang.python
Building a tree-based readline completer roey.katz@gmail.com - 2013-11-18 07:47 -0800
Re: Building a tree-based readline completer xDog Walker <thudfoo@gmail.com> - 2013-11-18 08:41 -0800
Re: Building a tree-based readline completer roey.katz@gmail.com - 2013-11-18 08:54 -0800
Re: Building a tree-based readline completer roey.katz@gmail.com - 2013-11-18 08:55 -0800
Re: Building a tree-based readline completer Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-18 17:13 +0000
Re: Building a tree-based readline completer xDog Walker <thudfoo@gmail.com> - 2013-11-18 09:36 -0800
Re: Building a tree-based readline completer Dave Angel <davea@davea.name> - 2013-11-18 15:51 -0500
Re: Building a tree-based readline completer roey.katz@gmail.com - 2013-11-18 16:41 -0800
| From | roey.katz@gmail.com |
|---|---|
| Date | 2013-11-18 07:47 -0800 |
| Subject | Building a tree-based readline completer |
| Message-ID | <fe046bab-d23d-4515-800e-6f23a507bf76@googlegroups.com> |
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<TAB PRESSED>
command com2
> comm<TAB PRESSED>
> command <TAB PRESSED>
> command OPT<TAB PRESSED>
OPTION_1 OPTION_2
> command OPTION_1<TAB PRESSED>
> command OPTION_1=<TAB PRESSED>
> 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 <tab> 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 <tab> 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 <tab>, 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.
[toc] | [next] | [standalone]
| From | xDog Walker <thudfoo@gmail.com> |
|---|---|
| Date | 2013-11-18 08:41 -0800 |
| Message-ID | <mailman.2852.1384792895.18130.python-list@python.org> |
| In reply to | #59880 |
On Monday 2013 November 18 07:47, roey.katz@gmail.com 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.
[toc] | [prev] | [next] | [standalone]
| From | roey.katz@gmail.com |
|---|---|
| Date | 2013-11-18 08:54 -0800 |
| Message-ID | <34f7f052-1fd6-449b-a7eb-dc0d3505ac4b@googlegroups.com> |
| In reply to | #59885 |
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.
[toc] | [prev] | [next] | [standalone]
| From | roey.katz@gmail.com |
|---|---|
| Date | 2013-11-18 08:55 -0800 |
| Message-ID | <e35a9ae4-2fd1-46cc-8e41-42e1172fd22f@googlegroups.com> |
| In reply to | #59890 |
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
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2013-11-18 17:13 +0000 |
| Message-ID | <mailman.2854.1384794812.18130.python-list@python.org> |
| In reply to | #59891 |
On 18/11/2013 16:55, roey.katz@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. >> >> >> >> - 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 > Would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, thanks. -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | xDog Walker <thudfoo@gmail.com> |
|---|---|
| Date | 2013-11-18 09:36 -0800 |
| Message-ID | <mailman.2856.1384796206.18130.python-list@python.org> |
| In reply to | #59891 |
On Monday 2013 November 18 09:13, Mark Lawrence wrote: > On 18/11/2013 16:55, roey.katz@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, [snip] > Would you please read and action this > https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the > double line spacing above, thanks. I am going to prevent seeing your repetition of each of these messages by killfiling you. > > -- > Python is the second best programming language in the world. > But the best has yet to be invented. Christian Tismer You sig is, imho, nonsensical. > > Mark Lawrence -- Yonder nor sorghum stenches shut ladle gulls stopper torque wet strainers.
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-11-18 15:51 -0500 |
| Message-ID | <mailman.2863.1384807868.18130.python-list@python.org> |
| In reply to | #59891 |
On Mon, 18 Nov 2013 08:55:05 -0800 (PST), roey.katz@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
[toc] | [prev] | [next] | [standalone]
| From | roey.katz@gmail.com |
|---|---|
| Date | 2013-11-18 16:41 -0800 |
| Message-ID | <58a3dc12-1f45-45af-a52f-282d5443bb2d@googlegroups.com> |
| In reply to | #59907 |
> On Mon, 18 Nov 2013 08:55:05 -0800 (PST), roey.katz@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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web