home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.6)
-
- from __future__ import with_statement
- __author__ = 'dotSyntax'
- import itertools
- from time import sleep
- from types import GeneratorType as generator
- import logging
- from util import TimeOut, default_timer
- from util.primitives.structures import PriorityQueue
- log = logging.getLogger('msn.msnifier')
-
- class Msnifier(TimeOut):
-
- def __init__(self, socket):
- TimeOut.__init__(self)
- self.to_send = None
- self.socket = socket
- self.queue = PriorityQueue()
-
-
- def send_pkt(self, pkt, priority = 5):
- self._cv.__enter__()
-
- try:
- self.queue.append(pkt, priority)
- finally:
- pass
-
-
-
- def compute_timeout(self):
- if self._finished:
- self._last_computed = -1
- else:
- self._last_computed = 5
- pkt = self.next_pkt()
- if pkt is not None:
- self._last_computed = self.socket.time_to_send(str(pkt))
- self.queue.append(iter([
- pkt]), priority = 1)
-
- return self._last_computed
-
-
- def process(self):
- pkt = self.next_pkt()
- if pkt is not None:
- self.socket._send(str(pkt))
-
-
-
- def next_pkt(self):
- pkt = None
- q = self.queue
- while pkt is None and q:
-
- try:
- x = q.peek()
-
- try:
- pkt = x.next()
- except AttributeError:
- pkt = q.next()
-
- continue
- except (GeneratorExit, StopIteration, ValueError):
- q.next()
- continue
-
-
- None<EXCEPTION MATCH>(GeneratorExit, StopIteration, ValueError)
- return pkt
-
-
-