mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-26 08:56:36 +00:00
bcanvas/CanvasImportStore.py:importTextBuffer(): handle exceptions.
This commit is contained in:
parent
f6afcd735a
commit
1d927bf2b9
@ -93,47 +93,50 @@ class CanvasImportStore():
|
|||||||
# }}}
|
# }}}
|
||||||
# {{{ importTextBuffer(self, inFile)
|
# {{{ importTextBuffer(self, inFile)
|
||||||
def importTextBuffer(self, inFile):
|
def importTextBuffer(self, inFile):
|
||||||
inLine, outMap, outMaxCols = inFile.readline(), [], 0
|
try:
|
||||||
while inLine:
|
inLine, outMap, outMaxCols = inFile.readline(), [], 0
|
||||||
inCellState, inCurCol, inCurColours, inMaxCol = self._CellState.CS_NONE, 0, (15, -1), len(inLine); outMap.append([]);
|
while inLine:
|
||||||
while inCurCol < inMaxCol:
|
inCellState, inCurCol, inCurColours, inMaxCol = self._CellState.CS_NONE, 0, (15, -1), len(inLine); outMap.append([]);
|
||||||
inChar = inLine[inCurCol]
|
while inCurCol < inMaxCol:
|
||||||
if inChar in set("\r\n"):
|
inChar = inLine[inCurCol]
|
||||||
inCurCol += 1
|
if inChar in set("\r\n"):
|
||||||
elif inChar == "\u0002":
|
inCurCol += 1
|
||||||
inCellState = self._flipCellStateBit(self._CellState.CS_BOLD, inCellState); inCurCol += 1;
|
elif inChar == "\u0002":
|
||||||
elif inChar == "\u0003":
|
inCellState = self._flipCellStateBit(self._CellState.CS_BOLD, inCellState); inCurCol += 1;
|
||||||
m = re.match("\u0003((1[0-5]|0?[0-9])?(?:,(1[0-5]|0?[0-9]))?)", inLine[inCurCol:])
|
elif inChar == "\u0003":
|
||||||
if m:
|
m = re.match("\u0003((1[0-5]|0?[0-9])?(?:,(1[0-5]|0?[0-9]))?)", inLine[inCurCol:])
|
||||||
if (m[2] != None) and (m[3] != None):
|
if m:
|
||||||
inCurColours = (int(m[2]), int(m[3]))
|
if (m[2] != None) and (m[3] != None):
|
||||||
elif (m[2] != None) and (m[3] == None):
|
inCurColours = (int(m[2]), int(m[3]))
|
||||||
inCurColours = (int(m[2]), int(inCurColours[1]))
|
elif (m[2] != None) and (m[3] == None):
|
||||||
|
inCurColours = (int(m[2]), int(inCurColours[1]))
|
||||||
|
else:
|
||||||
|
inCurColours = (15, -1)
|
||||||
|
inCurCol += len(m[0])
|
||||||
else:
|
else:
|
||||||
inCurColours = (15, -1)
|
inCurColours = (15, -1); inCurCol += 1;
|
||||||
inCurCol += len(m[0])
|
elif inChar == "\u0006":
|
||||||
|
inCellState = self._flipCellStateBit(self._CellState.CS_ITALIC, inCellState); inCurCol += 1;
|
||||||
|
elif inChar == "\u000f":
|
||||||
|
inCellState |= self._CellState.CS_NONE; inCurColours = (15, -1); inCurCol += 1;
|
||||||
|
elif inChar == "\u0016":
|
||||||
|
inCurColours = (inCurColours[1], inCurColours[0]); inCurCol += 1;
|
||||||
|
elif inChar == "\u001f":
|
||||||
|
inCellState = self._flipCellStateBit(self._CellState.CS_UNDERLINE, inCellState); inCurCol += 1;
|
||||||
else:
|
else:
|
||||||
inCurColours = (15, -1); inCurCol += 1;
|
outMap[-1].append([*inCurColours, inCellState, inChar]); inCurCol += 1;
|
||||||
elif inChar == "\u0006":
|
inLine, outMaxCols = inFile.readline(), max(outMaxCols, len(outMap[-1]))
|
||||||
inCellState = self._flipCellStateBit(self._CellState.CS_ITALIC, inCellState); inCurCol += 1;
|
if (len(outMap) > 1) \
|
||||||
elif inChar == "\u000f":
|
or ((len(outMap) == 1) and len(outMap[0])):
|
||||||
inCellState |= self._CellState.CS_NONE; inCurColours = (15, -1); inCurCol += 1;
|
for numRow in range(len(outMap)):
|
||||||
elif inChar == "\u0016":
|
for numCol in range(len(outMap[numRow]), outMaxCols):
|
||||||
inCurColours = (inCurColours[1], inCurColours[0]); inCurCol += 1;
|
outMap[numRow].append([15, -1, self._CellState.CS_NONE, " "])
|
||||||
elif inChar == "\u001f":
|
self.inSize, self.outMap = [outMaxCols, len(outMap)], outMap
|
||||||
inCellState = self._flipCellStateBit(self._CellState.CS_UNDERLINE, inCellState); inCurCol += 1;
|
return (True, None)
|
||||||
else:
|
else:
|
||||||
outMap[-1].append([*inCurColours, inCellState, inChar]); inCurCol += 1;
|
return (False, "empty output map")
|
||||||
inLine, outMaxCols = inFile.readline(), max(outMaxCols, len(outMap[-1]))
|
except:
|
||||||
if (len(outMap) > 1) \
|
return (False, sys.exc_info()[1])
|
||||||
or ((len(outMap) == 1) and len(outMap[0])):
|
|
||||||
for numRow in range(len(outMap)):
|
|
||||||
for numCol in range(len(outMap[numRow]), outMaxCols):
|
|
||||||
outMap[numRow].append([15, -1, self._CellState.CS_NONE, " "])
|
|
||||||
self.inSize, self.outMap = [outMaxCols, len(outMap)], outMap
|
|
||||||
return (True, None)
|
|
||||||
else:
|
|
||||||
return (False, "empty output map")
|
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ importTextFile(self, pathName)
|
# {{{ importTextFile(self, pathName)
|
||||||
def importTextFile(self, pathName):
|
def importTextFile(self, pathName):
|
||||||
|
Loading…
Reference in New Issue
Block a user