| 298 | |
| 299 | |
| 300 | class Proxy(Handler): |
| 301 | |
| 302 | def __init__(self, wrap1, wrap2): |
| 303 | Handler.__init__(self, [wrap1.rsock, wrap1.wsock, |
| 304 | wrap2.rsock, wrap2.wsock]) |
| 305 | self.wrap1 = wrap1 |
| 306 | self.wrap2 = wrap2 |
| 307 | |
| 308 | def pre_select(self, r, w, x): |
| 309 | if self.wrap1.shut_write: |
| 310 | self.wrap2.noread() |
| 311 | if self.wrap2.shut_write: |
| 312 | self.wrap1.noread() |
| 313 | |
| 314 | if self.wrap1.connect_to: |
| 315 | _add(w, self.wrap1.rsock) |
| 316 | elif self.wrap1.buf: |
| 317 | if not self.wrap2.too_full(): |
| 318 | _add(w, self.wrap2.wsock) |
| 319 | elif not self.wrap1.shut_read: |
| 320 | _add(r, self.wrap1.rsock) |
| 321 | |
| 322 | if self.wrap2.connect_to: |
| 323 | _add(w, self.wrap2.rsock) |
| 324 | elif self.wrap2.buf: |
| 325 | if not self.wrap1.too_full(): |
| 326 | _add(w, self.wrap1.wsock) |
| 327 | elif not self.wrap2.shut_read: |
| 328 | _add(r, self.wrap2.rsock) |
| 329 | |
| 330 | def callback(self, sock): |
| 331 | self.wrap1.try_connect() |
| 332 | self.wrap2.try_connect() |
| 333 | self.wrap1.fill() |
| 334 | self.wrap2.fill() |
| 335 | self.wrap1.copy_to(self.wrap2) |
| 336 | self.wrap2.copy_to(self.wrap1) |
| 337 | if self.wrap1.buf and self.wrap2.shut_write: |
| 338 | self.wrap1.buf = [] |
| 339 | self.wrap1.noread() |
| 340 | if self.wrap2.buf and self.wrap1.shut_write: |
| 341 | self.wrap2.buf = [] |
| 342 | self.wrap2.noread() |
| 343 | if (self.wrap1.shut_read and self.wrap2.shut_read and |
| 344 | not self.wrap1.buf and not self.wrap2.buf): |
| 345 | self.ok = False |
| 346 | self.wrap1.nowrite() |
| 347 | self.wrap2.nowrite() |
| 348 | |
| 349 | |
| 350 | class Mux(Handler): |
no outgoing calls
no test coverage detected