# Path: sshuttle/helpers.py
# def b(s):
#     return s.encode("ASCII")
# 
# def log(s):
#     global logprefix
#     try:
#         sys.stdout.flush()
#         # Put newline at end of string if line doesn't have one.
#         if not s.endswith("\n"):
#             s = s+"\n"
# 
#         prefix = logprefix
#         s = s.rstrip("\n")
#         for line in s.split("\n"):
#             # We output with \r\n instead of \n because when we use
#             # sudo with the use_pty option, the firewall process, the
#             # other processes printing to the terminal will have the
#             # \n move to the next line, but they will fail to reset
#             # cursor to the beginning of the line. Printing output
#             # with \r\n endings fixes that problem and does not appear
#             # to cause problems elsewhere.
#             sys.stderr.write(prefix + line + "\r\n")
#             prefix = "    "
#         sys.stderr.flush()
#     except IOError:
#         # this could happen if stderr gets forcibly disconnected, eg. because
#         # our tty closes.  That sucks, but it's no reason to abort the program.
#         pass
# 
# def debug1(s):
#     if verbose >= 1:
#         log(s)
# 
# def debug2(s):
#     if verbose >= 2:
#         log(s)
# 
# def debug3(s):
#     if verbose >= 3:
#         log(s)
# 
# class Fatal(Exception):
#     pass


import sys
import struct
import socket
import errno
import select
import os
import fcntl
from sshuttle.helpers import b, log, debug1, debug2, debug3, Fatal
            return
        rb = self.uread()
        if rb:
            self.buf.append(rb)
        if rb == b(''):  # empty string means EOF; None means temporarily empty
            self.noread()

    def copy_to(self, outwrap):
        if self.buf and self.buf[0]:
            wrote = outwrap.write(self.buf[0])
            self.buf[0] = self.buf[0][wrote:]
        while self.buf and not self.buf[0]:
            self.buf.pop(0)
        if not self.buf and self.shut_read:
            outwrap.nowrite()


class Handler:

    def __init__(self, socks=None, callback=None):
        self.ok = True
        self.socks = socks or []
        if callback:
            self.callback = callback

    def pre_select(self, r, w, x):
        for i in self.socks:
            _add(r, i)

    def callback(self, sock):

# Path: sshuttle/helpers.py
# def b(s):
#     return s.encode("ASCII")
# 
# def log(s):
#     global logprefix
#     try:
#         sys.stdout.flush()
#         # Put newline at end of string if line doesn't have one.
#         if not s.endswith("\n"):
#             s = s+"\n"
# 
#         prefix = logprefix
#         s = s.rstrip("\n")
#         for line in s.split("\n"):
#             # We output with \r\n instead of \n because when we use
#             # sudo with the use_pty option, the firewall process, the
#             # other processes printing to the terminal will have the
#             # \n move to the next line, but they will fail to reset
#             # cursor to the beginning of the line. Printing output
#             # with \r\n endings fixes that problem and does not appear
#             # to cause problems elsewhere.
#             sys.stderr.write(prefix + line + "\r\n")
#             prefix = "    "
#         sys.stderr.flush()
#     except IOError:
#         # this could happen if stderr gets forcibly disconnected, eg. because
#         # our tty closes.  That sucks, but it's no reason to abort the program.
#         pass
# 
# def debug1(s):
#     if verbose >= 1:
#         log(s)
# 
# def debug2(s):
#     if verbose >= 2:
#         log(s)
# 
# def debug3(s):
#     if verbose >= 3:
#         log(s)
# 
# class Fatal(Exception):
#     pass


# Path: sshuttle/ssnet.py
import sys
import struct
import socket
import errno
import select
import os
import fcntl
from sshuttle.helpers import b, log, debug1, debug2, debug3, Fatal

            return
        rb = self.uread()
        if rb:
            self.buf.append(rb)
        if rb == b(''):  # empty string means EOF; None means temporarily empty
            self.noread()

    def copy_to(self, outwrap):
        if self.buf and self.buf[0]:
            wrote = outwrap.write(self.buf[0])
            self.buf[0] = self.buf[0][wrote:]
        while self.buf and not self.buf[0]:
            self.buf.pop(0)
        if not self.buf and self.shut_read:
            outwrap.nowrite()


class Handler:

    def __init__(self, socks=None, callback=None):
        self.ok = True
        self.socks = socks or []
        if callback:
            self.callback = callback

    def pre_select(self, r, w, x):
        for i in self.socks:
            _add(r, i)

    def callback(self, sock):

        log('--no callback defined-- %r' % self)