Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Properties
calendar.LocaleTextCalendar Class Reference
Inheritance diagram for calendar.LocaleTextCalendar:
Inheritance graph
[legend]
Collaboration diagram for calendar.LocaleTextCalendar:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def formatweekday
def formatmonthname
def prweek
def formatday
def formatweek
def formatweekheader
def prmonth
def formatmonth
def formatyear
def pryear
def getfirstweekday
def setfirstweekday
def iterweekdays
def itermonthdates
def itermonthdays2
def itermonthdays
def monthdatescalendar
def monthdays2calendar
def monthdayscalendar
def yeardatescalendar
def yeardays2calendar
def yeardayscalendar

Public Attributes

 locale
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Properties

 firstweekday = property(getfirstweekday, setfirstweekday)

Detailed Description

This class can be passed a locale name in the constructor and will return
month and weekday names in the specified locale. If this locale includes
an encoding all strings containing month and weekday names will be returned
as unicode.

Definition at line 496 of file calendar.py.


Constructor & Destructor Documentation

def calendar.LocaleTextCalendar.__init__ (   self,
  firstweekday = 0,
  locale = None 
)

Definition at line 504 of file calendar.py.

00504 
00505     def __init__(self, firstweekday=0, locale=None):
00506         TextCalendar.__init__(self, firstweekday)
00507         if locale is None:
00508             locale = _locale.getdefaultlocale()
00509         self.locale = locale

Here is the caller graph for this function:


Member Function Documentation

def calendar.TextCalendar.formatday (   self,
  day,
  weekday,
  width 
) [inherited]
Returns a formatted day.

Definition at line 267 of file calendar.py.

00267 
00268     def formatday(self, day, weekday, width):
00269         """
00270         Returns a formatted day.
00271         """
00272         if day == 0:
00273             s = ''
00274         else:
00275             s = '%2i' % day             # right-align single-digit days
00276         return s.center(width)

Here is the caller graph for this function:

def calendar.TextCalendar.formatmonth (   self,
  theyear,
  themonth,
  w = 0,
  l = 0 
) [inherited]
Return a month's calendar string (multi-line).

Definition at line 314 of file calendar.py.

00314 
00315     def formatmonth(self, theyear, themonth, w=0, l=0):
00316         """
00317         Return a month's calendar string (multi-line).
00318         """
00319         w = max(2, w)
00320         l = max(1, l)
00321         s = self.formatmonthname(theyear, themonth, 7 * (w + 1) - 1)
00322         s = s.rstrip()
00323         s += '\n' * l
00324         s += self.formatweekheader(w).rstrip()
00325         s += '\n' * l
00326         for week in self.monthdays2calendar(theyear, themonth):
00327             s += self.formatweek(week, w).rstrip()
00328             s += '\n' * l
00329         return s

Here is the call graph for this function:

Here is the caller graph for this function:

def calendar.LocaleTextCalendar.formatmonthname (   self,
  theyear,
  themonth,
  width,
  withyear = True 
)
Return a formatted month name.

Reimplemented from calendar.TextCalendar.

Definition at line 519 of file calendar.py.

00519 
00520     def formatmonthname(self, theyear, themonth, width, withyear=True):
00521         with different_locale(self.locale):
00522             s = month_name[themonth]
00523             if withyear:
00524                 s = "%s %r" % (s, theyear)
00525             return s.center(width)
00526 

def calendar.TextCalendar.formatweek (   self,
  theweek,
  width 
) [inherited]
Returns a single week in a string (no newline).

Definition at line 277 of file calendar.py.

00277 
00278     def formatweek(self, theweek, width):
00279         """
00280         Returns a single week in a string (no newline).
00281         """
00282         return ' '.join(self.formatday(d, wd, width) for (d, wd) in theweek)

Here is the call graph for this function:

Here is the caller graph for this function:

def calendar.LocaleTextCalendar.formatweekday (   self,
  day,
  width 
)
Returns a formatted week day name.

Reimplemented from calendar.TextCalendar.

Definition at line 510 of file calendar.py.

00510 
00511     def formatweekday(self, day, width):
00512         with different_locale(self.locale):
00513             if width >= 9:
00514                 names = day_name
00515             else:
00516                 names = day_abbr
00517             name = names[day]
00518             return name[:width].center(width)

Here is the call graph for this function:

def calendar.TextCalendar.formatweekheader (   self,
  width 
) [inherited]
Return a header for a week.

Definition at line 293 of file calendar.py.

00293 
00294     def formatweekheader(self, width):
00295         """
00296         Return a header for a week.
00297         """
00298         return ' '.join(self.formatweekday(i, width) for i in self.iterweekdays())

Here is the call graph for this function:

Here is the caller graph for this function:

def calendar.TextCalendar.formatyear (   self,
  theyear,
  w = 2,
  l = 1,
  c = 6,
  m = 3 
) [inherited]
Returns a year's calendar as a multi-line string.

Definition at line 330 of file calendar.py.

00330 
00331     def formatyear(self, theyear, w=2, l=1, c=6, m=3):
00332         """
00333         Returns a year's calendar as a multi-line string.
00334         """
00335         w = max(2, w)
00336         l = max(1, l)
00337         c = max(2, c)
00338         colwidth = (w + 1) * 7 - 1
00339         v = []
00340         a = v.append
00341         a(repr(theyear).center(colwidth*m+c*(m-1)).rstrip())
00342         a('\n'*l)
00343         header = self.formatweekheader(w)
00344         for (i, row) in enumerate(self.yeardays2calendar(theyear, m)):
00345             # months in this row
00346             months = range(m*i+1, min(m*(i+1)+1, 13))
00347             a('\n'*l)
00348             names = (self.formatmonthname(theyear, k, colwidth, False)
00349                      for k in months)
00350             a(formatstring(names, colwidth, c).rstrip())
00351             a('\n'*l)
00352             headers = (header for k in months)
00353             a(formatstring(headers, colwidth, c).rstrip())
00354             a('\n'*l)
00355             # max number of weeks for this row
00356             height = max(len(cal) for cal in row)
00357             for j in range(height):
00358                 weeks = []
00359                 for cal in row:
00360                     if j >= len(cal):
00361                         weeks.append('')
00362                     else:
00363                         weeks.append(self.formatweek(cal[j], w))
00364                 a(formatstring(weeks, colwidth, c).rstrip())
00365                 a('\n' * l)
00366         return ''.join(v)

Here is the call graph for this function:

Here is the caller graph for this function:

def calendar.Calendar.getfirstweekday (   self) [inherited]

Definition at line 135 of file calendar.py.

00135 
00136     def getfirstweekday(self):
00137         return self._firstweekday % 7

def calendar.Calendar.itermonthdates (   self,
  year,
  month 
) [inherited]
Return an iterator for one month. The iterator will yield datetime.date
values and will always iterate through complete weeks, so it will yield
dates outside the specified month.

Definition at line 151 of file calendar.py.

00151 
00152     def itermonthdates(self, year, month):
00153         """
00154         Return an iterator for one month. The iterator will yield datetime.date
00155         values and will always iterate through complete weeks, so it will yield
00156         dates outside the specified month.
00157         """
00158         date = datetime.date(year, month, 1)
00159         # Go back to the beginning of the week
00160         days = (date.weekday() - self.firstweekday) % 7
00161         date -= datetime.timedelta(days=days)
00162         oneday = datetime.timedelta(days=1)
00163         while True:
00164             yield date
00165             date += oneday
00166             if date.month != month and date.weekday() == self.firstweekday:
00167                 break

Here is the caller graph for this function:

def calendar.Calendar.itermonthdays (   self,
  year,
  month 
) [inherited]
Like itermonthdates(), but will yield day numbers. For days outside
the specified month the day number is 0.

Definition at line 179 of file calendar.py.

00179 
00180     def itermonthdays(self, year, month):
00181         """
00182         Like itermonthdates(), but will yield day numbers. For days outside
00183         the specified month the day number is 0.
00184         """
00185         for date in self.itermonthdates(year, month):
00186             if date.month != month:
00187                 yield 0
00188             else:
00189                 yield date.day

Here is the call graph for this function:

Here is the caller graph for this function:

def calendar.Calendar.itermonthdays2 (   self,
  year,
  month 
) [inherited]
Like itermonthdates(), but will yield (day number, weekday number)
tuples. For days outside the specified month the day number is 0.

Definition at line 168 of file calendar.py.

00168 
00169     def itermonthdays2(self, year, month):
00170         """
00171         Like itermonthdates(), but will yield (day number, weekday number)
00172         tuples. For days outside the specified month the day number is 0.
00173         """
00174         for date in self.itermonthdates(year, month):
00175             if date.month != month:
00176                 yield (0, date.weekday())
00177             else:
00178                 yield (date.day, date.weekday())

Here is the call graph for this function:

Here is the caller graph for this function:

def calendar.Calendar.iterweekdays (   self) [inherited]
Return a iterator for one week of weekday numbers starting with the
configured first one.

Definition at line 143 of file calendar.py.

00143 
00144     def iterweekdays(self):
00145         """
00146         Return a iterator for one week of weekday numbers starting with the
00147         configured first one.
00148         """
00149         for i in range(self.firstweekday, self.firstweekday + 7):
00150             yield i%7

Here is the caller graph for this function:

def calendar.Calendar.monthdatescalendar (   self,
  year,
  month 
) [inherited]
Return a matrix (list of lists) representing a month's calendar.
Each row represents a week; week entries are datetime.date values.

Definition at line 190 of file calendar.py.

00190 
00191     def monthdatescalendar(self, year, month):
00192         """
00193         Return a matrix (list of lists) representing a month's calendar.
00194         Each row represents a week; week entries are datetime.date values.
00195         """
00196         dates = list(self.itermonthdates(year, month))
00197         return [ dates[i:i+7] for i in range(0, len(dates), 7) ]

Here is the call graph for this function:

Here is the caller graph for this function:

def calendar.Calendar.monthdays2calendar (   self,
  year,
  month 
) [inherited]
Return a matrix representing a month's calendar.
Each row represents a week; week entries are
(day number, weekday number) tuples. Day numbers outside this month
are zero.

Definition at line 198 of file calendar.py.

00198 
00199     def monthdays2calendar(self, year, month):
00200         """
00201         Return a matrix representing a month's calendar.
00202         Each row represents a week; week entries are
00203         (day number, weekday number) tuples. Day numbers outside this month
00204         are zero.
00205         """
00206         days = list(self.itermonthdays2(year, month))
00207         return [ days[i:i+7] for i in range(0, len(days), 7) ]

Here is the call graph for this function:

Here is the caller graph for this function:

def calendar.Calendar.monthdayscalendar (   self,
  year,
  month 
) [inherited]
Return a matrix representing a month's calendar.
Each row represents a week; days outside this month are zero.

Definition at line 208 of file calendar.py.

00208 
00209     def monthdayscalendar(self, year, month):
00210         """
00211         Return a matrix representing a month's calendar.
00212         Each row represents a week; days outside this month are zero.
00213         """
00214         days = list(self.itermonthdays(year, month))
00215         return [ days[i:i+7] for i in range(0, len(days), 7) ]

Here is the call graph for this function:

Here is the caller graph for this function:

def calendar.TextCalendar.prmonth (   self,
  theyear,
  themonth,
  w = 0,
  l = 0 
) [inherited]
Print a month's calendar.

Definition at line 308 of file calendar.py.

00308 
00309     def prmonth(self, theyear, themonth, w=0, l=0):
00310         """
00311         Print a month's calendar.
00312         """
00313         print(self.formatmonth(theyear, themonth, w, l), end=' ')

Here is the call graph for this function:

def calendar.TextCalendar.prweek (   self,
  theweek,
  width 
) [inherited]
Print a single week (no newline).

Definition at line 261 of file calendar.py.

00261 
00262     def prweek(self, theweek, width):
00263         """
00264         Print a single week (no newline).
00265         """
00266         print(self.formatweek(theweek, width), end=' ')

Here is the call graph for this function:

def calendar.TextCalendar.pryear (   self,
  theyear,
  w = 0,
  l = 0,
  c = 6,
  m = 3 
) [inherited]
Print a year's calendar.

Definition at line 367 of file calendar.py.

00367 
00368     def pryear(self, theyear, w=0, l=0, c=6, m=3):
00369         """Print a year's calendar."""
00370         print(self.formatyear(theyear, w, l, c, m))
00371 

Here is the call graph for this function:

def calendar.Calendar.setfirstweekday (   self,
  firstweekday 
) [inherited]

Definition at line 138 of file calendar.py.

00138 
00139     def setfirstweekday(self, firstweekday):
00140         self._firstweekday = firstweekday

def calendar.Calendar.yeardatescalendar (   self,
  year,
  width = 3 
) [inherited]
Return the data for the specified year ready for formatting. The return
value is a list of month rows. Each month row contains upto width months.
Each month contains between 4 and 6 weeks and each week contains 1-7
days. Days are datetime.date objects.

Definition at line 216 of file calendar.py.

00216 
00217     def yeardatescalendar(self, year, width=3):
00218         """
00219         Return the data for the specified year ready for formatting. The return
00220         value is a list of month rows. Each month row contains upto width months.
00221         Each month contains between 4 and 6 weeks and each week contains 1-7
00222         days. Days are datetime.date objects.
00223         """
00224         months = [
00225             self.monthdatescalendar(year, i)
00226             for i in range(January, January+12)
00227         ]
00228         return [months[i:i+width] for i in range(0, len(months), width) ]

Here is the call graph for this function:

def calendar.Calendar.yeardays2calendar (   self,
  year,
  width = 3 
) [inherited]
Return the data for the specified year ready for formatting (similar to
yeardatescalendar()). Entries in the week lists are
(day number, weekday number) tuples. Day numbers outside this month are
zero.

Definition at line 229 of file calendar.py.

00229 
00230     def yeardays2calendar(self, year, width=3):
00231         """
00232         Return the data for the specified year ready for formatting (similar to
00233         yeardatescalendar()). Entries in the week lists are
00234         (day number, weekday number) tuples. Day numbers outside this month are
00235         zero.
00236         """
00237         months = [
00238             self.monthdays2calendar(year, i)
00239             for i in range(January, January+12)
00240         ]
00241         return [months[i:i+width] for i in range(0, len(months), width) ]

Here is the call graph for this function:

Here is the caller graph for this function:

def calendar.Calendar.yeardayscalendar (   self,
  year,
  width = 3 
) [inherited]
Return the data for the specified year ready for formatting (similar to
yeardatescalendar()). Entries in the week lists are day numbers.
Day numbers outside this month are zero.

Definition at line 242 of file calendar.py.

00242 
00243     def yeardayscalendar(self, year, width=3):
00244         """
00245         Return the data for the specified year ready for formatting (similar to
00246         yeardatescalendar()). Entries in the week lists are day numbers.
00247         Day numbers outside this month are zero.
00248         """
00249         months = [
00250             self.monthdayscalendar(year, i)
00251             for i in range(January, January+12)
00252         ]
00253         return [months[i:i+width] for i in range(0, len(months), width) ]
00254 

Here is the call graph for this function:


Member Data Documentation

Definition at line 508 of file calendar.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.


Property Documentation

Definition at line 141 of file calendar.py.


The documentation for this class was generated from the following file: