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

Skip to content

Commit 6f2df4d

Browse files
committed
Run 2to3 over the Demo/ directory to shut up parse errors from 2to3 about lingering print statements.
1 parent a8c360e commit 6f2df4d

132 files changed

Lines changed: 1071 additions & 1081 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Demo/cgi/cgi1.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# If cgi0.sh works but cgi1.py doesn't, check the #! line and the file
99
# permissions. The docs for the cgi.py module have debugging tips.
1010

11-
print "Content-type: text/html"
12-
print
13-
print "<h1>Hello world</h1>"
14-
print "<p>This is cgi1.py"
11+
print("Content-type: text/html")
12+
print()
13+
print("<h1>Hello world</h1>")
14+
print("<p>This is cgi1.py")

Demo/cgi/cgi2.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
def main():
1010
form = cgi.FieldStorage()
11-
print "Content-type: text/html"
12-
print
11+
print("Content-type: text/html")
12+
print()
1313
if not form:
14-
print "<h1>No Form Keys</h1>"
14+
print("<h1>No Form Keys</h1>")
1515
else:
16-
print "<h1>Form Keys</h1>"
17-
for key in form.keys():
16+
print("<h1>Form Keys</h1>")
17+
for key in list(form.keys()):
1818
value = form[key].value
19-
print "<p>", cgi.escape(key), ":", cgi.escape(value)
19+
print("<p>", cgi.escape(key), ":", cgi.escape(value))
2020

2121
if __name__ == "__main__":
2222
main()

Demo/cgi/wiki.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
def main():
77
form = cgi.FieldStorage()
8-
print "Content-type: text/html"
9-
print
8+
print("Content-type: text/html")
9+
print()
1010
cmd = form.getvalue("cmd", "view")
1111
page = form.getvalue("page", "FrontPage")
1212
wiki = WikiPage(page)
@@ -20,22 +20,22 @@ class WikiPage:
2020

2121
def __init__(self, name):
2222
if not self.iswikiword(name):
23-
raise ValueError, "page name is not a wiki word"
23+
raise ValueError("page name is not a wiki word")
2424
self.name = name
2525
self.load()
2626

2727
def cmd_view(self, form):
28-
print "<h1>", escape(self.splitwikiword(self.name)), "</h1>"
29-
print "<p>"
28+
print("<h1>", escape(self.splitwikiword(self.name)), "</h1>")
29+
print("<p>")
3030
for line in self.data.splitlines():
3131
line = line.rstrip()
3232
if not line:
33-
print "<p>"
33+
print("<p>")
3434
else:
35-
print self.formatline(line)
36-
print "<hr>"
37-
print "<p>", self.mklink("edit", self.name, "Edit this page") + ";"
38-
print self.mklink("view", "FrontPage", "go to front page") + "."
35+
print(self.formatline(line))
36+
print("<hr>")
37+
print("<p>", self.mklink("edit", self.name, "Edit this page") + ";")
38+
print(self.mklink("view", "FrontPage", "go to front page") + ".")
3939

4040
def formatline(self, line):
4141
words = []
@@ -51,32 +51,32 @@ def formatline(self, line):
5151
return "".join(words)
5252

5353
def cmd_edit(self, form, label="Change"):
54-
print "<h1>", label, self.name, "</h1>"
55-
print '<form method="POST" action="%s">' % self.scripturl
54+
print("<h1>", label, self.name, "</h1>")
55+
print('<form method="POST" action="%s">' % self.scripturl)
5656
s = '<textarea cols="70" rows="20" name="text">%s</textarea>'
57-
print s % self.data
58-
print '<input type="hidden" name="cmd" value="create">'
59-
print '<input type="hidden" name="page" value="%s">' % self.name
60-
print '<br>'
61-
print '<input type="submit" value="%s Page">' % label
62-
print "</form>"
57+
print(s % self.data)
58+
print('<input type="hidden" name="cmd" value="create">')
59+
print('<input type="hidden" name="page" value="%s">' % self.name)
60+
print('<br>')
61+
print('<input type="submit" value="%s Page">' % label)
62+
print("</form>")
6363

6464
def cmd_create(self, form):
6565
self.data = form.getvalue("text", "").strip()
6666
error = self.store()
6767
if error:
68-
print "<h1>I'm sorry. That didn't work</h1>"
69-
print "<p>An error occurred while attempting to write the file:"
70-
print "<p>", escape(error)
68+
print("<h1>I'm sorry. That didn't work</h1>")
69+
print("<p>An error occurred while attempting to write the file:")
70+
print("<p>", escape(error))
7171
else:
7272
# Use a redirect directive, to avoid "reload page" problems
73-
print "<head>"
73+
print("<head>")
7474
s = '<meta http-equiv="refresh" content="1; URL=%s">'
75-
print s % (self.scripturl + "?cmd=view&page=" + self.name)
76-
print "<head>"
77-
print "<h1>OK</h1>"
78-
print "<p>If nothing happens, please click here:",
79-
print self.mklink("view", self.name, self.name)
75+
print(s % (self.scripturl + "?cmd=view&page=" + self.name))
76+
print("<head>")
77+
print("<h1>OK</h1>")
78+
print("<p>If nothing happens, please click here:", end=' ')
79+
print(self.mklink("view", self.name, self.name))
8080

