home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- from select import select, error
- from time import sleep
- from types import IntType
- from bisect import bisect
- POLLIN = 1
- POLLOUT = 2
- POLLERR = 8
- POLLHUP = 16
-
- class poll:
-
- def __init__(self):
- self.rlist = []
- self.wlist = []
-
-
- def register(self, f, t):
- if type(f) != IntType:
- f = f.fileno()
-
- if t & POLLIN != 0:
- insert(self.rlist, f)
- else:
- remove(self.rlist, f)
- if t & POLLOUT != 0:
- insert(self.wlist, f)
- else:
- remove(self.wlist, f)
-
-
- def unregister(self, f):
- if type(f) != IntType:
- f = f.fileno()
-
- remove(self.rlist, f)
- remove(self.wlist, f)
-
-
- def poll(self, timeout = None):
- if self.rlist != [] or self.wlist != []:
- (r, w, e) = select(self.rlist, self.wlist, [], timeout)
- else:
- sleep(timeout)
- return []
- result = []
- for s in r:
- result.append((s, POLLIN))
-
- for s in w:
- result.append((s, POLLOUT))
-
- return result
-
-
-
- def remove(list, item):
- i = bisect(list, item)
- if i > 0 and list[i - 1] == item:
- del list[i - 1]
-
-
-
- def insert(list, item):
- i = bisect(list, item)
- if i == 0 or list[i - 1] != item:
- list.insert(i, item)
-
-
-
- def test_remove():
- x = [
- 2,
- 4,
- 6]
- remove(x, 2)
- if not x == [
- 4,
- 6]:
- raise AssertionError
- x = [
- 2,
- 4,
- 6]
- remove(x, 4)
- if not x == [
- 2,
- 6]:
- raise AssertionError
- x = [
- 2,
- 4,
- 6]
- remove(x, 6)
- if not x == [
- 2,
- 4]:
- raise AssertionError
- x = [
- 2,
- 4,
- 6]
- remove(x, 5)
- if not x == [
- 2,
- 4,
- 6]:
- raise AssertionError
- x = [
- 2,
- 4,
- 6]
- remove(x, 1)
- if not x == [
- 2,
- 4,
- 6]:
- raise AssertionError
- x = [
- 2,
- 4,
- 6]
- remove(x, 7)
- if not x == [
- 2,
- 4,
- 6]:
- raise AssertionError
- x = [
- 2,
- 4,
- 6]
- remove(x, 5)
- if not x == [
- 2,
- 4,
- 6]:
- raise AssertionError
- x = []
- remove(x, 3)
- if not x == []:
- raise AssertionError
-
-
- def test_insert():
- x = [
- 2,
- 4]
- insert(x, 1)
- if not x == [
- 1,
- 2,
- 4]:
- raise AssertionError
- x = [
- 2,
- 4]
- insert(x, 3)
- if not x == [
- 2,
- 3,
- 4]:
- raise AssertionError
- x = [
- 2,
- 4]
- insert(x, 5)
- if not x == [
- 2,
- 4,
- 5]:
- raise AssertionError
- x = [
- 2,
- 4]
- insert(x, 2)
- if not x == [
- 2,
- 4]:
- raise AssertionError
- x = [
- 2,
- 4]
- insert(x, 4)
- if not x == [
- 2,
- 4]:
- raise AssertionError
- x = [
- 2,
- 3,
- 4]
- insert(x, 3)
- if not x == [
- 2,
- 3,
- 4]:
- raise AssertionError
- x = []
- insert(x, 3)
- if not x == [
- 3]:
- raise AssertionError
-
-