Skip to content

Commit

Permalink
Run 2to3 over the Demo/ directory to shut up parse errors from 2to3 a…
Browse files Browse the repository at this point in the history
…bout lingering print statements.
  • Loading branch information
collinw committed Jul 17, 2007
1 parent a8c360e commit 6f2df4d
Show file tree
Hide file tree
Showing 132 changed files with 1,071 additions and 1,081 deletions.
8 changes: 4 additions & 4 deletions Demo/cgi/cgi1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# If cgi0.sh works but cgi1.py doesn't, check the #! line and the file
# permissions. The docs for the cgi.py module have debugging tips.

print "Content-type: text/html"
print
print "<h1>Hello world</h1>"
print "<p>This is cgi1.py"
print("Content-type: text/html")
print()
print("<h1>Hello world</h1>")
print("<p>This is cgi1.py")
12 changes: 6 additions & 6 deletions Demo/cgi/cgi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

def main():
form = cgi.FieldStorage()
print "Content-type: text/html"
print
print("Content-type: text/html")
print()
if not form:
print "<h1>No Form Keys</h1>"
print("<h1>No Form Keys</h1>")
else:
print "<h1>Form Keys</h1>"
for key in form.keys():
print("<h1>Form Keys</h1>")
for key in list(form.keys()):
value = form[key].value
print "<p>", cgi.escape(key), ":", cgi.escape(value)
print("<p>", cgi.escape(key), ":", cgi.escape(value))

if __name__ == "__main__":
main()
54 changes: 27 additions & 27 deletions Demo/cgi/wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

def main():
form = cgi.FieldStorage()
print "Content-type: text/html"
print
print("Content-type: text/html")
print()
cmd = form.getvalue("cmd", "view")
page = form.getvalue("page", "FrontPage")
wiki = WikiPage(page)
Expand All @@ -20,22 +20,22 @@ class WikiPage:

def __init__(self, name):
if not self.iswikiword(name):
raise ValueError, "page name is not a wiki word"
raise ValueError("page name is not a wiki word")
self.name = name
self.load()

def cmd_view(self, form):
print "<h1>", escape(self.splitwikiword(self.name)), "</h1>"
print "<p>"
print("<h1>", escape(self.splitwikiword(self.name)), "</h1>")
print("<p>")
for line in self.data.splitlines():
line = line.rstrip()
if not line:
print "<p>"
print("<p>")
else:
print self.formatline(line)
print "<hr>"
print "<p>", self.mklink("edit", self.name, "Edit this page") + ";"
print self.mklink("view", "FrontPage", "go to front page") + "."
print(self.formatline(line))
print("<hr>")
print("<p>", self.mklink("edit", self.name, "Edit this page") + ";")
print(self.mklink("view", "FrontPage", "go to front page") + ".")

def formatline(self, line):
words = []
Expand All @@ -51,32 +51,32 @@ def formatline(self, line):
return "".join(words)

def cmd_edit(self, form, label="Change"):
print "<h1>", label, self.name, "</h1>"
print '<form method="POST" action="%s">' % self.scripturl
print("<h1>", label, self.name, "</h1>")
print('<form method="POST" action="%s">' % self.scripturl)
s = '<textarea cols="70" rows="20" name="text">%s</textarea>'
print s % self.data
print '<input type="hidden" name="cmd" value="create">'
print '<input type="hidden" name="page" value="%s">' % self.name
print '<br>'
print '<input type="submit" value="%s Page">' % label
print "</form>"
print(s % self.data)
print('<input type="hidden" name="cmd" value="create">')
print('<input type="hidden" name="page" value="%s">' % self.name)
print('<br>')
print('<input type="submit" value="%s Page">' % label)
print("</form>")

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

def cmd_new(self, form):
self.cmd_edit(form, label="Create")
Expand Down
30 changes: 15 additions & 15 deletions Demo/classes/Complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(self, re=0, im=0):
self.__dict__['im'] = _im

def __setattr__(self, name, value):
raise TypeError, 'Complex numbers are immutable'
raise TypeError('Complex numbers are immutable')

def __hash__(self):
if not self.im:
Expand Down Expand Up @@ -144,17 +144,17 @@ def __abs__(self):

def __int__(self):
if self.im:
raise ValueError, "can't convert Complex with nonzero im to int"
raise ValueError("can't convert Complex with nonzero im to int")
return int(self.re)

def __long__(self):
if self.im:
raise ValueError, "can't convert Complex with nonzero im to long"
return long(self.re)
raise ValueError("can't convert Complex with nonzero im to long")
return int(self.re)

def __float__(self):
if self.im:
raise ValueError, "can't convert Complex with nonzero im to float"
raise ValueError("can't convert Complex with nonzero im to float")
return float(self.re)

def __cmp__(self, other):
Expand Down Expand Up @@ -199,7 +199,7 @@ def __mul__(self, other):
def __div__(self, other):
other = ToComplex(other)
d = float(other.re*other.re + other.im*other.im)
if not d: raise ZeroDivisionError, 'Complex division'
if not d: raise ZeroDivisionError('Complex division')
return Complex((self.re*other.re + self.im*other.im) / d,
(self.im*other.re - self.re*other.im) / d)

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

def __pow__(self, n, z=None):
if z is not None:
raise TypeError, 'Complex does not support ternary pow()'
raise TypeError('Complex does not support ternary pow()')
if IsComplex(n):
if n.im:
if self.im: raise TypeError, 'Complex to the Complex power'
if self.im: raise TypeError('Complex to the Complex power')
else: return exp(math.log(self.re)*n)
n = n.re
r = pow(self.abs(), n)
Expand All @@ -229,21 +229,21 @@ def exp(z):


def checkop(expr, a, b, value, fuzz = 1e-6):
print ' ', a, 'and', b,
print(' ', a, 'and', b, end=' ')
try:
result = eval(expr)
except:
result = sys.exc_info()[0]
print '->', result
print('->', result)
if isinstance(result, str) or isinstance(value, str):
ok = (result == value)
else:
ok = abs(result - value) <= fuzz
if not ok:
print '!!\t!!\t!! should be', value, 'diff', abs(result - value)
print('!!\t!!\t!! should be', value, 'diff', abs(result - value))

def test():
print 'test constructors'
print('test constructors')
constructor_test = (
# "expect" is an array [re,im] "got" the Complex.
( (0,0), Complex() ),
Expand All @@ -260,9 +260,9 @@ def test():
for t in constructor_test:
cnt[0] += 1
if ((t[0][0]!=t[1].re)or(t[0][1]!=t[1].im)):
print " expected", t[0], "got", t[1]
print(" expected", t[0], "got", t[1])
cnt[1] += 1
print " ", cnt[1], "of", cnt[0], "tests failed"
print(" ", cnt[1], "of", cnt[0], "tests failed")
# test operators
testsuite = {
'a+b': [
Expand Down Expand Up @@ -310,7 +310,7 @@ def test():
],
}
for expr in sorted(testsuite):
print expr + ':'
print(expr + ':')
t = (expr,)
for item in testsuite[expr]:
checkop(*(t+item))
Expand Down
40 changes: 20 additions & 20 deletions Demo/classes/Dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
dbm = dbm + dim
del dbm, dim

_INT_TYPES = type(1), type(1L)
_INT_TYPES = type(1), type(1)

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

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

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

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

ans = Date(1,1,1) # arguments irrelevant; just getting a Date obj
del ans.ord, ans.month, ans.day, ans.year # un-initialize it
Expand Down Expand Up @@ -120,17 +120,17 @@ def _num2day(n): # return weekday name of day with ordinal n
class Date:
def __init__(self, month, day, year):
if not 1 <= month <= 12:
raise ValueError, 'month must be in 1..12: %r' % (month,)
raise ValueError('month must be in 1..12: %r' % (month,))
dim = _days_in_month(month, year)
if not 1 <= day <= dim:
raise ValueError, 'day must be in 1..%r: %r' % (dim, day)
raise ValueError('day must be in 1..%r: %r' % (dim, day))
self.month, self.day, self.year = month, day, year
self.ord = _date2num(self)

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

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

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

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

def weekday(self):
return _num2day(self.ord)
Expand All @@ -179,30 +179,30 @@ def test(firstyear, lastyear):
a = Date(9,30,1913)
b = Date(9,30,1914)
if repr(a) != 'Tue 30 Sep 1913':
raise DateTestError, '__repr__ failure'
raise DateTestError('__repr__ failure')
if (not a < b) or a == b or a > b or b != b:
raise DateTestError, '__cmp__ failure'
raise DateTestError('__cmp__ failure')
if a+365 != b or 365+a != b:
raise DateTestError, '__add__ failure'
raise DateTestError('__add__ failure')
if b-a != 365 or b-365 != a:
raise DateTestError, '__sub__ failure'
raise DateTestError('__sub__ failure')
try:
x = 1 - a
raise DateTestError, 'int-date should have failed'
raise DateTestError('int-date should have failed')
except TypeError:
pass
try:
x = a + b
raise DateTestError, 'date+date should have failed'
raise DateTestError('date+date should have failed')
except TypeError:
pass
if a.weekday() != 'Tuesday':
raise DateTestError, 'weekday() failure'
raise DateTestError('weekday() failure')
if max(a,b) is not b or min(a,b) is not a:
raise DateTestError, 'min/max failure'
raise DateTestError('min/max failure')
d = {a-1:b, b:a+1}
if d[b-366] != b or d[a+(b-a)] != Date(10,1,1913):
raise DateTestError, 'dictionary failure'
raise DateTestError('dictionary failure')

# verify date<->number conversions for first and last days for
# all years in firstyear .. lastyear
Expand All @@ -214,9 +214,9 @@ def test(firstyear, lastyear):
lord = ford + _days_in_year(y) - 1
fd, ld = Date(1,1,y), Date(12,31,y)
if (fd.ord,ld.ord) != (ford,lord):
raise DateTestError, ('date->num failed', y)
raise DateTestError('date->num failed', y)
fd, ld = _num2date(ford), _num2date(lord)
if (1,1,y,12,31,y) != \
(fd.month,fd.day,fd.year,ld.month,ld.day,ld.year):
raise DateTestError, ('num->date failed', y)
raise DateTestError('num->date failed', y)
y = y + 1
Loading

0 comments on commit 6f2df4d

Please sign in to comment.