home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2080 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  7.4 KB  |  229 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import re
  5. import time
  6. import warnings
  7.  
  8. class ExperimentalWarning(UserWarning):
  9.     pass
  10.  
  11.  
  12. def experimental(message):
  13.     warnings.warn(message, ExperimentalWarning, stacklevel = 3)
  14.  
  15.  
  16. def hide_experimental_warnings():
  17.     warnings.filterwarnings('ignore', category = ExperimentalWarning)
  18.  
  19.  
  20. def reset_experimental_warnings():
  21.     warnings.filterwarnings('default', category = ExperimentalWarning)
  22.  
  23.  
  24. def deprecation(message):
  25.     warnings.warn(message, DeprecationWarning, stacklevel = 3)
  26.  
  27.  
  28. def hide_deprecations():
  29.     warnings.filterwarnings('ignore', category = DeprecationWarning)
  30.  
  31.  
  32. def reset_deprecations():
  33.     warnings.filterwarnings('default', category = DeprecationWarning)
  34.  
  35.  
  36. def isstringlike(x):
  37.     
  38.     try:
  39.         x + ''
  40.     except:
  41.         return False
  42.  
  43.     return True
  44.  
  45. from calendar import timegm
  46. EPOCH = 1970
  47.  
  48. def my_timegm(tt):
  49.     (year, month, mday, hour, min, sec) = tt[:6]
  50.     if year >= EPOCH:
  51.         if month <= month:
  52.             pass
  53.         elif month <= 12:
  54.             if mday <= mday:
  55.                 pass
  56.             elif mday <= 31:
  57.                 if hour <= hour:
  58.                     pass
  59.                 elif hour <= 24:
  60.                     if min <= min:
  61.                         pass
  62.                     elif min <= 59:
  63.                         if sec <= sec:
  64.                             pass
  65.                         elif sec <= 61:
  66.                             return timegm(tt)
  67.     return None
  68.  
  69. days = [
  70.     'Mon',
  71.     'Tue',
  72.     'Wed',
  73.     'Thu',
  74.     'Fri',
  75.     'Sat',
  76.     'Sun']
  77. months = [
  78.     'Jan',
  79.     'Feb',
  80.     'Mar',
  81.     'Apr',
  82.     'May',
  83.     'Jun',
  84.     'Jul',
  85.     'Aug',
  86.     'Sep',
  87.     'Oct',
  88.     'Nov',
  89.     'Dec']
  90. months_lower = []
  91. for month in months:
  92.     months_lower.append(month.lower())
  93.  
  94.  
  95. def time2isoz(t = None):
  96.     if t is None:
  97.         t = time.time()
  98.     
  99.     (year, mon, mday, hour, min, sec) = time.gmtime(t)[:6]
  100.     return '%04d-%02d-%02d %02d:%02d:%02dZ' % (year, mon, mday, hour, min, sec)
  101.  
  102.  
  103. def time2netscape(t = None):
  104.     if t is None:
  105.         t = time.time()
  106.     
  107.     (year, mon, mday, hour, min, sec, wday) = time.gmtime(t)[:7]
  108.     return '%s %02d-%s-%04d %02d:%02d:%02d GMT' % (days[wday], mday, months[mon - 1], year, hour, min, sec)
  109.  
  110. UTC_ZONES = {
  111.     'GMT': None,
  112.     'UTC': None,
  113.     'UT': None,
  114.     'Z': None }
  115. timezone_re = re.compile('^([-+])?(\\d\\d?):?(\\d\\d)?$')
  116.  
  117. def offset_from_tz_string(tz):
  118.     offset = None
  119.     if UTC_ZONES.has_key(tz):
  120.         offset = 0
  121.     else:
  122.         m = timezone_re.search(tz)
  123.         if m:
  124.             offset = 3600 * int(m.group(2))
  125.             if m.group(3):
  126.                 offset = offset + 60 * int(m.group(3))
  127.             
  128.             if m.group(1) == '-':
  129.                 offset = -offset
  130.             
  131.         
  132.     return offset
  133.  
  134.  
  135. def _str2time(day, mon, yr, hr, min, sec, tz):
  136.     
  137.     try:
  138.         mon = months_lower.index(mon.lower()) + 1
  139.     except ValueError:
  140.         
  141.         try:
  142.             imon = int(mon)
  143.         except ValueError:
  144.             return None
  145.  
  146.         if imon <= imon:
  147.             pass
  148.         elif imon <= 12:
  149.             mon = imon
  150.         else:
  151.             return None
  152.         imon <= 12
  153.  
  154.     if hr is None:
  155.         hr = 0
  156.     
  157.     if min is None:
  158.         min = 0
  159.     
  160.     if sec is None:
  161.         sec = 0
  162.     
  163.     yr = int(yr)
  164.     day = int(day)
  165.     hr = int(hr)
  166.     min = int(min)
  167.     sec = int(sec)
  168.     if yr < 1000:
  169.         cur_yr = time.localtime(time.time())[0]
  170.         m = cur_yr % 100
  171.         tmp = yr
  172.         yr = yr + cur_yr - m
  173.         m = m - tmp
  174.         if abs(m) > 50:
  175.             if m > 0:
  176.                 yr = yr + 100
  177.             else:
  178.                 yr = yr - 100
  179.         
  180.     
  181.     t = my_timegm((yr, mon, day, hr, min, sec, tz))
  182.     if t is not None:
  183.         if tz is None:
  184.             tz = 'UTC'
  185.         
  186.         tz = tz.upper()
  187.         offset = offset_from_tz_string(tz)
  188.         if offset is None:
  189.             return None
  190.         t = t - offset
  191.     
  192.     return t
  193.  
  194. strict_re = re.compile('^[SMTWF][a-z][a-z], (\\d\\d) ([JFMASOND][a-z][a-z]) (\\d\\d\\d\\d) (\\d\\d):(\\d\\d):(\\d\\d) GMT$')
  195. wkday_re = re.compile('^(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)[a-z]*,?\\s*', re.I)
  196. loose_http_re = re.compile('^\n    (\\d\\d?)            # day\n       (?:\\s+|[-\\/])\n    (\\w+)              # month\n        (?:\\s+|[-\\/])\n    (\\d+)              # year\n    (?:\n          (?:\\s+|:)    # separator before clock\n       (\\d\\d?):(\\d\\d)  # hour:min\n       (?::(\\d\\d))?    # optional seconds\n    )?                 # optional clock\n       \\s*\n    ([-+]?\\d{2,4}|(?![APap][Mm]\\b)[A-Za-z]+)? # timezone\n       \\s*\n    (?:\\(\\w+\\))?       # ASCII representation of timezone in parens.\n       \\s*$', re.X)
  197.  
  198. def http2time(text):
  199.     m = strict_re.search(text)
  200.     if m:
  201.         g = m.groups()
  202.         mon = months_lower.index(g[1].lower()) + 1
  203.         tt = (int(g[2]), mon, int(g[0]), int(g[3]), int(g[4]), float(g[5]))
  204.         return my_timegm(tt)
  205.     text = text.lstrip()
  206.     text = wkday_re.sub('', text, 1)
  207.     (day, mon, yr, hr, min, sec, tz) = [
  208.         None] * 7
  209.     m = loose_http_re.search(text)
  210.     if m is not None:
  211.         (day, mon, yr, hr, min, sec, tz) = m.groups()
  212.     else:
  213.         return None
  214.     return m(day, mon, yr, hr, min, sec, tz)
  215.  
  216. iso_re = re.compile('^\n    (\\d{4})              # year\n       [-\\/]?\n    (\\d\\d?)              # numerical month\n       [-\\/]?\n    (\\d\\d?)              # day\n   (?:\n         (?:\\s+|[-:Tt])  # separator before clock\n      (\\d\\d?):?(\\d\\d)    # hour:min\n      (?::?(\\d\\d(?:\\.\\d*)?))?  # optional seconds (and fractional)\n   )?                    # optional clock\n      \\s*\n   ([-+]?\\d\\d?:?(:?\\d\\d)?\n    |Z|z)?               # timezone  (Z is "zero meridian", i.e. GMT)\n      \\s*$', re.X)
  217.  
  218. def iso2time(text):
  219.     text = text.lstrip()
  220.     (day, mon, yr, hr, min, sec, tz) = [
  221.         None] * 7
  222.     m = iso_re.search(text)
  223.     if m is not None:
  224.         (yr, mon, day, hr, min, sec, tz, _) = m.groups()
  225.     else:
  226.         return None
  227.     return m is not None(day, mon, yr, hr, min, sec, tz)
  228.  
  229.