"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Cheetah/SourceReader.py" between
cheetah3-3.1.0.tar.gz and cheetah3-3.2.0.tar.gz

About: Cheetah3 is a template engine and code generation tool for e.g. for Web development or Java, SQL, LaTeX, form email ... (written in Python).

SourceReader.py  (cheetah3-3.1.0):SourceReader.py  (cheetah3-3.2.0)
skipping to change at line 78 skipping to change at line 78
for i in range(len(self._BOLs)): for i in range(len(self._BOLs)):
if pos >= self._BOLs[i] and pos <= self._EOLs[i]: if pos >= self._BOLs[i] and pos <= self._EOLs[i]:
return i return i
def getRowCol(self, pos=None): def getRowCol(self, pos=None):
if pos is None: if pos is None:
pos = self._pos pos = self._pos
lineNum = self.lineNum(pos) lineNum = self.lineNum(pos)
BOL = self._BOLs[lineNum] BOL = self._BOLs[lineNum]
return lineNum+1, pos-BOL+1 return lineNum + 1, pos - BOL + 1
def getRowColLine(self, pos=None): def getRowColLine(self, pos=None):
if pos is None: if pos is None:
pos = self._pos pos = self._pos
row, col = self.getRowCol(pos) row, col = self.getRowCol(pos)
return row, col, self.splitlines()[row-1] return row, col, self.splitlines()[row - 1]
def getLine(self, pos): def getLine(self, pos):
if pos is None: if pos is None:
pos = self._pos pos = self._pos
lineNum = self.lineNum(pos) lineNum = self.lineNum(pos)
return self.splitlines()[lineNum] return self.splitlines()[lineNum]
def pos(self): def pos(self):
return self._pos return self._pos
skipping to change at line 106 skipping to change at line 106
self.checkPos(pos) self.checkPos(pos)
self._pos = pos self._pos = pos
def validPos(self, pos): def validPos(self, pos):
return pos <= self._breakPoint and pos >= 0 return pos <= self._breakPoint and pos >= 0
def checkPos(self, pos): def checkPos(self, pos):
if not pos <= self._breakPoint: if not pos <= self._breakPoint:
raise Error( raise Error(
"pos (" + str(pos) + ") is invalid: beyond the stream's end (" "pos (" + str(pos) + ") is invalid: beyond the stream's end ("
+ str(self._breakPoint-1) + ")") + str(self._breakPoint - 1) + ")")
elif not pos >= 0: elif not pos >= 0:
raise Error("pos (" + str(pos) + ") is invalid: less than 0") raise Error("pos (" + str(pos) + ") is invalid: less than 0")
def breakPoint(self): def breakPoint(self):
return self._breakPoint return self._breakPoint
def setBreakPoint(self, pos): def setBreakPoint(self, pos):
if pos > self._srcLen: if pos > self._srcLen:
raise Error( raise Error(
"New breakpoint (" + str(pos) + "New breakpoint (" + str(pos)
") is invalid: beyond the end of stream's source string (" + + ") is invalid: beyond the end of stream's source string ("
str(self._srcLen) + ")") + str(self._srcLen) + ")")
elif not pos >= 0: elif not pos >= 0:
raise Error( raise Error(
"New breakpoint (" + str(pos) + ") is invalid: less than 0") "New breakpoint (" + str(pos) + ") is invalid: less than 0")
self._breakPoint = pos self._breakPoint = pos
def setBookmark(self, name): def setBookmark(self, name):
self._bookmarks[name] = self._pos self._bookmarks[name] = self._pos
self._posTobookmarkMap[self._pos] = name self._posTobookmarkMap[self._pos] = name
def hasBookmark(self, name): def hasBookmark(self, name):
return name in self._bookmarks return name in self._bookmarks
def gotoBookmark(self, name): def gotoBookmark(self, name):
if not self.hasBookmark(name): if not self.hasBookmark(name):
raise Error( raise Error(
"Invalid bookmark (" + name + ") is invalid: does not exist") "Invalid bookmark (" + name + ") is invalid: does not exist")
pos = self._bookmarks[name] pos = self._bookmarks[name]
if not self.validPos(pos): if not self.validPos(pos):
raise Error("Invalid bookmark (" + name + ', ' + raise Error("Invalid bookmark (" + name + ', '
str(pos) + ") is invalid: pos is out of range") + str(pos) + ") is invalid: pos is out of range")
self._pos = pos self._pos = pos
def atEnd(self): def atEnd(self):
return self._pos >= self._breakPoint return self._pos >= self._breakPoint
def atStart(self): def atStart(self):
return self._pos == 0 return self._pos == 0
def peek(self, offset=0): def peek(self, offset=0):
self.checkPos(self._pos+offset) self.checkPos(self._pos + offset)
pos = self._pos + offset pos = self._pos + offset
return self._src[pos] return self._src[pos]
def getc(self): def getc(self):
pos = self._pos pos = self._pos
if self.validPos(pos+1): if self.validPos(pos + 1):
self._pos += 1 self._pos += 1
return self._src[pos] return self._src[pos]
def ungetc(self, c=None): def ungetc(self, c=None):
if not self.atStart(): if not self.atStart():
raise Error('Already at beginning of stream') raise Error('Already at beginning of stream')
self._pos -= 1 self._pos -= 1
if c is not None: if c is not None:
self._src[self._pos] = c self._src[self._pos] = c
skipping to change at line 216 skipping to change at line 216
def rfind(self, it, pos): def rfind(self, it, pos):
if pos is None: if pos is None:
pos = self._pos pos = self._pos
return self._src.rfind(it, pos) return self._src.rfind(it, pos)
def findBOL(self, pos=None): def findBOL(self, pos=None):
if pos is None: if pos is None:
pos = self._pos pos = self._pos
src = self.src() src = self.src()
return max(src.rfind('\n', 0, pos)+1, src.rfind('\r', 0, pos)+1, 0) return max(src.rfind('\n', 0, pos) + 1, src.rfind('\r', 0, pos) + 1, 0)
def findEOL(self, pos=None, gobble=False): def findEOL(self, pos=None, gobble=False):
if pos is None: if pos is None:
pos = self._pos pos = self._pos
match = EOLZre.search(self.src(), pos) match = EOLZre.search(self.src(), pos)
if gobble: if gobble:
return match.end() return match.end()
else: else:
return match.start() return match.start()
skipping to change at line 251 skipping to change at line 251
def matchWhiteSpace(self, WSchars=' \f\t'): def matchWhiteSpace(self, WSchars=' \f\t'):
return (not self.atEnd()) and self.peek() in WSchars return (not self.atEnd()) and self.peek() in WSchars
def getWhiteSpace(self, max=None, WSchars=' \f\t'): def getWhiteSpace(self, max=None, WSchars=' \f\t'):
if not self.matchWhiteSpace(WSchars): if not self.matchWhiteSpace(WSchars):
return '' return ''
start = self.pos() start = self.pos()
breakPoint = self.breakPoint() breakPoint = self.breakPoint()
if max is not None: if max is not None:
breakPoint = min(breakPoint, self.pos()+max) breakPoint = min(breakPoint, self.pos() + max)
while self.pos() < breakPoint: while self.pos() < breakPoint:
self.advance() self.advance()
if not self.matchWhiteSpace(WSchars): if not self.matchWhiteSpace(WSchars):
break break
return self.src()[start:self.pos()] return self.src()[start:self.pos()]
def matchNonWhiteSpace(self, WSchars=' \f\t\n\r'): def matchNonWhiteSpace(self, WSchars=' \f\t\n\r'):
return self.atEnd() or not self.peek() in WSchars return self.atEnd() or not self.peek() in WSchars
def getNonWhiteSpace(self, WSchars=' \f\t\n\r'): def getNonWhiteSpace(self, WSchars=' \f\t\n\r'):
 End of changes. 9 change blocks. 
12 lines changed or deleted 12 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)