Back to index

python3.2  3.2.2
Classes | Functions | Variables
email._parseaddr Namespace Reference

Classes

class  AddrlistClass
class  AddressList

Functions

def parsedate_tz
def parsedate
def mktime_tz
def quote

Variables

list __all__
string SPACE = ' '
string EMPTYSTRING = ''
string COMMASPACE = ', '
list _monthnames
list _daynames = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']
dictionary _timezones

Function Documentation

Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.

Definition at line 154 of file _parseaddr.py.

00154 
00155 def mktime_tz(data):
00156     """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp."""
00157     if data[9] is None:
00158         # No zone info, so localtime is better assumption than GMT
00159         return time.mktime(data[:8] + (-1,))
00160     else:
00161         t = time.mktime(data[:8] + (0,))
00162         return t - data[9] - time.timezone
00163 

Convert a time string to a time tuple.

Definition at line 145 of file _parseaddr.py.

00145 
00146 def parsedate(data):
00147     """Convert a time string to a time tuple."""
00148     t = parsedate_tz(data)
00149     if isinstance(t, tuple):
00150         return t[:9]
00151     else:
00152         return t
00153 

Here is the call graph for this function:

Convert a date string to a time tuple.

Accounts for military timezones.

Definition at line 45 of file _parseaddr.py.

00045 
00046 def parsedate_tz(data):
00047     """Convert a date string to a time tuple.
00048 
00049     Accounts for military timezones.
00050     """
00051     data = data.split()
00052     # The FWS after the comma after the day-of-week is optional, so search and
00053     # adjust for this.
00054     if data[0].endswith(',') or data[0].lower() in _daynames:
00055         # There's a dayname here. Skip it
00056         del data[0]
00057     else:
00058         i = data[0].rfind(',')
00059         if i >= 0:
00060             data[0] = data[0][i+1:]
00061     if len(data) == 3: # RFC 850 date, deprecated
00062         stuff = data[0].split('-')
00063         if len(stuff) == 3:
00064             data = stuff + data[1:]
00065     if len(data) == 4:
00066         s = data[3]
00067         i = s.find('+')
00068         if i == -1:
00069             i = s.find('-')
00070         if i > 0:
00071             data[3:] = [s[:i], s[i:]]
00072         else:
00073             data.append('') # Dummy tz
00074     if len(data) < 5:
00075         return None
00076     data = data[:5]
00077     [dd, mm, yy, tm, tz] = data
00078     mm = mm.lower()
00079     if mm not in _monthnames:
00080         dd, mm = mm, dd.lower()
00081         if mm not in _monthnames:
00082             return None
00083     mm = _monthnames.index(mm) + 1
00084     if mm > 12:
00085         mm -= 12
00086     if dd[-1] == ',':
00087         dd = dd[:-1]
00088     i = yy.find(':')
00089     if i > 0:
00090         yy, tm = tm, yy
00091     if yy[-1] == ',':
00092         yy = yy[:-1]
00093     if not yy[0].isdigit():
00094         yy, tz = tz, yy
00095     if tm[-1] == ',':
00096         tm = tm[:-1]
00097     tm = tm.split(':')
00098     if len(tm) == 2:
00099         [thh, tmm] = tm
00100         tss = '0'
00101     elif len(tm) == 3:
00102         [thh, tmm, tss] = tm
00103     else:
00104         return None
00105     try:
00106         yy = int(yy)
00107         dd = int(dd)
00108         thh = int(thh)
00109         tmm = int(tmm)
00110         tss = int(tss)
00111     except ValueError:
00112         return None
00113     # Check for a yy specified in two-digit format, then convert it to the
00114     # appropriate four-digit format, according to the POSIX standard. RFC 822
00115     # calls for a two-digit yy, but RFC 2822 (which obsoletes RFC 822)
00116     # mandates a 4-digit yy. For more information, see the documentation for
00117     # the time module.
00118     if yy < 100:
00119         # The year is between 1969 and 1999 (inclusive).
00120         if yy > 68:
00121             yy += 1900
00122         # The year is between 2000 and 2068 (inclusive).
00123         else:
00124             yy += 2000
00125     tzoffset = None
00126     tz = tz.upper()
00127     if tz in _timezones:
00128         tzoffset = _timezones[tz]
00129     else:
00130         try:
00131             tzoffset = int(tz)
00132         except ValueError:
00133             pass
00134     # Convert a timezone offset into seconds ; -0500 -> -18000
00135     if tzoffset:
00136         if tzoffset < 0:
00137             tzsign = -1
00138             tzoffset = -tzoffset
00139         else:
00140             tzsign = 1
00141         tzoffset = tzsign * ( (tzoffset//100)*3600 + (tzoffset % 100)*60)
00142     # Daylight Saving Time flag is set to -1, since DST is unknown.
00143     return yy, mm, dd, thh, tmm, tss, 0, 1, -1, tzoffset
00144 

Here is the call graph for this function:

Here is the caller graph for this function:

def email._parseaddr.quote (   str)
Prepare string to be used in a quoted string.

Turns backslash and double quote characters into quoted pairs.  These
are the only characters that need to be quoted inside a quoted string.
Does not add the surrounding double quotes.

Definition at line 164 of file _parseaddr.py.

00164 
00165 def quote(str):
00166     """Prepare string to be used in a quoted string.
00167 
00168     Turns backslash and double quote characters into quoted pairs.  These
00169     are the only characters that need to be quoted inside a quoted string.
00170     Does not add the surrounding double quotes.
00171     """
00172     return str.replace('\\', '\\\\').replace('"', '\\"')
00173 

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
00001 [
00002     'mktime_tz',
00003     'parsedate',
00004     'parsedate_tz',
00005     'quote',
00006     ]

Definition at line 9 of file _parseaddr.py.

list email._parseaddr._daynames = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']

Definition at line 28 of file _parseaddr.py.

Initial value:
00001 ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul',
00002                'aug', 'sep', 'oct', 'nov', 'dec',
00003                'january', 'february', 'march', 'april', 'may', 'june', 'july',
00004                'august', 'september', 'october', 'november', 'december']

Definition at line 23 of file _parseaddr.py.

Initial value:
00001 {'UT':0, 'UTC':0, 'GMT':0, 'Z':0,
00002               'AST': -400, 'ADT': -300,  # Atlantic (used in Canada)
00003               'EST': -500, 'EDT': -400,  # Eastern
00004               'CST': -600, 'CDT': -500,  # Central
00005               'MST': -700, 'MDT': -600,  # Mountain
00006               'PST': -800, 'PDT': -700   # Pacific
00007               }

Definition at line 36 of file _parseaddr.py.

Definition at line 20 of file _parseaddr.py.

Definition at line 19 of file _parseaddr.py.

Definition at line 18 of file _parseaddr.py.