Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions
_strptime.LocaleTime Class Reference
Inheritance diagram for _strptime.LocaleTime:
Inheritance graph
[legend]
Collaboration diagram for _strptime.LocaleTime:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__

Public Attributes

 lang
 a_weekday
 f_weekday
 a_month
 f_month
 am_pm
 LC_date_time
 LC_date
 LC_time
 timezone
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Member Functions

def __pad
def __calc_weekday
def __calc_month
def __calc_am_pm
def __calc_date_time
def __calc_timezone

Detailed Description

Stores and handles locale-specific information related to time.

ATTRIBUTES:
    f_weekday -- full weekday names (7-item list)
    a_weekday -- abbreviated weekday names (7-item list)
    f_month -- full month names (13-item list; dummy value in [0], which
                is added by code)
    a_month -- abbreviated month names (13-item list, dummy value in
                [0], which is added by code)
    am_pm -- AM/PM representation (2-item list)
    LC_date_time -- format string for date/time representation (string)
    LC_date -- format string for date representation (string)
    LC_time -- format string for time representation (string)
    timezone -- daylight- and non-daylight-savings timezone representation
                (2-item list of sets)
    lang -- Language used by instance (2-item tuple)

Definition at line 33 of file _strptime.py.


Constructor & Destructor Documentation

Set all attributes.

Order of methods called matters for dependency reasons.

The locale language is set at the offset and then checked again before
exiting.  This is to make sure that the attributes were not set with a
mix of information from more than one locale.  This would most likely
happen when using threads where one thread calls a locale-dependent
function while another thread changes the locale while the function in
the other thread is still running.  Proper coding would call for
locks to prevent changing the locale while locale-dependent code is
running.  The check here is done in case someone does not think about
doing this.

Only other possible issue is if someone changed the timezone and did
not call tz.tzset .  That is an issue for the programmer, though,
since changing the timezone is worthless without that call.

Definition at line 52 of file _strptime.py.

00052 
00053     def __init__(self):
00054         """Set all attributes.
00055 
00056         Order of methods called matters for dependency reasons.
00057 
00058         The locale language is set at the offset and then checked again before
00059         exiting.  This is to make sure that the attributes were not set with a
00060         mix of information from more than one locale.  This would most likely
00061         happen when using threads where one thread calls a locale-dependent
00062         function while another thread changes the locale while the function in
00063         the other thread is still running.  Proper coding would call for
00064         locks to prevent changing the locale while locale-dependent code is
00065         running.  The check here is done in case someone does not think about
00066         doing this.
00067 
00068         Only other possible issue is if someone changed the timezone and did
00069         not call tz.tzset .  That is an issue for the programmer, though,
00070         since changing the timezone is worthless without that call.
00071 
00072         """
00073         self.lang = _getlang()
00074         self.__calc_weekday()
00075         self.__calc_month()
00076         self.__calc_am_pm()
00077         self.__calc_timezone()
00078         self.__calc_date_time()
00079         if _getlang() != self.lang:
00080             raise ValueError("locale changed during initialization")

Here is the caller graph for this function:


Member Function Documentation

def _strptime.LocaleTime.__calc_am_pm (   self) [private]

Definition at line 105 of file _strptime.py.

00105 
00106     def __calc_am_pm(self):
00107         # Set self.am_pm by using time.strftime().
00108 
00109         # The magic date (1999,3,17,hour,44,55,2,76,0) is not really that
00110         # magical; just happened to have used it everywhere else where a
00111         # static date was needed.
00112         am_pm = []
00113         for hour in (1, 22):
00114             time_tuple = time.struct_time((1999,3,17,hour,44,55,2,76,0))
00115             am_pm.append(time.strftime("%p", time_tuple).lower())
00116         self.am_pm = am_pm

def _strptime.LocaleTime.__calc_date_time (   self) [private]

Definition at line 117 of file _strptime.py.

00117 
00118     def __calc_date_time(self):
00119         # Set self.date_time, self.date, & self.time by using
00120         # time.strftime().
00121 
00122         # Use (1999,3,17,22,44,55,2,76,0) for magic date because the amount of
00123         # overloaded numbers is minimized.  The order in which searches for
00124         # values within the format string is very important; it eliminates
00125         # possible ambiguity for what something represents.
00126         time_tuple = time.struct_time((1999,3,17,22,44,55,2,76,0))
00127         date_time = [None, None, None]
00128         date_time[0] = time.strftime("%c", time_tuple).lower()
00129         date_time[1] = time.strftime("%x", time_tuple).lower()
00130         date_time[2] = time.strftime("%X", time_tuple).lower()
00131         replacement_pairs = [('%', '%%'), (self.f_weekday[2], '%A'),
00132                     (self.f_month[3], '%B'), (self.a_weekday[2], '%a'),
00133                     (self.a_month[3], '%b'), (self.am_pm[1], '%p'),
00134                     ('1999', '%Y'), ('99', '%y'), ('22', '%H'),
00135                     ('44', '%M'), ('55', '%S'), ('76', '%j'),
00136                     ('17', '%d'), ('03', '%m'), ('3', '%m'),
00137                     # '3' needed for when no leading zero.
00138                     ('2', '%w'), ('10', '%I')]
00139         replacement_pairs.extend([(tz, "%Z") for tz_values in self.timezone
00140                                                 for tz in tz_values])
00141         for offset,directive in ((0,'%c'), (1,'%x'), (2,'%X')):
00142             current_format = date_time[offset]
00143             for old, new in replacement_pairs:
00144                 # Must deal with possible lack of locale info
00145                 # manifesting itself as the empty string (e.g., Swedish's
00146                 # lack of AM/PM info) or a platform returning a tuple of empty
00147                 # strings (e.g., MacOS 9 having timezone as ('','')).
00148                 if old:
00149                     current_format = current_format.replace(old, new)
00150             # If %W is used, then Sunday, 2005-01-03 will fall on week 0 since
00151             # 2005-01-03 occurs before the first Monday of the year.  Otherwise
00152             # %U is used.
00153             time_tuple = time.struct_time((1999,1,3,1,1,1,6,3,0))
00154             if '00' in time.strftime(directive, time_tuple):
00155                 U_W = '%W'
00156             else:
00157                 U_W = '%U'
00158             date_time[offset] = current_format.replace('11', U_W)
00159         self.LC_date_time = date_time[0]
00160         self.LC_date = date_time[1]
00161         self.LC_time = date_time[2]

def _strptime.LocaleTime.__calc_month (   self) [private]

Definition at line 98 of file _strptime.py.

00098 
00099     def __calc_month(self):
00100         # Set self.f_month and self.a_month using the calendar module.
00101         a_month = [calendar.month_abbr[i].lower() for i in range(13)]
00102         f_month = [calendar.month_name[i].lower() for i in range(13)]
00103         self.a_month = a_month
00104         self.f_month = f_month

def _strptime.LocaleTime.__calc_timezone (   self) [private]

Definition at line 162 of file _strptime.py.

00162 
00163     def __calc_timezone(self):
00164         # Set self.timezone by using time.tzname.
00165         # Do not worry about possibility of time.tzname[0] == timetzname[1]
00166         # and time.daylight; handle that in strptime .
00167         try:
00168             time.tzset()
00169         except AttributeError:
00170             pass
00171         no_saving = frozenset(["utc", "gmt", time.tzname[0].lower()])
00172         if time.daylight:
00173             has_saving = frozenset([time.tzname[1].lower()])
00174         else:
00175             has_saving = frozenset()
00176         self.timezone = (no_saving, has_saving)
00177 

def _strptime.LocaleTime.__calc_weekday (   self) [private]

Definition at line 90 of file _strptime.py.

00090 
00091     def __calc_weekday(self):
00092         # Set self.a_weekday and self.f_weekday using the calendar
00093         # module.
00094         a_weekday = [calendar.day_abbr[i].lower() for i in range(7)]
00095         f_weekday = [calendar.day_name[i].lower() for i in range(7)]
00096         self.a_weekday = a_weekday
00097         self.f_weekday = f_weekday

def _strptime.LocaleTime.__pad (   self,
  seq,
  front 
) [private]

Definition at line 81 of file _strptime.py.

00081 
00082     def __pad(self, seq, front):
00083         # Add '' to seq to either the front (is True), else the back.
00084         seq = list(seq)
00085         if front:
00086             seq.insert(0, '')
00087         else:
00088             seq.append('')
00089         return seq


Member Data Documentation

Definition at line 102 of file _strptime.py.

Definition at line 95 of file _strptime.py.

Definition at line 115 of file _strptime.py.

Definition at line 103 of file _strptime.py.

Definition at line 96 of file _strptime.py.

Definition at line 72 of file _strptime.py.

Definition at line 159 of file _strptime.py.

Definition at line 158 of file _strptime.py.

Definition at line 160 of file _strptime.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 175 of file _strptime.py.


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