Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Attributes
MoinMoin.support.parsedatetime.parsedatetime_consts.Constants Class Reference

List of all members.

Public Member Functions

def __init__
def __getattr__
def daysInMonth
def buildSources

Public Attributes

 localeID
 fallbackLocales
 locale
 usePyICU
 Second
 Minute
 Hour
 Day
 Week
 Month
 Year
 rangeSep
 BirthdayEpoch
 DOWParseStyle
 CurrentDOWParseStyle
 re_sources
 re_values
 Modifiers
 dayOffsets
 WeekdayOffsets
 MonthOffsets
 dateSep
 timeSep
 am
 pm
 meridian
 usesMeridian
 uses24
 dp_order
 RE_DATE4
 RE_DATE3
 RE_MONTH
 RE_WEEKDAY
 RE_SPECIAL
 RE_UNITS
 RE_QUNITS
 RE_MODIFIER
 RE_MODIFIER2
 RE_TIMEHMS
 RE_TIMEHMS2
 RE_DATE
 RE_DATE2
 RE_DAY
 RE_DAY2
 RE_TIME
 RE_REMAINING
 RE_RTIMEHMS
 RE_RTIMEHMS2
 RE_RDATE
 RE_RDATE3
 DATERNG1
 DATERNG2
 DATERNG3
 TIMERNG1
 TIMERNG2
 TIMERNG3
 TIMERNG4
 re_option
 cre_source
 cre_keys

Private Attributes

 _leapYears
 _DaysInMonthList

Detailed Description

Default set of constants for parsedatetime.

If PyICU is present, then the class will first try to get PyICU
to return a locale specified by C{localeID}.  If either C{localeID} is
None or if the locale does not exist within PyICU, then each of the
locales defined in C{fallbackLocales} is tried in order.

If PyICU is not present or none of the specified locales can be used,
then the class will initialize itself to the en_US locale.

if PyICU is not present or not requested, only the locales defined by
C{pdtLocales} will be searched.

Definition at line 874 of file parsedatetime_consts.py.


Constructor & Destructor Documentation

def MoinMoin.support.parsedatetime.parsedatetime_consts.Constants.__init__ (   self,
  localeID = None,
  usePyICU = True,
  fallbackLocales = ['en_US'] 
)

Definition at line 889 of file parsedatetime_consts.py.

00889 
00890     def __init__(self, localeID=None, usePyICU=True, fallbackLocales=['en_US']):
00891         self.localeID        = localeID
00892         self.fallbackLocales = fallbackLocales
00893 
00894         if 'en_US' not in self.fallbackLocales:
00895             self.fallbackLocales.append('en_US')
00896 
00897           # define non-locale specific constants
00898 
00899         self.locale   = None
00900         self.usePyICU = usePyICU
00901 
00902         # starting cache of leap years
00903         # daysInMonth will add to this if during
00904         # runtime it gets a request for a year not found
00905         self._leapYears = [ 1904, 1908, 1912, 1916, 1920, 1924, 1928, 1932, 1936, 1940, 1944,
00906                             1948, 1952, 1956, 1960, 1964, 1968, 1972, 1976, 1980, 1984, 1988,
00907                             1992, 1996, 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032,
00908                             2036, 2040, 2044, 2048, 2052, 2056, 2060, 2064, 2068, 2072, 2076,
00909                             2080, 2084, 2088, 2092, 2096 ]
00910 
00911         self.Second =   1
00912         self.Minute =  60 * self.Second
00913         self.Hour   =  60 * self.Minute
00914         self.Day    =  24 * self.Hour
00915         self.Week   =   7 * self.Day
00916         self.Month  =  30 * self.Day
00917         self.Year   = 365 * self.Day
00918 
00919         self.rangeSep = u'-'
00920 
00921         self._DaysInMonthList = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
00922 
00923         self.BirthdayEpoch = 50
00924 
00925         # DOWParseStyle controls how we parse "Tuesday"
00926         # If the current day was Thursday and the text to parse is "Tuesday"
00927         # then the following table shows how each style would be returned
00928         # -1, 0, +1
00929         #
00930         # Current day marked as ***
00931         #
00932         #          Sun Mon Tue Wed Thu Fri Sat
00933         # week -1
00934         # current         -1,0     ***
00935         # week +1          +1
00936         #
00937         # If the current day was Monday and the text to parse is "Tuesday"
00938         # then the following table shows how each style would be returned
00939         # -1, 0, +1
00940         #
00941         #          Sun Mon Tue Wed Thu Fri Sat
00942         # week -1           -1
00943         # current      *** 0,+1
00944         # week +1
00945 
00946         self.DOWParseStyle = 1
00947 
00948         # CurrentDOWParseStyle controls how we parse "Friday"
00949         # If the current day was Friday and the text to parse is "Friday"
00950         # then the following table shows how each style would be returned
00951         # True/False. This also depends on DOWParseStyle.
00952         #
00953         # Current day marked as ***
00954         #
00955         # DOWParseStyle = 0
00956         #          Sun Mon Tue Wed Thu Fri Sat
00957         # week -1
00958         # current                      T,F
00959         # week +1
00960         #
00961         # DOWParseStyle = -1
00962         #          Sun Mon Tue Wed Thu Fri Sat
00963         # week -1                       F
00964         # current                       T
00965         # week +1
00966         #
00967         # DOWParseStyle = +1
00968         #
00969         #          Sun Mon Tue Wed Thu Fri Sat
00970         # week -1
00971         # current                       T
00972         # week +1                       F
00973 
00974         self.CurrentDOWParseStyle = False
00975 
00976         # initalize attributes to empty values to ensure
00977         # they are defined
00978         self.re_sources     = None
00979         self.re_values      = None
00980         self.Modifiers      = None
00981         self.dayOffsets     = None
00982         self.WeekdayOffsets = None
00983         self.MonthOffsets   = None
00984         self.dateSep        = None
00985         self.timeSep        = None
00986         self.am             = None
00987         self.pm             = None
00988         self.meridian       = None
00989         self.usesMeridian   = None
00990         self.uses24         = None
00991         self.dp_order       = None
00992 
00993         self.RE_DATE4     = r''
00994         self.RE_DATE3     = r''
00995         self.RE_MONTH     = r''
00996         self.RE_WEEKDAY   = r''
00997         self.RE_SPECIAL   = r''
00998         self.RE_UNITS     = r''
00999         self.RE_QUNITS    = r''
01000         self.RE_MODIFIER  = r''
01001         self.RE_MODIFIER2 = r''
01002         self.RE_TIMEHMS   = r''
01003         self.RE_TIMEHMS2  = r''
01004         self.RE_DATE      = r''
01005         self.RE_DATE2     = r''
01006         self.RE_DAY       = r''
01007         self.RE_DAY2      = r''
01008         self.RE_TIME      = r''
01009         self.RE_REMAINING = r''
01010         self.RE_RTIMEHMS  = r''
01011         self.RE_RTIMEHMS2 = r''
01012         self.RE_RDATE     = r''
01013         self.RE_RDATE3    = r''
01014         self.DATERNG1     = r''
01015         self.DATERNG2     = r''
01016         self.DATERNG3     = r''
01017         self.TIMERNG1     = r''
01018         self.TIMERNG2     = r''
01019         self.TIMERNG3     = r''
01020         self.TIMERNG4     = r''
01021 
01022         _initLocale(self)
01023         _initConstants(self)
01024         _initSymbols(self)
01025         _initPatterns(self)
01026 
01027         self.re_option = re.IGNORECASE + re.VERBOSE
01028         self.cre_source = { 'CRE_SPECIAL':   self.RE_SPECIAL,
01029                             'CRE_UNITS':     self.RE_UNITS,
01030                             'CRE_QUNITS':    self.RE_QUNITS,
01031                             'CRE_MODIFIER':  self.RE_MODIFIER,
01032                             'CRE_MODIFIER2': self.RE_MODIFIER2,
01033                             'CRE_TIMEHMS':   self.RE_TIMEHMS,
01034                             'CRE_TIMEHMS2':  self.RE_TIMEHMS2,
01035                             'CRE_DATE':      self.RE_DATE,
01036                             'CRE_DATE2':     self.RE_DATE2,
01037                             'CRE_DATE3':     self.RE_DATE3,
01038                             'CRE_DATE4':     self.RE_DATE4,
01039                             'CRE_MONTH':     self.RE_MONTH,
01040                             'CRE_WEEKDAY':   self.RE_WEEKDAY,
01041                             'CRE_DAY':       self.RE_DAY,
01042                             'CRE_DAY2':      self.RE_DAY2,
01043                             'CRE_TIME':      self.RE_TIME,
01044                             'CRE_REMAINING': self.RE_REMAINING,
01045                             'CRE_RTIMEHMS':  self.RE_RTIMEHMS,
01046                             'CRE_RTIMEHMS2': self.RE_RTIMEHMS2,
01047                             'CRE_RDATE':     self.RE_RDATE,
01048                             'CRE_RDATE3':    self.RE_RDATE3,
01049                             'CRE_TIMERNG1':  self.TIMERNG1,
01050                             'CRE_TIMERNG2':  self.TIMERNG2,
01051                             'CRE_TIMERNG3':  self.TIMERNG3,
01052                             'CRE_TIMERNG4':  self.TIMERNG4,
01053                             'CRE_DATERNG1':  self.DATERNG1,
01054                             'CRE_DATERNG2':  self.DATERNG2,
01055                             'CRE_DATERNG3':  self.DATERNG3,
01056                           }
01057         self.cre_keys = self.cre_source.keys()
01058 


Member Function Documentation

Definition at line 1059 of file parsedatetime_consts.py.

01059 
01060     def __getattr__(self, name):
01061         if name in self.cre_keys:
01062             value = re.compile(self.cre_source[name], self.re_option)
01063             setattr(self, name, value)
01064             return value
01065         else:
01066             raise AttributeError, name

Return a dictionary of date/time tuples based on the keys
found in self.re_sources.

The current time is used as the default and any specified
item found in self.re_sources is inserted into the value
and the generated dictionary is returned.

Definition at line 1087 of file parsedatetime_consts.py.

01087 
01088     def buildSources(self, sourceTime=None):
01089         """
01090         Return a dictionary of date/time tuples based on the keys
01091         found in self.re_sources.
01092 
01093         The current time is used as the default and any specified
01094         item found in self.re_sources is inserted into the value
01095         and the generated dictionary is returned.
01096         """
01097         if sourceTime is None:
01098             (yr, mth, dy, hr, mn, sec, wd, yd, isdst) = time.localtime()
01099         else:
01100             (yr, mth, dy, hr, mn, sec, wd, yd, isdst) = sourceTime
01101 
01102         sources  = {}
01103         defaults = { 'yr': yr, 'mth': mth, 'dy':  dy,
01104                      'hr': hr, 'mn':  mn,  'sec': sec, }
01105 
01106         for item in self.re_sources:
01107             values = {}
01108             source = self.re_sources[item]
01109 
01110             for key in defaults.keys():
01111                 if key in source:
01112                     values[key] = source[key]
01113                 else:
01114                     values[key] = defaults[key]
01115 
01116             sources[item] = ( values['yr'], values['mth'], values['dy'],
01117                               values['hr'], values['mn'], values['sec'], wd, yd, isdst )
01118 
01119         return sources
01120 
Take the given month (1-12) and a given year (4 digit) return
the number of days in the month adjusting for leap year as needed

Definition at line 1067 of file parsedatetime_consts.py.