8181
def cmd_new(self, form):
8282
self.cmd_edit(form, label="Create")

Demo/classes/Complex.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def __init__(self, re=0, im=0):
114114
self.__dict__['im'] = _im
115115

116116
def __setattr__(self, name, value):
117-
raise TypeError, 'Complex numbers are immutable'
117+
raise TypeError('Complex numbers are immutable')
118118

119119
def __hash__(self):
120120
if not self.im:
@@ -144,17 +144,17 @@ def __abs__(self):
144144

145145
def __int__(self):
146146
if self.im:
147-
raise ValueError, "can't convert Complex with nonzero im to int"
147+
raise ValueError("can't convert Complex with nonzero im to int")
148148
return int(self.re)
149149

150150
def __long__(self):
151151
if self.im:
152-
raise ValueError, "can't convert Complex with nonzero im to long"
153-
return long(self.re)
152+
raise ValueError("can't convert Complex with nonzero im to long")
153+
return int(self.re)
154154

155155
def __float__(self):
156156
if self.im:
157-
raise ValueError, "can't convert Complex with nonzero im to float"
157+
raise ValueError("can't convert Complex with nonzero im to float")
158158
return float(self.re)
159159

160160
def __cmp__(self, other):
@@ -199,7 +199,7 @@ def __mul__(self, other):
199199
def __div__(self, other):
200200
other = ToComplex(other)
201201
d = float(other.re*other.re + other.im*other.im)
202-
if not d: raise ZeroDivisionError, 'Complex division'
202+
if not d: raise ZeroDivisionError('Complex division')
203203
return Complex((self.re*other.re + self.im*other.im) / d,
204204
(self.im*other.re - self.re*other.im) / d)
205205

@@ -209,10 +209,10 @@ def __rdiv__(self, other):
209209

210210
def __pow__(self, n, z=None):
211211
if z is not None:
212-
raise TypeError, 'Complex does not support ternary pow()'
212+
raise TypeError('Complex does not support ternary pow()')
213213
if IsComplex(n):
214214
if n.im:
215-
if self.im: raise TypeError, 'Complex to the Complex power'
215+
if self.im: raise TypeError('Complex to the Complex power')
216216
else: return exp(math.log(self.re)*n)
217217
n = n.re
218218
r = pow(self.abs(), n)
@@ -229,21 +229,21 @@ def exp(z):
229229

230230

231231
def checkop(expr, a, b, value, fuzz = 1e-6):
232-
print ' ', a, 'and', b,
232+
print(' ', a, 'and', b, end=' ')
233233
try:
234234
result = eval(expr)
235235
except:
236236
result = sys.exc_info()[0]
237-
print '->', result
237+
print('->', result)
238238
if isinstance(result, str) or isinstance(value, str):
239239
ok = (result == value)
240240
else:
241241
ok = abs(result - value) <= fuzz
242242
if not ok:
243-
print '!!\t!!\t!! should be', value, 'diff', abs(result - value)
243+
print('!!\t!!\t!! should be', value, 'diff', abs(result - value))
244244

245245
def test():
246-
print 'test constructors'
246+
print('test constructors')
247247
constructor_test = (
248248
# "expect" is an array [re,im] "got" the Complex.
249249
( (0,0), Complex() ),
@@ -260,9 +260,9 @@ def test():
260260
for t in constructor_test:
261261
cnt[0] += 1
262262
if ((t[0][0]!=t[1].re)or(t[0][1]!=t[1].im)):
263-
print " expected", t[0], "got", t[1]
263+
print(" expected", t[0], "got", t[1])
264264
cnt[1] += 1
265-
print " ", cnt[1], "of", cnt[0], "tests failed"
265+
print(" ", cnt[1], "of", cnt[0], "tests failed")
266266
# test operators
267267
testsuite = {
268268
'a+b': [
@@ -310,7 +310,7 @@ def test():
310310
],
311311
}
312312
for expr in sorted(testsuite):
313-
print expr + ':'
313+
print(expr + ':')
314314
t = (expr,)
315315
for item in testsuite[expr]:
316316
checkop(*(t+item))

Demo/classes/Dates.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
dbm = dbm + dim
5858
del dbm, dim
5959

60-
_INT_TYPES = type(1), type(1L)
60+
_INT_TYPES = type(1), type(1)
6161

6262
def _is_leap(year): # 1 if leap year, else 0
6363
if year % 4 != 0: return 0
@@ -68,7 +68,7 @@ def _days_in_year(year): # number of days in year
6868
return 365 + _is_leap(year)
6969

7070
def _days_before_year(year): # number of days before year
71-
return year*365L + (year+3)/4 - (year+99)/100 + (year+399)/400
71+
return year*365 + (year+3)/4 - (year+99)/100 + (year+399)/400
7272

7373
def _days_in_month(month, year): # number of days in month of year
7474
if month == 2 and _is_leap(year): return 29
@@ -86,7 +86,7 @@ def _date2num(date): # compute ordinal of date.month,day,year
8686

8787
def _num2date(n): # return date with ordinal n
8888
if type(n) not in _INT_TYPES:
89-
raise TypeError, 'argument must be integer: %r' % type(n)
89+
raise TypeError('argument must be integer: %r' % type(n))
9090

9191
ans = Date(1,1,1) # arguments irrelevant; just getting a Date obj
9292
del ans.ord, ans.month, ans.day, ans.year # un-initialize it
@@ -120,17 +120,17 @@ def _num2day(n): # return weekday name of day with ordinal n
120120
class Date:
121121
def __init__(self, month, day, year):
122122
if not 1 <= month <= 12:
123-
raise ValueError, 'month must be in 1..12: %r' % (month,)
123+
raise ValueError('month must be in 1..12: %r' % (month,))
124124
dim = _days_in_month(month, year)
125125
if not 1 <= day <= dim:
126-
raise ValueError, 'day must be in 1..%r: %r' % (dim, day)
126+
raise ValueError('day must be in 1..%r: %r' % (dim, day))
127127
self.month, self.day, self.year = month, day, year
128128
self.ord = _date2num(self)
129129

130130
# don't allow setting existing attributes
131131
def __setattr__(self, name, value):
132-
if self.__dict__.has_key(name):
133-
raise AttributeError, 'read-only attribute ' + name
132+
if name in self.__dict__:
133+
raise AttributeError('read-only attribute ' + name)
134134
self.__dict__[name] = value
135135

136136
def __cmp__(self, other):
@@ -151,7 +151,7 @@ def __repr__(self):
151151
# Python 1.1 coerces neither int+date nor date+int
152152
def __add__(self, n):
153153
if type(n) not in _INT_TYPES:
154-
raise TypeError, 'can\'t add %r to date' % type(n)
154+
raise TypeError('can\'t add %r to date' % type(n))
155155
return _num2date(self.ord + n)
156156
__radd__ = __add__ # handle int+date
157157

@@ -164,7 +164,7 @@ def __sub__(self, other):
164164

165165
# complain about int-date
166166
def __rsub__(self, other):
167-
raise TypeError, 'Can\'t subtract date from integer'
167+
raise TypeError('Can\'t subtract date from integer')
168168

169169
def weekday(self):
170170
return _num2day(self.ord)
@@ -179,30 +179,30 @@ def test(firstyear, lastyear):
179179
a = Date(9,30,1913)
180180
b = Date(9,30,1914)
181181
if repr(a) != 'Tue 30 Sep 1913':
182-
raise DateTestError, '__repr__ failure'
182+
raise DateTestError('__repr__ failure')
183183
if (not a < b) or a == b or a > b or b != b:
184-
raise DateTestError, '__cmp__ failure'
184+
raise DateTestError('__cmp__ failure')
185185
if a+365 != b or 365+a != b:
186-
raise DateTestError, '__add__ failure'
186+
raise DateTestError('__add__ failure')
187187
if b-a != 365 or b-365 != a:
188-
raise DateTestError, '__sub__ failure'
188+
raise DateTestError('__sub__ failure')
189189
try:
190190
x = 1 - a
191-
raise DateTestError, 'int-date should have failed'
191+
raise DateTestError('int-date should have failed')
192192
except TypeError:
193193
pass
194194
try:
195195
x = a + b
196-
raise DateTestError, 'date+date should have failed'
196+
raise DateTestError('date+date should have failed')
197197
except TypeError:
198198
pass
199199
if a.weekday() != 'Tuesday':
200-
raise DateTestError, 'weekday() failure'
200+
raise DateTestError('weekday() failure')
201201
if max(a,b) is not b or min(a,b) is not a:
202-
raise DateTestError, 'min/max failure'
202+
raise DateTestError('min/max failure')
203203
d = {a-1:b, b:a+1}
204204
if d[b-366] != b or d[a+(b-a)] != Date(10,1,1913):
205-
raise DateTestError, 'dictionary failure'
205+
raise DateTestError('dictionary failure')
206206

207207
# verify date<->number conversions for first and last days for
208208
# all years in firstyear .. lastyear
@@ -214,9 +214,9 @@ def test(firstyear, lastyear):
214214
lord = ford + _days_in_year(y) - 1
215215
fd, ld = Date(1,1,y), Date(12,31,y)
216216
if (fd.ord,ld.ord) != (ford,lord):
217-
raise DateTestError, ('date->num failed', y)
217+
raise DateTestError('date->num failed', y)
218218
fd, ld = _num2date(ford), _num2date(lord)
219219
if (1,1,y,12,31,y) != \
220220
(fd.month,fd.day,fd.year,ld.month,ld.day,ld.year):
221-
raise DateTestError, ('num->date failed', y)
221+
raise DateTestError('num->date failed', y)
222222
y = y + 1

0 commit comments

Comments
 (0)