Commit 06de3078 authored by Martin Blais's avatar Martin Blais

Normalized a few cases of whitespace in function declarations.

Found them using::

  find . -name '*.py' | while read i ; do grep 'def[^(]*( ' $i /dev/null ; done
  find . -name '*.py' | while read i ; do grep ' ):' $i /dev/null ; done

(I was doing this all over my own code anyway, because I'd been using spaces in
all defs, so I thought I'd make a run on the Python code as well.  If you need
to do such fixes in your own code, you can use xx-rename or parenregu.el within
emacs.)
parent ec35227e
......@@ -59,32 +59,32 @@ del dbm, dim
_INT_TYPES = type(1), type(1L)
def _is_leap( year ): # 1 if leap year, else 0
def _is_leap(year): # 1 if leap year, else 0
if year % 4 != 0: return 0
if year % 400 == 0: return 1
return year % 100 != 0
def _days_in_year( year ): # number of days in year
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
def _days_before_year(year): # number of days before year
return year*365L + (year+3)/4 - (year+99)/100 + (year+399)/400
def _days_in_month( month, year ): # number of days in month of year
def _days_in_month(month, year): # number of days in month of year
if month == 2 and _is_leap(year): return 29
return _DAYS_IN_MONTH[month-1]
def _days_before_month( month, year ): # number of days in year before month
def _days_before_month(month, year): # number of days in year before month
return _DAYS_BEFORE_MONTH[month-1] + (month > 2 and _is_leap(year))
def _date2num( date ): # compute ordinal of date.month,day,year
return _days_before_year( date.year ) + \
_days_before_month( date.month, date.year ) + \
def _date2num(date): # compute ordinal of date.month,day,year
return _days_before_year(date.year) + \
_days_before_month(date.month, date.year) + \
date.day
_DI400Y = _days_before_year( 400 ) # number of days in 400 years
_DI400Y = _days_before_year(400) # number of days in 400 years
def _num2date( n ): # return date with ordinal n
def _num2date(n): # return date with ordinal n
if type(n) not in _INT_TYPES:
raise TypeError, 'argument must be integer: %r' % type(n)
......@@ -95,53 +95,53 @@ def _num2date( n ): # return date with ordinal n
n400 = (n-1)/_DI400Y # # of 400-year blocks preceding
year, n = 400 * n400, n - _DI400Y * n400
more = n / 365
dby = _days_before_year( more )
dby = _days_before_year(more)
if dby >= n:
more = more - 1
dby = dby - _days_in_year( more )
dby = dby - _days_in_year(more)
year, n = year + more, int(n - dby)
try: year = int(year) # chop to int, if it fits
except (ValueError, OverflowError): pass
month = min( n/29 + 1, 12 )
dbm = _days_before_month( month, year )
month = min(n/29 + 1, 12)
dbm = _days_before_month(month, year)
if dbm >= n:
month = month - 1
dbm = dbm - _days_in_month( month, year )
dbm = dbm - _days_in_month(month, year)
ans.month, ans.day, ans.year = month, n-dbm, year
return ans
def _num2day( n ): # return weekday name of day with ordinal n
def _num2day(n): # return weekday name of day with ordinal n
return _DAY_NAMES[ int(n % 7) ]
class Date:
def __init__( self, month, day, year ):
def __init__(self, month, day, year):
if not 1 <= month <= 12:
raise ValueError, 'month must be in 1..12: %r' % (month,)
dim = _days_in_month( month, year )
dim = _days_in_month(month, year)
if not 1 <= day <= dim:
raise ValueError, 'day must be in 1..%r: %r' % (dim, day)
self.month, self.day, self.year = month, day, year
self.ord = _date2num( self )
self.ord = _date2num(self)
# don't allow setting existing attributes
def __setattr__( self, name, value ):
def __setattr__(self, name, value):
if self.__dict__.has_key(name):
raise AttributeError, 'read-only attribute ' + name
self.__dict__[name] = value
def __cmp__( self, other ):
return cmp( self.ord, other.ord )
def __cmp__(self, other):
return cmp(self.ord, other.ord)
# define a hash function so dates can be used as dictionary keys
def __hash__( self ):
return hash( self.ord )
def __hash__(self):
return hash(self.ord)
# print as, e.g., Mon 16 Aug 1993
def __repr__( self ):
def __repr__(self):
return '%.3s %2d %.3s %r' % (
self.weekday(),
self.day,
......@@ -149,33 +149,33 @@ class Date:
self.year)
# Python 1.1 coerces neither int+date nor date+int
def __add__( self, n ):
def __add__(self, n):
if type(n) not in _INT_TYPES:
raise TypeError, 'can\'t add %r to date' % type(n)
return _num2date( self.ord + n )
return _num2date(self.ord + n)
__radd__ = __add__ # handle int+date
# Python 1.1 coerces neither date-int nor date-date
def __sub__( self, other ):
def __sub__(self, other):
if type(other) in _INT_TYPES: # date-int
return _num2date( self.ord - other )
return _num2date(self.ord - other)
else:
return self.ord - other.ord # date-date
# complain about int-date
def __rsub__( self, other ):
def __rsub__(self, other):
raise TypeError, 'Can\'t subtract date from integer'
def weekday( self ):
return _num2day( self.ord )
def weekday(self):
return _num2day(self.ord)
def today():
import time
local = time.localtime(time.time())
return Date( local[1], local[2], local[0] )
return Date(local[1], local[2], local[0])
DateTestError = 'DateTestError'
def test( firstyear, lastyear ):
def test(firstyear, lastyear):
a = Date(9,30,1913)
b = Date(9,30,1914)
if repr(a) != 'Tue 30 Sep 1913':
......@@ -207,7 +207,7 @@ def test( firstyear, lastyear ):
# verify date<->number conversions for first and last days for
# all years in firstyear .. lastyear
lord = _days_before_year( firstyear )
lord = _days_before_year(firstyear)
y = firstyear
while y <= lastyear:
ford = lord + 1
......
......@@ -4,14 +4,14 @@ from Coroutine import *
# fringe visits a nested list in inorder, and detaches for each non-list
# element; raises EarlyExit after the list is exhausted
def fringe( co, list ):
def fringe(co, list):
for x in list:
if type(x) is type([]):
fringe(co, x)
else:
co.back(x)
def printinorder( list ):
def printinorder(list):
co = Coroutine()
f = co.create(fringe, co, list)
try:
......@@ -27,7 +27,7 @@ x = [0, 1, [2, [3]], [4,5], [[[6]]] ]
printinorder(x) # 0 1 2 3 4 5 6
# fcmp lexicographically compares the fringes of two nested lists
def fcmp( l1, l2 ):
def fcmp(l1, l2):
co1 = Coroutine(); f1 = co1.create(fringe, co1, l1)
co2 = Coroutine(); f2 = co2.create(fringe, co2, l2)
while 1:
......
......@@ -133,7 +133,7 @@ class PointersTestCase(unittest.TestCase):
self.failUnlessEqual(p[0], 42)
self.failUnlessEqual(p.contents.value, 42)
def test_charpp( self ):
def test_charpp(self):
"""Test that a character pointer-to-pointer is correctly passed"""
dll = CDLL(_ctypes_test.__file__)
func = dll._testfunc_c_p_p
......
......@@ -468,7 +468,7 @@ class DisplayStyle:
"""DisplayStyle - handle configuration options shared by
(multiple) Display Items"""
def __init__(self, itemtype, cnf={}, **kw ):
def __init__(self, itemtype, cnf={}, **kw):
master = _default_root # global from Tkinter
if not master and cnf.has_key('refwindow'): master=cnf['refwindow']
elif not master and kw.has_key('refwindow'): master= kw['refwindow']
......@@ -480,7 +480,7 @@ class DisplayStyle:
def __str__(self):
return self.stylename
def _options(self, cnf, kw ):
def _options(self, cnf, kw):
if kw and cnf:
cnf = _cnfmerge((cnf, kw))
elif kw:
......
......@@ -140,7 +140,7 @@ class ParserBase:
# Internal -- parse a marked section
# Override this to handle MS-word extension syntax <![if word]>content<![endif]>
def parse_marked_section( self, i, report=1 ):
def parse_marked_section(self, i, report=1):
rawdata= self.rawdata
assert rawdata[i:i+3] == '<![', "unexpected call to parse_marked_section()"
sectName, j = self._scan_name( i+3, i )
......
......@@ -262,7 +262,7 @@ class ProgressBar:
self.w.ShowWindow()
self.d.DrawDialog()
def __del__( self ):
def __del__(self):
if self.w:
self.w.BringToFront()
self.w.HideWindow()
......@@ -274,7 +274,7 @@ class ProgressBar:
self.w.BringToFront()
self.w.SetWTitle(newstr)
def label( self, *newstr ):
def label(self, *newstr):
"""label(text) - Set text in progress box"""
self.w.BringToFront()
if newstr:
......
......@@ -150,7 +150,7 @@ class SSLFakeFile:
It only supports what is needed in smtplib.
"""
def __init__( self, sslobj):
def __init__(self, sslobj):
self.sslobj = sslobj
def readline(self):
......
......@@ -362,7 +362,7 @@ class BuiltinTest(unittest.TestCase):
_cells = {}
def __setitem__(self, key, formula):
self._cells[key] = formula
def __getitem__(self, key ):
def __getitem__(self, key):
return eval(self._cells[key], globals(), self)
ss = SpreadSheet()
......
......@@ -390,7 +390,7 @@ test_classes.append(test_gettempdir)
class test_mkstemp(TC):
"""Test mkstemp()."""
def do_create(self, dir=None, pre="", suf="", ):
def do_create(self, dir=None, pre="", suf=""):
if dir is None:
dir = tempfile.gettempdir()
try:
......
......@@ -784,7 +784,7 @@ class MyHTMLParser(sgmllib.SGMLParser):
self.url = url
sgmllib.SGMLParser.__init__(self)
def check_name_id( self, attributes ):
def check_name_id(self, attributes):
""" Check the name or id attributes on an element.
"""
# We must rescue the NAME or id (name is deprecated in XHTML)
......@@ -799,7 +799,7 @@ class MyHTMLParser(sgmllib.SGMLParser):
else: self.names.append(value)
break
def unknown_starttag( self, tag, attributes ):
def unknown_starttag(self, tag, attributes):
""" In XHTML, you can have id attributes on any element.
"""
self.check_name_id(attributes)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment