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 / commentsbase.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  6.3 KB  |  126 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from lphelper import change_obj, user, LateBindingProperty
  5. from attachmentsbase import LPAttachments, LPAttachment
  6. import exceptions
  7.  
  8. class LPComment(object):
  9.     
  10.     def __init__(self, subject = None, text = None, attachment = None):
  11.         self.subject = subject
  12.         self.text = text
  13.         self._LPComment__attachments = set()
  14.         if attachment is None:
  15.             attachment = set()
  16.         
  17.         if isinstance(attachment, LPAttachment):
  18.             attachment = set((attachment,))
  19.         
  20.         self._LPComment__nr = id(self)
  21.         self._LPComment__user = None
  22.         self._LPComment__date = None
  23.  
  24.     
  25.     def set_attr(self, **kwargs):
  26.         self._LPComment__nr = kwargs.get('nr', self._LPComment__nr)
  27.         self._LPComment__user = kwargs.get('user', self._LPComment__user)
  28.         self._LPComment__date = kwargs.get('date', self._LPComment__date)
  29.  
  30.     
  31.     def __repr__(self):
  32.         if self._LPComment__nr and self._LPComment__user and self._LPComment__date:
  33.             return '<Comment #%s by %s on %s>' % (self._LPComment__nr, self._LPComment__user, self._LPComment__date)
  34.         return "<Comment 'unknown'>"
  35.  
  36.     
  37.     def number(self):
  38.         return self._LPComment__nr
  39.  
  40.     number = property(number)
  41.     
  42.     def user(self):
  43.         return self._LPComment__user
  44.  
  45.     user = property(user)
  46.     
  47.     def date(self):
  48.         '''TODO: return Date-object ??'''
  49.         return self._LPComment__date
  50.  
  51.     date = property(date)
  52.     
  53.     def get_attachments(self):
  54.         return self._LPComment__attachments
  55.  
  56.     
  57.     def set_attachments(self, attachment):
  58.         if isinstance(attachment, Attachment):
  59.             if not not (self.attachments):
  60.                 raise AssertionError, 'Impossible to add more then one file to a comment'
  61.             self._LPComment__attachments.add(attachment)
  62.         else:
  63.             raise TypeError, ''
  64.         return not (self.attachments)
  65.  
  66.     attachments = property(get_attachments, set_attachments, doc = 'attachment added to a comment')
  67.  
  68.  
  69. class LPComments(list):
  70.     
  71.     def __init__(self, comments = None, url = None):
  72.         self._cache = []
  73.         self._LPComments__url = url
  74.         self.parsed = False
  75.         if comments is None:
  76.             comments = list()
  77.         
  78.         list.__init__(self, comments)
  79.  
  80.     
  81.     def __repr__(self):
  82.         return '<Commentslist>'
  83.  
  84.     
  85.     def __str__(self):
  86.         if not len(self) > 1 or '[%s]':
  87.             pass
  88.         x = '%s'
  89.         return x % ','.join((lambda .0: for i in .0:
  90. str(i))(self))
  91.  
  92.     
  93.     def new(self, *args, **kwargs):
  94.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  95.  
  96.     
  97.     def parse(self):
  98.         pass
  99.  
  100.     
  101.     def add(self, comment):
  102.         if isinstance(comment, LPComment):
  103.             self.append(comment)
  104.         else:
  105.             raise IOError, "'comment' must be an instance of 'LPComment'"
  106.         return isinstance(comment, LPComment)
  107.  
  108.     
  109.     def changed(self):
  110.         changed = []
  111.         save = self[:]
  112.         while True:
  113.             if self._cache == save:
  114.                 return changed
  115.             x = save.pop()
  116.             changed.insert(0, change_obj(x, action = 'added'))
  117.             continue
  118.             self._cache == save
  119.  
  120.     changed = property(changed)
  121.     
  122.     def commit(self, force_changes = False, ignore_lp_errors = True):
  123.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  124.  
  125.  
  126.