# Path: chirp/common/http.py
# _GET_REQUEST = """GET %(path)s HTTP/1.1
# User-Agent: chirp.common.http
# Host: %(host)s:%(port)d
# Accept: */*
# Connection: close
# 
# """.replace("\n", "\r\n")
# _READ_SIZE = 4096
# def get_with_timeout(host, port, path, timeout_s):


import re
import time
from chirp.common import http

_CLIENT_RE = re.compile("(\d+\.\d+\.\d+\.\d+):src port (\d+) :dst port (\d+)")


class Barix(object):

    TIMEOUT_S = 1.0

    def __init__(self, host, port):
        self.host = host
        self.port = port
        self.base_url = "http://%s:%d" % (host, port)
        self.status_url = self.base_url + "/uistatusl.html"
        self.clients_url = self.base_url + "/clients.cgi"
        
        self.last_update_time = None
        self.last_update_time_str = "unknown"
        self.status = "unknown"
        self.left_level = "unknown"
        self.right_level = "unknown"
        self.clients = {}

    def ping(self):
        status_str = http.get_with_timeout(
            self.host, self.port, "/uistatusl.html", self.TIMEOUT_S)
        if status_str is None:
            return False
        status_str = _remove_tags(status_str).replace("-->", "")
        status_info = status_str.split()


# Path: chirp/common/http.py
# _GET_REQUEST = """GET %(path)s HTTP/1.1
# User-Agent: chirp.common.http
# Host: %(host)s:%(port)d
# Accept: */*
# Connection: close
# 
# """.replace("\n", "\r\n")
# _READ_SIZE = 4096
# def get_with_timeout(host, port, path, timeout_s):


# Path: chirp/stream/barix.py
import re
import time
from chirp.common import http


_CLIENT_RE = re.compile("(\d+\.\d+\.\d+\.\d+):src port (\d+) :dst port (\d+)")


class Barix(object):

    TIMEOUT_S = 1.0

    def __init__(self, host, port):
        self.host = host
        self.port = port
        self.base_url = "http://%s:%d" % (host, port)
        self.status_url = self.base_url + "/uistatusl.html"
        self.clients_url = self.base_url + "/clients.cgi"
        
        self.last_update_time = None
        self.last_update_time_str = "unknown"
        self.status = "unknown"
        self.left_level = "unknown"
        self.right_level = "unknown"
        self.clients = {}

    def ping(self):
        status_str = http.get_with_timeout(
            self.host, self.port, "/uistatusl.html", self.TIMEOUT_S)
        if status_str is None:
            return False
        status_str = _remove_tags(status_str).replace("-->", "")
        status_info = status_str.split()


        clients_str = http.get_with_timeout(