01067 
01068     def daysInMonth(self, month, year):
01069         """
01070         Take the given month (1-12) and a given year (4 digit) return
01071         the number of days in the month adjusting for leap year as needed
01072         """
01073         result = None
01074 
01075         if month > 0 and month <= 12:
01076             result = self._DaysInMonthList[month - 1]
01077 
01078             if month == 2:
01079                 if year in self._leapYears:
01080                     result += 1
01081                 else:
01082                     if calendar.isleap(year):
01083                         self._leapYears.append(year)
01084                         result += 1
01085 
01086         return result


Member Data Documentation

Definition at line 920 of file parsedatetime_consts.py.

Definition at line 904 of file parsedatetime_consts.py.

Definition at line 985 of file parsedatetime_consts.py.

Definition at line 922 of file parsedatetime_consts.py.

Definition at line 1056 of file parsedatetime_consts.py.

Definition at line 1027 of file parsedatetime_consts.py.

Definition at line 973 of file parsedatetime_consts.py.

Definition at line 1013 of file parsedatetime_consts.py.

Definition at line 1014 of file parsedatetime_consts.py.

Definition at line 1015 of file parsedatetime_consts.py.

Definition at line 983 of file parsedatetime_consts.py.

Definition at line 913 of file parsedatetime_consts.py.

Definition at line 980 of file parsedatetime_consts.py.

Definition at line 945 of file parsedatetime_consts.py.

Definition at line 990 of file parsedatetime_consts.py.

Definition at line 891 of file parsedatetime_consts.py.

Definition at line 912 of file parsedatetime_consts.py.

Definition at line 898 of file parsedatetime_consts.py.

Definition at line 890 of file parsedatetime_consts.py.

Definition at line 987 of file parsedatetime_consts.py.

Definition at line 911 of file parsedatetime_consts.py.

Definition at line 979 of file parsedatetime_consts.py.

Definition at line 915 of file parsedatetime_consts.py.

Definition at line 982 of file parsedatetime_consts.py.

Definition at line 986 of file parsedatetime_consts.py.

Definition at line 918 of file parsedatetime_consts.py.

Definition at line 1003 of file parsedatetime_consts.py.

Definition at line 1004 of file parsedatetime_consts.py.

Definition at line 993 of file parsedatetime_consts.py.

Definition at line 992 of file parsedatetime_consts.py.

Definition at line 1005 of file parsedatetime_consts.py.

Definition at line 1006 of file parsedatetime_consts.py.

Definition at line 999 of file parsedatetime_consts.py.

Definition at line 1000 of file parsedatetime_consts.py.

Definition at line 994 of file parsedatetime_consts.py.

Definition at line 1026 of file parsedatetime_consts.py.

Definition at line 998 of file parsedatetime_consts.py.

Definition at line 1011 of file parsedatetime_consts.py.

Definition at line 1012 of file parsedatetime_consts.py.

Definition at line 1008 of file parsedatetime_consts.py.

Definition at line 1009 of file parsedatetime_consts.py.

Definition at line 1010 of file parsedatetime_consts.py.

Definition at line 977 of file parsedatetime_consts.py.

Definition at line 996 of file parsedatetime_consts.py.

Definition at line 1007 of file parsedatetime_consts.py.

Definition at line 1001 of file parsedatetime_consts.py.

Definition at line 1002 of file parsedatetime_consts.py.

Definition at line 997 of file parsedatetime_consts.py.

Definition at line 978 of file parsedatetime_consts.py.

Definition at line 995 of file parsedatetime_consts.py.

Definition at line 910 of file parsedatetime_consts.py.

Definition at line 1016 of file parsedatetime_consts.py.

Definition at line 1017 of file parsedatetime_consts.py.

Definition at line 1018 of file parsedatetime_consts.py.

Definition at line 1019 of file parsedatetime_consts.py.

Definition at line 984 of file parsedatetime_consts.py.

Definition at line 899 of file parsedatetime_consts.py.

Definition at line 989 of file parsedatetime_consts.py.

Definition at line 988 of file parsedatetime_consts.py.

Definition at line 914 of file parsedatetime_consts.py.

Definition at line 981 of file parsedatetime_consts.py.

Definition at line 916 of file parsedatetime_consts.py.


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