wip shlex

This commit is contained in:
Michel Oosterhof
2015-10-17 08:00:08 +00:00
parent 8b376b86c7
commit 09185e63cf
2 changed files with 21 additions and 10 deletions

View File

@ -124,22 +124,31 @@ class HoneyPotShell(object):
self.interactive = interactive
self.cmdpending = []
self.environ = protocol.environ
#self.lexer.debug = 1
self.showPrompt()
def lineReceived(self, line):
"""
"""
log.msg('CMD: %s' % (line,))
line = line[:500]
comment = re.compile('^\s*#')
for i in [x.strip() for x in re.split(';|&&|\n', line.strip())[:10]]:
if not len(i):
self.lexer = shlex.shlex(punctuation_chars=True);
self.lexer.push_source(line)
tokens = []
while True:
tok = self.lexer.get_token()
log.msg( "tok: %s" % (repr(tok)) )
# for now, execute all after &&
if tok == ';' or tok == self.lexer.eof or tok == '&&':
self.cmdpending.append((tokens))
tokens = []
if tok == ';':
continue
if comment.match(i):
if tok == '&&':
continue
self.cmdpending.append(i)
if tok == self.lexer.eof:
break
tokens.append(tok)
if len(self.cmdpending):
self.runCommand()
else:

View File

@ -13,7 +13,7 @@ import re
import sys
from collections import deque
from io import StringIO
from io import StringIO, BytesIO
__all__ = ["shlex", "split", "quote"]
@ -22,7 +22,8 @@ class shlex:
def __init__(self, instream=None, infile=None, posix=False,
punctuation_chars=False):
if isinstance(instream, str):
instream = StringIO(instream)
#instream = StringIO(instream)
instream = BytesIO(instream)
if instream is not None:
self.instream = instream
self.infile = infile
@ -81,7 +82,8 @@ class shlex:
def push_source(self, newstream, newfile=None):
"Push an input source onto the lexer's input source stack."
if isinstance(newstream, str):
newstream = StringIO(newstream)
#newstream = StringIO(newstream)
newstream = BytesIO(newstream)
self.filestack.appendleft((self.infile, self.instream, self.lineno))
self.infile = newfile
self.instream = newstream