home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / launchpadbugs / lptime.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  3.4 KB  |  104 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from datetime import datetime
  5. from time import strptime
  6. from email import Utils
  7.  
  8. class LPTime(datetime):
  9.     
  10.     def convert_rfc2822_time(time_str):
  11.         """ converts a time-string used in /+text into a time-tuple
  12.         time_str: like 'Tue, 27 Nov 2007 11:15:12 -0000'
  13.         returns: time tuple
  14.         """
  15.         return Utils.parsedate(time_str)[0:6]
  16.  
  17.     convert_rfc2822_time = staticmethod(convert_rfc2822_time)
  18.     
  19.     def convert_text_time(time_str):
  20.         """ converts a time-string used in /+text into a time-tuple
  21.         time_str: like 'Tue, 27 Nov 2007 11:15:12 -0000'
  22.         returns: time tuple
  23.         """
  24.         return strptime(time_str, '%a, %d %b %Y %H:%M:%S -0000')[0:6]
  25.  
  26.     convert_text_time = staticmethod(convert_text_time)
  27.     
  28.     def convert_html_time(time_str):
  29.         """ converts a time-string used in html-page into a time-tuple
  30.         time_str: like '2007-11-27 11:15:12 UTC'
  31.         returns: time tuple
  32.         """
  33.         return strptime(time_str, '%Y-%m-%d %H:%M:%S %Z')[0:6]
  34.  
  35.     convert_html_time = staticmethod(convert_html_time)
  36.     
  37.     def convert_activity_time(time_str):
  38.         """ converts a time-string used in activity-log-html-page into a time-tuple
  39.         time_str: like '28 Nov 07 20:10'
  40.         returns: time tuple
  41.         """
  42.         return strptime(time_str, '%d %b %y %H:%M')[0:6]
  43.  
  44.     convert_activity_time = staticmethod(convert_activity_time)
  45.     
  46.     def convert_lastcomment_time(time_str):
  47.         """ converts a time-string used in lastzcomment-function into a time-tuple
  48.         time_str: like '2007-12-24'
  49.         returns: time tuple
  50.         """
  51.         return strptime(time_str, '%Y-%m-%d')[0:3]
  52.  
  53.     convert_lastcomment_time = staticmethod(convert_lastcomment_time)
  54.     
  55.     def __new__(cls, time_str):
  56.         t = None
  57.         conv_functions = (LPTime.convert_rfc2822_time, LPTime.convert_text_time, LPTime.convert_html_time, LPTime.convert_activity_time, LPTime.convert_lastcomment_time)
  58.         for i in conv_functions:
  59.             
  60.             try:
  61.                 t = i(time_str)
  62.                 if t[0] < 1900:
  63.                     continue
  64.                 
  65.             continue
  66.             except (ValueError, TypeError):
  67.                 continue
  68.                 continue
  69.             
  70.  
  71.         else:
  72.             x = time_str.split()
  73.             if x[-1].isalpha():
  74.                 
  75.                 try:
  76.                     x[-1] = 'UTC'
  77.                     t = LPTime.convert_html_time(' '.join(x))
  78.                     if t[0] < 1900:
  79.                         t = None
  80.                 except (ValueError, TypeError):
  81.                     None<EXCEPTION MATCH>(ValueError, TypeError)
  82.                     None<EXCEPTION MATCH>(ValueError, TypeError)
  83.                 except:
  84.                     None<EXCEPTION MATCH>(ValueError, TypeError)<EXCEPTION MATCH>(ValueError, TypeError)
  85.                 
  86.  
  87.         if not t:
  88.             raise ValueError, 'Unknown date format (%s)' % time_str
  89.         t
  90.         obj = super(LPTime, cls).__new__(LPTime, *t)
  91.         if obj.year < 1900:
  92.             if obj.year < 50:
  93.                 obj = obj.replace(year = obj.year + 2000)
  94.             else:
  95.                 obj = obj.replace(year = obj.year + 1900)
  96.         
  97.         return obj
  98.  
  99.     
  100.     def __str__(self):
  101.         return self.strftime('%Y-%m-%d %H:%M:%S UTC')
  102.  
  103.  
  104.