def _tokenize(self, handle):
for line in handle:
if line.startswith("#"):
continue
elif line.startswith(";"):
token = line[1:].strip()
for line in handle:
line = line.strip()
if line == ';':
break
token += line
yield token
else:
try:
tokens = shlex.split(line)
except ValueError:
# error "No closing quotation"
line = line.replace("'",'"')
# if odd - add a closing " to that line
if not line.count('"') % 2 == 0:
line = '{}"'.format(line)
tokens = shlex.split(line)
for token in tokens:
yield token
评论列表
文章目录