2
0
Fork 0

Fixed a buffer problem, still a queue problem to fix.

This commit is contained in:
Thomas Touhey 2018-05-24 14:43:17 +02:00
parent c682ac247c
commit 2c2ce72719
No known key found for this signature in database
GPG Key ID: 2ECEB0517AD947FB
3 changed files with 26 additions and 3 deletions

View File

@ -125,18 +125,22 @@ class TextoutStream:
def __init__(self, stream):
# If the 'stream' is a string, we want to use standard stream
# functions, so we're gonna enforce them using the `StringIO` class.
if isinstance(stream, str):
stream = _io.StringIO(stream)
# Buffer management.
self.stream = stream
self.buf = ""
# Management of the last tag match.
self.result = None
self.last = None
# Error position.
self.pos = 0
self.line = 0
self.col = 0
@ -148,18 +152,21 @@ class TextoutStream:
def __next__(self):
# If we have a result, process it.
if self.result:
data, self.result = TextoutUnit(self.result), None
self.last = data
return data
# Make sure to have enough data to read.
self.buf += self.stream.read(self.BUFFER_SIZE - len(self.buf))
if not self.buf:
self.last = None
raise StopIteration
# Check that we have a result.
result = self._Tag.search(self.buf, partial = True)
if not result:
text = self.buf
@ -169,6 +176,7 @@ class TextoutStream:
# If there is some text, return it.
# Eventually store the result so we can process it later.
if result.start() > 0:
ret = self.buf[:result.start()]
self.buf = self.buf[result.end():]
@ -178,6 +186,7 @@ class TextoutStream:
return ret
# Process the result now!
self.buf = self.buf[result.end():]
data = TextoutUnit(result)
self.last = data

View File

@ -97,12 +97,16 @@ class TextoutTag:
return ret
def __out(self, name):
""" Generic function to call two output functions of the same type. """
""" Generic function to call two output functions of the same
type. """
getattr(self, '__' + name)()
getattr(self, name + '_' + self.__output_type)()
def __after_preprocess(self):
""" After preprocessing, check the begin, content and end that may
have been set by the preprocessing function. """
ot = self.__output_type
for otype in ('begin', 'content', 'end'):

View File

@ -317,6 +317,11 @@ class Translator:
if dat.ign:
self.cign += 1
# If we're about to put a tag or anything, empty the text block
# here.
self.flush_text()
# If it is a block, end the current block.
if dat.type == dat.BLOCK:
@ -411,6 +416,7 @@ class Translator:
# XXX: I'm unsure about this. Shall raw tags return code
# or text? The text will only be escaped as raw mode is
# still enabled at this point.
self.put_text(content)
else:
self.put_code(content)
@ -506,6 +512,8 @@ class Translator:
def end_block(self):
""" End the current block. """
# Get the original queue.
queue = self.queue.copy()
# We want to collect inline and block tags, in the order they
@ -517,8 +525,10 @@ class Translator:
# Check if the tag has been started and if it is a super
# block (which means we want to stop here).
if dat.super: break
if not dat.started: continue
if dat.super:
break
if not dat.started:
continue
# Then put the tag in the appropriate queue.