@@ -122,13 +122,6 @@ def monthcalendar(year, month):
122122 rows .append (row )
123123 return rows
124124
125- def _center (str , width ):
126- """Center a string in a field."""
127- n = width - len (str )
128- if n <= 0 :
129- return str
130- return ' ' * ((n + 1 )/ 2 ) + str + ' ' * ((n )/ 2 )
131-
132125def prweek (theweek , width ):
133126 """Print a single week (no newline)."""
134127 print week (theweek , width ),
@@ -141,7 +134,7 @@ def week(theweek, width):
141134 s = ''
142135 else :
143136 s = '%2i' % day # right-align single-digit days
144- days .append (_center ( s , width ))
137+ days .append (s . center ( width ))
145138 return ' ' .join (days )
146139
147140def weekheader (width ):
@@ -152,7 +145,7 @@ def weekheader(width):
152145 names = day_abbr
153146 days = []
154147 for i in range (_firstweekday , _firstweekday + 7 ):
155- days .append (_center ( names [i % 7 ][:width ], width ))
148+ days .append (names [i % 7 ][:width ]. center ( width ))
156149 return ' ' .join (days )
157150
158151def prmonth (theyear , themonth , w = 0 , l = 0 ):
@@ -163,7 +156,7 @@ def month(theyear, themonth, w=0, l=0):
163156 """Return a month's calendar string (multi-line)."""
164157 w = max (2 , w )
165158 l = max (1 , l )
166- s = (_center (month_name [themonth ] + ' ' + `theyear` ,
159+ s = ((month_name [themonth ] + ' ' + `theyear` ). center (
167160 7 * (w + 1 ) - 1 ).rstrip () +
168161 '\n ' * l + weekheader (w ).rstrip () + '\n ' * l )
169162 for aweek in monthcalendar (theyear , themonth ):
@@ -180,8 +173,8 @@ def format3c(a, b, c, colwidth=_colwidth, spacing=_spacing):
180173
181174def format3cstring (a , b , c , colwidth = _colwidth , spacing = _spacing ):
182175 """Returns a string formatted from 3 strings, centered within 3 columns."""
183- return (_center ( a , colwidth ) + ' ' * spacing + _center ( b , colwidth ) +
184- ' ' * spacing + _center ( c , colwidth ))
176+ return (a . center ( colwidth ) + ' ' * spacing + b . center ( colwidth ) +
177+ ' ' * spacing + c . center ( colwidth ))
185178
186179def prcal (year , w = 0 , l = 0 , c = _spacing ):
187180 """Print a year's calendar."""
@@ -193,7 +186,7 @@ def calendar(year, w=0, l=0, c=_spacing):
193186 l = max (1 , l )
194187 c = max (2 , c )
195188 colwidth = (w + 1 ) * 7 - 1
196- s = _center ( `year` , colwidth * 3 + c * 2 ).rstrip () + '\n ' * l
189+ s = `year` . center ( colwidth * 3 + c * 2 ).rstrip () + '\n ' * l
197190 header = weekheader (w )
198191 header = format3cstring (header , header , header , colwidth , c ).rstrip ()
199192 for q in range (January , January + 12 , 3 ):
0 commit comments