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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. __author__ = 'dotSyntax'
  6. import itertools
  7. from time import sleep
  8. from types import GeneratorType as generator
  9. import logging
  10. from util import TimeOut, default_timer
  11. from util.primitives.structures import PriorityQueue
  12. log = logging.getLogger('msn.msnifier')
  13.  
  14. class Msnifier(TimeOut):
  15.     
  16.     def __init__(self, socket):
  17.         TimeOut.__init__(self)
  18.         self.to_send = None
  19.         self.socket = socket
  20.         self.queue = PriorityQueue()
  21.  
  22.     
  23.     def send_pkt(self, pkt, priority = 5):
  24.         self._cv.__enter__()
  25.         
  26.         try:
  27.             self.queue.append(pkt, priority)
  28.         finally:
  29.             pass
  30.  
  31.  
  32.     
  33.     def compute_timeout(self):
  34.         if self._finished:
  35.             self._last_computed = -1
  36.         else:
  37.             self._last_computed = 5
  38.             pkt = self.next_pkt()
  39.             if pkt is not None:
  40.                 self._last_computed = self.socket.time_to_send(str(pkt))
  41.                 self.queue.append(iter([
  42.                     pkt]), priority = 1)
  43.             
  44.         return self._last_computed
  45.  
  46.     
  47.     def process(self):
  48.         pkt = self.next_pkt()
  49.         if pkt is not None:
  50.             self.socket._send(str(pkt))
  51.         
  52.  
  53.     
  54.     def next_pkt(self):
  55.         pkt = None
  56.         q = self.queue
  57.         while pkt is None and q:
  58.             
  59.             try:
  60.                 x = q.peek()
  61.                 
  62.                 try:
  63.                     pkt = x.next()
  64.                 except AttributeError:
  65.                     pkt = q.next()
  66.  
  67.             continue
  68.             except (GeneratorExit, StopIteration, ValueError):
  69.                 q.next()
  70.                 continue
  71.             
  72.  
  73.             None<EXCEPTION MATCH>(GeneratorExit, StopIteration, ValueError)
  74.         return pkt
  75.  
  76.  
  77.