Created
March 14, 2011 14:44
-
-
Save mdboom/869225 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- src/pyparsing_py3.py 2011-03-11 13:18:54.000000000 -0500 | |
+++ ../matplotlib-py3/lib/matplotlib/pyparsing_py3.py 2011-03-11 12:40:24.000000000 -0500 | |
@@ -58,8 +58,8 @@ | |
- embedded comments | |
""" | |
-__version__ = "1.5.4" | |
-__versionTime__ = "10 Aug 2010 09:19" | |
+__version__ = "1.5.5" | |
+__versionTime__ = "12 Aug 2010 03:56" | |
__author__ = "Paul McGuire <[email protected]>" | |
import string | |
@@ -139,10 +139,10 @@ | |
# build list of single arg builtins, tolerant of Python version, that can be used as parse actions | |
singleArgBuiltins = [] | |
-import builtin | |
+import builtins | |
for fname in "sum len enumerate sorted reversed list tuple set any all".split(): | |
try: | |
- singleArgBuiltins.append(getattr(builtin,fname)) | |
+ singleArgBuiltins.append(getattr(builtins,fname)) | |
except AttributeError: | |
continue | |
@@ -938,15 +938,11 @@ | |
loc,tokens = self.parseImpl( instring, preloc, doActions ) | |
except IndexError: | |
raise ParseException( instring, len(instring), self.errmsg, self ) | |
- except ParseBaseException: | |
+ except ParseBaseException as err: | |
#~ print ("Exception raised:", err) | |
- err = None | |
if self.debugActions[2]: | |
- err = sys.exc_info()[1] | |
self.debugActions[2]( instring, tokensStart, self, err ) | |
if self.failAction: | |
- if err is None: | |
- err = sys.exc_info()[1] | |
self.failAction( instring, tokensStart, self, err ) | |
raise | |
else: | |
@@ -976,10 +972,9 @@ | |
self.resultsName, | |
asList=self.saveAsList and isinstance(tokens,(ParseResults,list)), | |
modal=self.modalResults ) | |
- except ParseBaseException: | |
+ except ParseBaseException as err: | |
#~ print "Exception raised in user parse action:", err | |
if (self.debugActions[2] ): | |
- err = sys.exc_info()[1] | |
self.debugActions[2]( instring, tokensStart, self, err ) | |
raise | |
else: | |
@@ -1010,7 +1005,7 @@ | |
lookup = (self,instring,loc,callPreParse,doActions) | |
if lookup in ParserElement._exprArgCache: | |
value = ParserElement._exprArgCache[ lookup ] | |
- if isinstance(value,Exception): | |
+ if isinstance(value, Exception): | |
raise value | |
return value | |
else: | |
@@ -1018,9 +1013,9 @@ | |
value = self._parseNoCache( instring, loc, doActions, callPreParse ) | |
ParserElement._exprArgCache[ lookup ] = (value[0],value[1].copy()) | |
return value | |
- except ParseBaseException: | |
- pe = sys.exc_info()[1] | |
- ParserElement._exprArgCache[ lookup ] = pe | |
+ except ParseBaseException as err: | |
+ err.__traceback__ = None | |
+ ParserElement._exprArgCache[ lookup ] = err | |
raise | |
_parse = _parseNoCache | |
@@ -1089,13 +1084,12 @@ | |
#loc = self.preParse( instring, loc ) | |
se = StringEnd() | |
se._parse( instring, loc ) | |
- except ParseBaseException: | |
+ except ParseBaseException as err: | |
if ParserElement.verbose_stacktrace: | |
raise | |
else: | |
# catch and re-raise exception from here, clears out pyparsing internal stack trace | |
- exc = sys.exc_info()[1] | |
- raise exc | |
+ raise err | |
else: | |
return tokens | |
@@ -1134,13 +1128,12 @@ | |
loc = nextLoc | |
else: | |
loc = preloc+1 | |
- except ParseBaseException: | |
+ except ParseBaseException as err: | |
if ParserElement.verbose_stacktrace: | |
raise | |
else: | |
# catch and re-raise exception from here, clears out pyparsing internal stack trace | |
- exc = sys.exc_info()[1] | |
- raise exc | |
+ raise err | |
def transformString( self, instring ): | |
"""Extension to C{scanString}, to modify matching text with modified tokens that may | |
@@ -1167,13 +1160,12 @@ | |
lastE = e | |
out.append(instring[lastE:]) | |
return "".join(map(_ustr,out)) | |
- except ParseBaseException: | |
+ except ParseBaseException as err: | |
if ParserElement.verbose_stacktrace: | |
raise | |
else: | |
# catch and re-raise exception from here, clears out pyparsing internal stack trace | |
- exc = sys.exc_info()[1] | |
- raise exc | |
+ raise err | |
def searchString( self, instring, maxMatches=_MAX_INT ): | |
"""Another extension to C{scanString}, simplifying the access to the tokens found | |
@@ -1182,13 +1174,12 @@ | |
""" | |
try: | |
return ParseResults([ t for t,s,e in self.scanString( instring, maxMatches ) ]) | |
- except ParseBaseException: | |
+ except ParseBaseException as err: | |
if ParserElement.verbose_stacktrace: | |
raise | |
else: | |
# catch and re-raise exception from here, clears out pyparsing internal stack trace | |
- exc = sys.exc_info()[1] | |
- raise exc | |
+ raise err | |
def __add__(self, other ): | |
"""Implementation of + operator - returns And""" | |
@@ -1462,20 +1453,9 @@ | |
f.close() | |
try: | |
return self.parseString(file_contents, parseAll) | |
- except ParseBaseException: | |
+ except ParseBaseException as err: | |
# catch and re-raise exception from here, clears out pyparsing internal stack trace | |
- exc = sys.exc_info()[1] | |
- raise exc | |
- | |
- def getException(self): | |
- return ParseException("",0,self.errmsg,self) | |
- | |
- def __getattr__(self,aname): | |
- if aname == "myException": | |
- self.myException = ret = self.getException(); | |
- return ret; | |
- else: | |
- raise AttributeError("no such attribute " + aname) | |
+ raise err | |
def __eq__(self,other): | |
if isinstance(other, ParserElement): | |
@@ -1535,10 +1515,7 @@ | |
#self.myException.msg = self.errmsg | |
def parseImpl( self, instring, loc, doActions=True ): | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException(instring, loc, self.errmsg, self) | |
class Literal(Token): | |
@@ -1567,11 +1544,7 @@ | |
if (instring[loc] == self.firstMatchChar and | |
(self.matchLen==1 or instring.startswith(self.match,loc)) ): | |
return loc+self.matchLen, self.match | |
- #~ raise ParseException( instring, loc, self.errmsg ) | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
_L = Literal | |
class Keyword(Token): | |
@@ -1618,11 +1591,7 @@ | |
(loc >= len(instring)-self.matchLen or instring[loc+self.matchLen] not in self.identChars) and | |
(loc == 0 or instring[loc-1] not in self.identChars) ): | |
return loc+self.matchLen, self.match | |
- #~ raise ParseException( instring, loc, self.errmsg ) | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
def copy(self): | |
c = super(Keyword,self).copy() | |
@@ -1651,11 +1620,7 @@ | |
def parseImpl( self, instring, loc, doActions=True ): | |
if instring[ loc:loc+self.matchLen ].upper() == self.match: | |
return loc+self.matchLen, self.returnString | |
- #~ raise ParseException( instring, loc, self.errmsg ) | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
class CaselessKeyword(Keyword): | |
def __init__( self, matchString, identChars=Keyword.DEFAULT_KEYWORD_CHARS ): | |
@@ -1665,11 +1630,7 @@ | |
if ( (instring[ loc:loc+self.matchLen ].upper() == self.caselessmatch) and | |
(loc >= len(instring)-self.matchLen or instring[loc+self.matchLen].upper() not in self.identChars) ): | |
return loc+self.matchLen, self.match | |
- #~ raise ParseException( instring, loc, self.errmsg ) | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
class Word(Token): | |
"""Token for matching words composed of allowed character sets. | |
@@ -1735,20 +1696,13 @@ | |
if self.re: | |
result = self.re.match(instring,loc) | |
if not result: | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException(instring, loc, self.errmsg, self) | |
loc = result.end() | |
return loc,result.group() | |
if not(instring[ loc ] in self.initChars): | |
- #~ raise ParseException( instring, loc, self.errmsg ) | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
start = loc | |
loc += 1 | |
instrlen = len(instring) | |
@@ -1768,11 +1722,7 @@ | |
throwException = True | |
if throwException: | |
- #~ raise ParseException( instring, loc, self.errmsg ) | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
return loc, instring[start:loc] | |
@@ -1842,10 +1792,7 @@ | |
def parseImpl( self, instring, loc, doActions=True ): | |
result = self.re.match(instring,loc) | |
if not result: | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException(instring, loc, self.errmsg, self) | |
loc = result.end() | |
d = result.groupdict() | |
@@ -1947,10 +1894,7 @@ | |
def parseImpl( self, instring, loc, doActions=True ): | |
result = instring[loc] == self.firstQuoteChar and self.re.match(instring,loc) or None | |
if not result: | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException(instring, loc, self.errmsg, self) | |
loc = result.end() | |
ret = result.group() | |
@@ -2017,11 +1961,7 @@ | |
def parseImpl( self, instring, loc, doActions=True ): | |
if instring[loc] in self.notChars: | |
- #~ raise ParseException( instring, loc, self.errmsg ) | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
start = loc | |
loc += 1 | |
@@ -2032,11 +1972,7 @@ | |
loc += 1 | |
if loc - start < self.minLen: | |
- #~ raise ParseException( instring, loc, self.errmsg ) | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
return loc, instring[start:loc] | |
@@ -2090,11 +2026,7 @@ | |
def parseImpl( self, instring, loc, doActions=True ): | |
if not(instring[ loc ] in self.matchWhite): | |
- #~ raise ParseException( instring, loc, self.errmsg ) | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
start = loc | |
loc += 1 | |
maxloc = start + self.maxLen | |
@@ -2103,11 +2035,7 @@ | |
loc += 1 | |
if loc - start < self.minLen: | |
- #~ raise ParseException( instring, loc, self.errmsg ) | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
return loc, instring[start:loc] | |
@@ -2160,11 +2088,7 @@ | |
if not( loc==0 or | |
(loc == self.preParse( instring, 0 )) or | |
(instring[loc-1] == "\n") ): #col(loc, instring) != 1: | |
- #~ raise ParseException( instring, loc, "Expected start of line" ) | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
return loc, [] | |
class LineEnd(_PositionToken): | |
@@ -2180,18 +2104,11 @@ | |
if instring[loc] == "\n": | |
return loc+1, "\n" | |
else: | |
- #~ raise ParseException( instring, loc, "Expected end of line" ) | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
elif loc == len(instring): | |
return loc+1, [] | |
else: | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
class StringStart(_PositionToken): | |
"""Matches if current position is at the beginning of the parse string""" | |
@@ -2204,11 +2121,7 @@ | |
if loc != 0: | |
# see if entire string up to here is just whitespace and ignoreables | |
if loc != self.preParse( instring, 0 ): | |
- #~ raise ParseException( instring, loc, "Expected start of text" ) | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
return loc, [] | |
class StringEnd(_PositionToken): | |
@@ -2220,20 +2133,13 @@ | |
def parseImpl( self, instring, loc, doActions=True ): | |
if loc < len(instring): | |
- #~ raise ParseException( instring, loc, "Expected end of text" ) | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
elif loc == len(instring): | |
return loc+1, [] | |
elif loc > len(instring): | |
return loc, [] | |
else: | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
class WordStart(_PositionToken): | |
"""Matches if the current position is at the beginning of a Word, and | |
@@ -2251,10 +2157,7 @@ | |
if loc != 0: | |
if (instring[loc-1] in self.wordChars or | |
instring[loc] not in self.wordChars): | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
return loc, [] | |
class WordEnd(_PositionToken): | |
@@ -2275,11 +2178,7 @@ | |
if instrlen>0 and loc<instrlen: | |
if (instring[loc] in self.wordChars or | |
instring[loc-1] not in self.wordChars): | |
- #~ raise ParseException( instring, loc, "Expected end of word" ) | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
return loc, [] | |
@@ -2415,9 +2314,9 @@ | |
loc, exprtokens = e._parse( instring, loc, doActions ) | |
except ParseSyntaxException: | |
raise | |
- except ParseBaseException: | |
- pe = sys.exc_info()[1] | |
- raise ParseSyntaxException(pe) | |
+ except ParseBaseException as e: | |
+ e.__traceback__ = None | |
+ raise ParseSyntaxException(e) | |
except IndexError: | |
raise ParseSyntaxException( ParseException(instring, len(instring), self.errmsg, self) ) | |
else: | |
@@ -2468,8 +2367,8 @@ | |
for e in self.exprs: | |
try: | |
loc2 = e.tryParse( instring, loc ) | |
- except ParseException: | |
- err = sys.exc_info()[1] | |
+ except ParseException as err: | |
+ err.__traceback__ = None | |
if err.loc > maxExcLoc: | |
maxException = err | |
maxExcLoc = err.loc | |
@@ -2766,11 +2665,7 @@ | |
except (ParseException,IndexError): | |
pass | |
else: | |
- #~ raise ParseException(instring, loc, self.errmsg ) | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
return loc, [] | |
def __str__( self ): | |
@@ -2959,10 +2854,7 @@ | |
raise | |
else: | |
loc += 1 | |
- exc = self.myException | |
- exc.loc = loc | |
- exc.pstr = instring | |
- raise exc | |
+ raise ParseException( instring, loc, self.errmsg, self ) | |
class Forward(ParseElementEnhance): | |
"""Forward declaration of an expression to be defined later - | |
@@ -3166,10 +3058,9 @@ | |
sys.stderr.write( ">>entering %s(line: '%s', %d, %s)\n" % (thisFunc,line(l,s),l,t) ) | |
try: | |
ret = f(*paArgs) | |
- except Exception: | |
- exc = sys.exc_info()[1] | |
+ except Exception as exc: | |
sys.stderr.write( "<<leaving %s (exception: %s)\n" % (thisFunc,exc) ) | |
- raise | |
+ raise | |
sys.stderr.write( "<<leaving %s (ret: %s)\n" % (thisFunc,ret) ) | |
return ret | |
try: | |
@@ -3758,8 +3649,7 @@ | |
print ("tokens.columns = " + str(tokens.columns)) | |
print ("tokens.tables = " + str(tokens.tables)) | |
print (tokens.asXML("SQL",True)) | |
- except ParseBaseException: | |
- err = sys.exc_info()[1] | |
+ except ParseBaseException as err: | |
print (teststring + "->") | |
print (err.line) | |
print (" "*(err.column-1) + "^") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment