Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1df5f54

Browse files
committed
Remove code that tries to synch Py2 and Py3 versions of code - this branch is now Py2-only
1 parent de60e3d commit 1df5f54

File tree

6 files changed

+54
-7449
lines changed

6 files changed

+54
-7449
lines changed

src/CHANGES

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
Change Log
33
==========
44

5-
Version 1.5.7 - October, 2012
5+
Version 1.5.7 - November, 2012
66
-----------------------------
77
- NOTE: This is the last release of pyparsing that will try to
88
maintain compatibility with Python versions < 2.6. The next
9-
release of pyparsing will be version 1.6.0, using new Python
9+
release of pyparsing will be version 2.0.0, using new Python
1010
syntax that will not be compatible for Python version 2.5 or
1111
older.
1212

src/makeRelease.bat

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
set MAKING_PYPARSING_RELEASE=1
22

3-
copy ..\sourceforge\svn\trunk\src\CHANGES .
4-
copy ..\sourceforge\svn\trunk\src\setup.py .
5-
copy ..\sourceforge\svn\trunk\src\pyparsing_py2.py .
6-
copy ..\sourceforge\svn\trunk\src\pyparsing_py3.py .
3+
copy ..\sourceforge\svn\pyparsing_1.5.x\src\CHANGES .
4+
copy ..\sourceforge\svn\pyparsing_1.5.x\src\setup.py .
5+
copy ..\sourceforge\svn\pyparsing_1.5.x\src\pyparsing.py .
76

8-
if exist pyparsing.py del pyparsing.py
97
rmdir build
108
rmdir dist
119

@@ -16,15 +14,9 @@ python setup.py sdist --formats=gztar,zip
1614
copy/y MANIFEST.in_bdist MANIFEST.in
1715
if exist MANIFEST del MANIFEST
1816

19-
copy/y pyparsing_py2.py pyparsing.py
2017
python setup.py bdist_wininst --target-version=2.4 --plat-name=win32
2118
python setup.py bdist_wininst --target-version=2.5 --plat-name=win32
2219
python setup.py bdist_wininst --target-version=2.6 --plat-name=win32
2320
python setup.py bdist_wininst --target-version=2.7 --plat-name=win32
2421

25-
copy/y pyparsing_py3.py pyparsing.py
26-
python setup.py bdist_wininst --target-version=3.0 --plat-name=win32
27-
python setup.py bdist_wininst --target-version=3.1 --plat-name=win32
28-
python setup.py bdist_wininst --target-version=3.2 --plat-name=win32
29-
3022
set MAKING_PYPARSING_RELEASE=

src/pyparsing.py

+47-69
Original file line numberDiff line numberDiff line change
@@ -91,47 +91,36 @@ class names, and the use of '+', '|' and '^' operators.
9191
'indentedBlock', 'originalTextFor', 'ungroup', 'infixNotation',
9292
]
9393

94-
"""
95-
Detect if we are running version 3.X and make appropriate changes
96-
Robert A. Clark
97-
"""
98-
_PY3K = sys.version_info[0] > 2
99-
if _PY3K:
100-
_MAX_INT = sys.maxsize
101-
basestring = str
102-
unichr = chr
103-
_ustr = str
104-
else:
105-
_MAX_INT = sys.maxint
106-
range = xrange
107-
set = lambda s : dict( [(c,0) for c in s] )
108-
109-
def _ustr(obj):
110-
"""Drop-in replacement for str(obj) that tries to be Unicode friendly. It first tries
111-
str(obj). If that fails with a UnicodeEncodeError, then it tries unicode(obj). It
112-
then < returns the unicode object | encodes it with the default encoding | ... >.
113-
"""
114-
if isinstance(obj,unicode):
115-
return obj
94+
_MAX_INT = sys.maxint
95+
range = xrange
96+
set = lambda s : dict( [(c,0) for c in s] )
97+
98+
def _ustr(obj):
99+
"""Drop-in replacement for str(obj) that tries to be Unicode friendly. It first tries
100+
str(obj). If that fails with a UnicodeEncodeError, then it tries unicode(obj). It
101+
then < returns the unicode object | encodes it with the default encoding | ... >.
102+
"""
103+
if isinstance(obj,unicode):
104+
return obj
116105

117-
try:
118-
# If this works, then _ustr(obj) has the same behaviour as str(obj), so
119-
# it won't break any existing code.
120-
return str(obj)
121-
122-
except UnicodeEncodeError:
123-
# The Python docs (http://docs.python.org/ref/customization.html#l2h-182)
124-
# state that "The return value must be a string object". However, does a
125-
# unicode object (being a subclass of basestring) count as a "string
126-
# object"?
127-
# If so, then return a unicode object:
128-
return unicode(obj)
129-
# Else encode it... but how? There are many choices... :)
130-
# Replace unprintables with escape codes?
131-
#return unicode(obj).encode(sys.getdefaultencoding(), 'backslashreplace_errors')
132-
# Replace unprintables with question marks?
133-
#return unicode(obj).encode(sys.getdefaultencoding(), 'replace')
134-
# ...
106+
try:
107+
# If this works, then _ustr(obj) has the same behaviour as str(obj), so
108+
# it won't break any existing code.
109+
return str(obj)
110+
111+
except UnicodeEncodeError:
112+
# The Python docs (http://docs.python.org/ref/customization.html#l2h-182)
113+
# state that "The return value must be a string object". However, does a
114+
# unicode object (being a subclass of basestring) count as a "string
115+
# object"?
116+
# If so, then return a unicode object:
117+
return unicode(obj)
118+
# Else encode it... but how? There are many choices... :)
119+
# Replace unprintables with escape codes?
120+
#return unicode(obj).encode(sys.getdefaultencoding(), 'backslashreplace_errors')
121+
# Replace unprintables with question marks?
122+
#return unicode(obj).encode(sys.getdefaultencoding(), 'replace')
123+
# ...
135124

136125
# build list of single arg builtins, tolerant of Python version, that can be used as parse actions
137126
singleArgBuiltins = []
@@ -860,15 +849,12 @@ def _parseNoCache( self, instring, loc, doActions=True, callPreParse=True ):
860849
loc,tokens = self.parseImpl( instring, preloc, doActions )
861850
except IndexError:
862851
raise ParseException( instring, len(instring), self.errmsg, self )
863-
except ParseBaseException:
852+
except ParseBaseException, err:
864853
#~ print ("Exception raised:", err)
865854
err = None
866855
if self.debugActions[2]:
867-
err = sys.exc_info()[1]
868856
self.debugActions[2]( instring, tokensStart, self, err )
869857
if self.failAction:
870-
if err is None:
871-
err = sys.exc_info()[1]
872858
self.failAction( instring, tokensStart, self, err )
873859
raise
874860
else:
@@ -898,10 +884,9 @@ def _parseNoCache( self, instring, loc, doActions=True, callPreParse=True ):
898884
self.resultsName,
899885
asList=self.saveAsList and isinstance(tokens,(ParseResults,list)),
900886
modal=self.modalResults )
901-
except ParseBaseException:
887+
except ParseBaseException, err:
902888
#~ print "Exception raised in user parse action:", err
903889
if (self.debugActions[2] ):
904-
err = sys.exc_info()[1]
905890
self.debugActions[2]( instring, tokensStart, self, err )
906891
raise
907892
else:
@@ -940,8 +925,7 @@ def _parseCache( self, instring, loc, doActions=True, callPreParse=True ):
940925
value = self._parseNoCache( instring, loc, doActions, callPreParse )
941926
ParserElement._exprArgCache[ lookup ] = (value[0],value[1].copy())
942927
return value
943-
except ParseBaseException:
944-
pe = sys.exc_info()[1]
928+
except ParseBaseException, pe:
945929
ParserElement._exprArgCache[ lookup ] = pe
946930
raise
947931

@@ -1011,12 +995,11 @@ def parseString( self, instring, parseAll=False ):
1011995
loc = self.preParse( instring, loc )
1012996
se = Empty() + StringEnd()
1013997
se._parse( instring, loc )
1014-
except ParseBaseException:
998+
except ParseBaseException, exc:
1015999
if ParserElement.verbose_stacktrace:
10161000
raise
10171001
else:
10181002
# catch and re-raise exception from here, clears out pyparsing internal stack trace
1019-
exc = sys.exc_info()[1]
10201003
raise exc
10211004
else:
10221005
return tokens
@@ -1064,12 +1047,11 @@ def scanString( self, instring, maxMatches=_MAX_INT, overlap=False ):
10641047
loc = nextLoc
10651048
else:
10661049
loc = preloc+1
1067-
except ParseBaseException:
1050+
except ParseBaseException, exc:
10681051
if ParserElement.verbose_stacktrace:
10691052
raise
10701053
else:
10711054
# catch and re-raise exception from here, clears out pyparsing internal stack trace
1072-
exc = sys.exc_info()[1]
10731055
raise exc
10741056

10751057
def transformString( self, instring ):
@@ -1098,12 +1080,11 @@ def transformString( self, instring ):
10981080
out.append(instring[lastE:])
10991081
out = [o for o in out if o]
11001082
return "".join(map(_ustr,_flatten(out)))
1101-
except ParseBaseException:
1083+
except ParseBaseException, exc:
11021084
if ParserElement.verbose_stacktrace:
11031085
raise
11041086
else:
11051087
# catch and re-raise exception from here, clears out pyparsing internal stack trace
1106-
exc = sys.exc_info()[1]
11071088
raise exc
11081089

11091090
def searchString( self, instring, maxMatches=_MAX_INT ):
@@ -1113,12 +1094,11 @@ def searchString( self, instring, maxMatches=_MAX_INT ):
11131094
"""
11141095
try:
11151096
return ParseResults([ t for t,s,e in self.scanString( instring, maxMatches ) ])
1116-
except ParseBaseException:
1097+
except ParseBaseException, exc:
11171098
if ParserElement.verbose_stacktrace:
11181099
raise
11191100
else:
11201101
# catch and re-raise exception from here, clears out pyparsing internal stack trace
1121-
exc = sys.exc_info()[1]
11221102
raise exc
11231103

11241104
def __add__(self, other ):
@@ -1396,10 +1376,12 @@ def parseFile( self, file_or_filename, parseAll=False ):
13961376
f.close()
13971377
try:
13981378
return self.parseString(file_contents, parseAll)
1399-
except ParseBaseException:
1400-
# catch and re-raise exception from here, clears out pyparsing internal stack trace
1401-
exc = sys.exc_info()[1]
1402-
raise exc
1379+
except ParseBaseException, exc:
1380+
if ParserElement.verbose_stacktrace:
1381+
raise
1382+
else:
1383+
# catch and re-raise exception from here, clears out pyparsing internal stack trace
1384+
raise exc
14031385

14041386
def getException(self):
14051387
return ParseException("",0,self.errmsg,self)
@@ -2348,8 +2330,7 @@ def parseImpl( self, instring, loc, doActions=True ):
23482330
loc, exprtokens = e._parse( instring, loc, doActions )
23492331
except ParseSyntaxException:
23502332
raise
2351-
except ParseBaseException:
2352-
pe = sys.exc_info()[1]
2333+
except ParseBaseException, pe:
23532334
raise ParseSyntaxException(pe)
23542335
except IndexError:
23552336
raise ParseSyntaxException( ParseException(instring, len(instring), self.errmsg, self) )
@@ -2401,8 +2382,7 @@ def parseImpl( self, instring, loc, doActions=True ):
24012382
for e in self.exprs:
24022383
try:
24032384
loc2 = e.tryParse( instring, loc )
2404-
except ParseException:
2405-
err = sys.exc_info()[1]
2385+
except ParseException, err:
24062386
if err.loc > maxExcLoc:
24072387
maxException = err
24082388
maxExcLoc = err.loc
@@ -2984,7 +2964,7 @@ def __init__(self, *args):
29842964
DeprecationWarning,stacklevel=2)
29852965

29862966
def postParse( self, instring, loc, tokenlist ):
2987-
return list(map( string.upper, tokenlist ))
2967+
return list(map( str.upper, tokenlist ))
29882968

29892969

29902970
class Combine(TokenConverter):
@@ -3096,8 +3076,7 @@ def z(*paArgs):
30963076
sys.stderr.write( ">>entering %s(line: '%s', %d, %s)\n" % (thisFunc,line(l,s),l,t) )
30973077
try:
30983078
ret = f(*paArgs)
3099-
except Exception:
3100-
exc = sys.exc_info()[1]
3079+
except Exception, exc:
31013080
sys.stderr.write( "<<leaving %s (exception: %s)\n" % (thisFunc,exc) )
31023081
raise
31033082
sys.stderr.write( "<<leaving %s (ret: %s)\n" % (thisFunc,ret) )
@@ -3709,8 +3688,7 @@ def test( teststring ):
37093688
print ("tokens.columns = " + str(tokens.columns))
37103689
print ("tokens.tables = " + str(tokens.tables))
37113690
print (tokens.asXML("SQL",True))
3712-
except ParseBaseException:
3713-
err = sys.exc_info()[1]
3691+
except ParseBaseException, err:
37143692
print (teststring + "->")
37153693
print (err.line)
37163694
print (" "*(err.column-1) + "^")

0 commit comments

Comments
 (0)