home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 January / maximum-cd-2012-01.iso / DiscContents / digsby_setup.exe / lib / msn / MSNObject.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-10-05  |  5.4 KB  |  162 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  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 _extra'.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, **kwds):
  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.         self._extra = kwds
  40.  
  41.     
  42.     def get_sha1d(self):
  43.         return self._sha1d.encode('base-64').strip()
  44.  
  45.     
  46.     def set_sha1d(self, new_val):
  47.         self._sha1d = new_val.decode('base-64')
  48.  
  49.     
  50.     def get_friendly(self):
  51.         return self._friendly.encode('utf-16-le').encode('base-64').strip()
  52.  
  53.     
  54.     def set_friendly(self, new_val):
  55.         self._friendly = new_val.decode('base-64').decode('utf-16-le')
  56.  
  57.     
  58.     def calc_sha1c(self):
  59.         to_hash = 'Creator%sSize%sType%sLocation%sFriendly%sSHA1D%s' % (self.creator, self.size, self.type, self.location, self.friendly, self.sha1d)
  60.         return hashlib.sha1(to_hash).digest()
  61.  
  62.     
  63.     def get_sha1c(self):
  64.         return self.calc_sha1c().encode('base-64').strip()
  65.  
  66.     
  67.     def set_sha1c(self, new_val):
  68.         if new_val != self.sha1c:
  69.             raise ValueError, 'SHA1C hash is not correct'
  70.         new_val != self.sha1c
  71.  
  72.     
  73.     def get_stamp(self):
  74.         if self._stamp is None:
  75.             return self._stamp
  76.         return self._stamp.encode('base-64').strip()
  77.  
  78.     
  79.     def set_stamp(self, new_val):
  80.         if new_val is None:
  81.             self._stamp = None
  82.         else:
  83.             self._stamp = new_val.decode('base-64')
  84.  
  85.     
  86.     def get_avatarcontentid(self):
  87.         if self._avatarcontentid is None:
  88.             return self._avatarcontentid
  89.         return msn.util.base64_encode(self._avatarcontentid)
  90.  
  91.     
  92.     def set_avatarcontentid(self, new_val):
  93.         if new_val is None:
  94.             self._avatarcontentid = None
  95.         else:
  96.             self._avatarcontentid = msn.util.base64_decode(new_val)
  97.  
  98.     friendly = property(get_friendly, set_friendly)
  99.     sha1d = property(get_sha1d, set_sha1d)
  100.     sha1c = property(get_sha1c, set_sha1c)
  101.     stamp = property(get_stamp, set_stamp)
  102.     avatarcontentid = property(get_avatarcontentid, set_avatarcontentid)
  103.     
  104.     def to_xml(self):
  105.         if self._xml is None:
  106.             t = util.xml_tag.tag('msnobj')
  107.             t._attrs = util.odict()
  108.             t._attrs['Creator'] = self.creator
  109.             t._attrs['Size'] = self.size
  110.             t._attrs['Type'] = self.type
  111.             t._attrs['Location'] = self.location
  112.             t._attrs['Friendly'] = self.friendly
  113.             t._attrs['SHA1D'] = self.sha1d
  114.             t._attrs['SHA1C'] = self.sha1c
  115.             xml = t._to_xml(pretty = False).strip()
  116.             xml = xml[:-3] + '/>'
  117.             self._xml = xml
  118.         
  119.         return self._xml
  120.  
  121.     
  122.     def __ne__(self, other):
  123.         return not self.__eq__(other)
  124.  
  125.     
  126.     def __eq__(self, other):
  127.         
  128.         try:
  129.             for attr in ('creator', 'size', 'type', 'location', 'sha1d'):
  130.                 mine = getattr(self, attr)
  131.                 theirs = getattr(other, attr)
  132.                 if getattr(self, attr) != getattr(other, attr):
  133.                     return False
  134.         except AttributeError:
  135.             e = None
  136.             return False
  137.  
  138.         return True
  139.  
  140.     
  141.     def parse(cls, xml):
  142.         t = util.xml_tag.tag(xml)
  143.         o = cls(**t._attrs)
  144.         o.stamp = t._attrs.get('stamp', None)
  145.         o.avatarcontentid = t._attrs.get('avatarcontentid', None)
  146.         (o.friendly, o.sha1d) = [ t[k] for k in [
  147.             'Friendly',
  148.             'SHA1D'] ]
  149.         
  150.         try:
  151.             o.sha1c = t['SHA1C']
  152.         except:
  153.             []
  154.             []
  155.             o.sha1c = o.sha1c
  156.  
  157.         o._xml = xml
  158.         return o
  159.  
  160.     parse = classmethod(parse)
  161.  
  162.