Use logging for debug

This commit is contained in:
Florian Bruhin 2014-11-04 20:06:58 +01:00
parent cb76a100c2
commit 9a5df13639
2 changed files with 17 additions and 24 deletions

View File

@ -125,6 +125,7 @@ qt = logging.getLogger('qt') # Warnings produced by Qt
style = logging.getLogger('style') style = logging.getLogger('style')
rfc6266 = logging.getLogger('rfc6266') rfc6266 = logging.getLogger('rfc6266')
ipc = logging.getLogger('ipc') ipc = logging.getLogger('ipc')
shlexer = logging.getLogger('shlexer')
ram_handler = None ram_handler = None

View File

@ -21,6 +21,8 @@
from io import StringIO from io import StringIO
from qutebrowser.utils import log
class ShellLexer: class ShellLexer:
@ -41,10 +43,7 @@ class ShellLexer:
self.escape = '\\' self.escape = '\\'
self.escapedquotes = '"' self.escapedquotes = '"'
self.state = ' ' self.state = ' '
self.debug = 0
self.token = '' self.token = ''
if self.debug:
print('shlex: reading from %s' % (self.instream))
def get_token(self): def get_token(self):
"Get a token from the input stream (or from stack if it's nonempty)" "Get a token from the input stream (or from stack if it's nonempty)"
@ -53,11 +52,10 @@ class ShellLexer:
if raw == self.eof: if raw == self.eof:
return self.eof return self.eof
# Neither inclusion nor EOF # Neither inclusion nor EOF
if self.debug >= 1:
if raw != self.eof: if raw != self.eof:
print("shlex: token=" + repr(raw)) log.shlexer.vdebug("token={!r}".format(raw))
else: else:
print("shlex: token=EOF") log.shlexer.vdebug("token=EOF")
return raw return raw
def read_token(self): def read_token(self):
@ -66,9 +64,8 @@ class ShellLexer:
escapedstate = ' ' escapedstate = ' '
while True: while True:
nextchar = self.instream.read(1) nextchar = self.instream.read(1)
if self.debug >= 3: log.shlexer.vdebug("in state {!r} I see character: {!r}".format(
print("shlex: in state", repr(self.state), "I see character:", self.state, nextchar))
repr(nextchar))
if self.state is None: if self.state is None:
self.token = '' # past end of file self.token = '' # past end of file
break break
@ -77,8 +74,7 @@ class ShellLexer:
self.state = None # end of file self.state = None # end of file
break break
elif nextchar in self.whitespace: elif nextchar in self.whitespace:
if self.debug >= 2: log.shlexer.vdebug("I see whitespace in whitespace state")
print("shlex: I see whitespace in whitespace state")
if self.token or quoted: if self.token or quoted:
break # emit current token break # emit current token
else: else:
@ -94,8 +90,7 @@ class ShellLexer:
elif self.state in self.quotes: elif self.state in self.quotes:
quoted = True quoted = True
if not nextchar: # end of file if not nextchar: # end of file
if self.debug >= 2: log.shlexer.vdebug("I see EOF in quotes state")
print("shlex: I see EOF in quotes state")
# XXX what error should be raised here? # XXX what error should be raised here?
raise ValueError("No closing quotation") raise ValueError("No closing quotation")
if nextchar == self.state: if nextchar == self.state:
@ -108,8 +103,7 @@ class ShellLexer:
self.token = self.token + nextchar self.token = self.token + nextchar
elif self.state in self.escape: elif self.state in self.escape:
if not nextchar: # end of file if not nextchar: # end of file
if self.debug >= 2: log.shlexer.vdebug("I see EOF in escape state")
print("shlex: I see EOF in escape state")
# XXX what error should be raised here? # XXX what error should be raised here?
raise ValueError("No escaped character") raise ValueError("No escaped character")
# In posix shells, only the quote itself or the escape # In posix shells, only the quote itself or the escape
@ -124,8 +118,7 @@ class ShellLexer:
self.state = None # end of file self.state = None # end of file
break break
elif nextchar in self.whitespace: elif nextchar in self.whitespace:
if self.debug >= 2: log.shlexer.vdebug("shlex: I see whitespace in word state")
print("shlex: I see whitespace in word state")
self.state = ' ' self.state = ' '
if self.token or quoted: if self.token or quoted:
break # emit current token break # emit current token
@ -142,11 +135,10 @@ class ShellLexer:
self.token = '' self.token = ''
if not quoted and result == '': if not quoted and result == '':
result = None result = None
if self.debug > 1:
if result: if result:
print("shlex: raw token=" + repr(result)) log.shlexer.debug("raw token={!r}".format(result))
else: else:
print("shlex: raw token=EOF") log.shlexer.debug("raw token=EOF")
return result return result
def __iter__(self): def __iter__(self):