home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / msn / MSNObject.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  5.4 KB  |  158 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import hashlib
  5. import util
  6. import util.xml_tag as util
  7. import msn
  8. from logging import getLogger
  9. log = getLogger('msn.object')
  10.  
  11. class MSNObject(object):
  12.     __slots__ = 'creator size type location friendly sha1d sha1c\n                _friendly _sha1d _sha1c stamp _stamp contenttype contentid avatarid\n                avatarcontentid _avatarcontentid _xml'.split()
  13.     EUF = '{A4268EEC-FEC5-49E5-95C3-F126696BDBF6}'
  14.     types = {
  15.         '2': 'emoticons',
  16.         '3': 'icon',
  17.         '5': 'bg_image',
  18.         '8': 'wink',
  19.         '11': 'sound',
  20.         '12': 'state' }
  21.     
  22.     def __init__(self, Creator, Type, Location, Size, SHA1D, Friendly = u'\x00', SHA1C = None, contenttype = None, contentid = None, stamp = None, avatarid = None, avatarcontentid = None):
  23.         object.__init__(self)
  24.         self.creator = Creator
  25.         self.type = Type
  26.         self.size = Size
  27.         self.location = Location
  28.         self._sha1d = SHA1D
  29.         self._friendly = Friendly
  30.         if not SHA1C:
  31.             pass
  32.         self._sha1c = self.calc_sha1c()
  33.         self._stamp = stamp
  34.         self._avatarcontentid = avatarcontentid
  35.         self.contenttype = contenttype
  36.         self.contentid = contentid
  37.         self.avatarid = avatarid
  38.         self._xml = None
  39.  
  40.     
  41.     def get_sha1d(self):
  42.         return self._sha1d.encode('base-64').strip()
  43.  
  44.     
  45.     def set_sha1d(self, new_val):
  46.         self._sha1d = new_val.decode('base-64')
  47.  
  48.     
  49.     def get_friendly(self):
  50.         return self._friendly.encode('utf-16-le').encode('base-64').strip()
  51.  
  52.     
  53.     def set_friendly(self, new_val):
  54.         self._friendly = new_val.decode('base-64').decode('utf-16-le')
  55.  
  56.     
  57.     def calc_sha1c(self):
  58.         to_hash = 'Creator%sSize%sType%sLocation%sFriendly%sSHA1D%s' % (self.creator, self.size, self.type, self.location, self.friendly, self.sha1d)
  59.         return hashlib.sha1(to_hash).digest()
  60.  
  61.     
  62.     def get_sha1c(self):
  63.         return self.calc_sha1c().encode('base-64').strip()
  64.  
  65.     
  66.     def set_sha1c(self, new_val):
  67.         if new_val != self.sha1c:
  68.             raise ValueError, 'SHA1C hash is not correct'
  69.         
  70.  
  71.     
  72.     def get_stamp(self):
  73.         return None if self._stamp is None else self._stamp.encode('base-64').strip()
  74.  
  75.     
  76.     def set_stamp(self, new_val):
  77.         if new_val is None:
  78.             self._stamp = None
  79.         else:
  80.             self._stamp = new_val.decode('base-64')
  81.  
  82.     
  83.     def get_avatarcontentid(self):
  84.         return None if self._avatarcontentid is None else msn.util.base64_encode(self._avatarcontentid)
  85.  
  86.     
  87.     def set_avatarcontentid(self, new_val):
  88.         if new_val is None:
  89.             self._avatarcontentid = None
  90.         else:
  91.             self._avatarcontentid = msn.util.base64_decode(new_val)
  92.  
  93.     friendly = property(get_friendly, set_friendly)
  94.     sha1d = property(get_sha1d, set_sha1d)
  95.     sha1c = property(get_sha1c, set_sha1c)
  96.     stamp = property(get_stamp, set_stamp)
  97.     avatarcontentid = property(get_avatarcontentid, set_avatarcontentid)
  98.     
  99.     def to_xml(self):
  100.         if self._xml is None:
  101.             t = util.xml_tag.tag('msnobj')
  102.             t._attrs = util.odict()
  103.             t._attrs['Creator'] = self.creator
  104.             t._attrs['Size'] = self.size
  105.             t._attrs['Type'] = self.type
  106.             t._attrs['Location'] = self.location
  107.             t._attrs['Friendly'] = self.friendly
  108.             t._attrs['SHA1D'] = self.sha1d
  109.             t._attrs['SHA1C'] = self.sha1c
  110.             xml = t._to_xml(pretty = False).strip()
  111.             xml = xml[:-3] + '/>'
  112.             self._xml = xml
  113.         
  114.         return self._xml
  115.  
  116.     
  117.     def __ne__(self, other):
  118.         return not self.__eq__(other)
  119.  
  120.     
  121.     def __eq__(self, other):
  122.         
  123.         try:
  124.             for attr in ('creator', 'size', 'type', 'location', 'sha1d'):
  125.                 mine = getattr(self, attr)
  126.                 theirs = getattr(other, attr)
  127.                 if getattr(self, attr) != getattr(other, attr):
  128.                     return False
  129.                     continue
  130.         except AttributeError:
  131.             e = None
  132.             return False
  133.  
  134.         return True
  135.  
  136.     
  137.     def parse(cls, xml):
  138.         t = util.xml_tag.tag(xml)
  139.         o = cls(**t._attrs)
  140.         o.stamp = t._attrs.get('stamp', None)
  141.         o.avatarcontentid = t._attrs.get('avatarcontentid', None)
  142.         (o.friendly, o.sha1d) = [ t[k] for k in [
  143.             'Friendly',
  144.             'SHA1D'] ]
  145.         
  146.         try:
  147.             o.sha1c = t['SHA1C']
  148.         except:
  149.             []
  150.             []
  151.             o.sha1c = o.sha1c
  152.  
  153.         o._xml = xml
  154.         return o
  155.  
  156.     parse = classmethod(parse)
  157.  
  158.