# Path: common/httpd.py
# class ThreadedHTTPServer(SocketServer.ThreadingMixIn,
#                          BaseHTTPServer.HTTPServer):
# class BaseRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
#   def url_to_fs_path(self, url):
#   def send_head(self):
# 
# Path: common/util.py
# ANSI_BLUE = '\033[36m'
# ANSI_GREEN = '\033[32m'
# ANSI_RESET = '\033[0;0m'
# class Logger(object):
#   def __init__(self, color):
#   def __call__(self, msg, *args):
# def GetPackageDir():
# def GetUserDir():
# 
# Path: common/spy.py
# class Error(Exception):
# class UsageReporter(object):
# class NullUsageReporter(object):
#   def __init__(self, host_port):
#   def Send(self, msg):
#   def SendDict(self, d):
#   def SendRecord(self, event, d):
#   def Send(self, msg):
#   def SendDict(self, d):
#   def SendRecord(self, event, d):
# def _GetUsageConfig():
# def _ReadAddressFile(address_file=None):
# def GetClientFromConfig(address_file=None):


import datetime
import errno
import getpass
import json
import optparse
import os
import Queue
import threading
import string  # for lower case letters
import sys
import handlers
import tnet
from common import httpd
from common import util
from common import spy
  log('received header %r', header)

  next_part = header.get('nextPart')
  if next_part is not None:
    if isinstance(next_part, int):
      waiter.SetCounter(next_part)
      log('received counter state in header: %d', next_part)
    else:
      log('Ignored invalid nextPart %r', next_part)

  q = Queue.Queue()

  r = ReadStdin(q)
  t1 = threading.Thread(target=r)
  t1.setDaemon(True)  # So Ctrl-C works
  t1.start()

  n = Notify(q, waiter)
  t2 = threading.Thread(target=n)
  t2.setDaemon(True)  # So Ctrl-C works
  t2.start()

  scroll_name = os.path.basename(scroll_path)

  handler_class = handlers.WaitingRequestHandler
  handler_class.user_dir = opts.user_dir
  handler_class.package_dir = package_dir
  handler_class.waiters = {scroll_name: waiter}
  handler_class.active_scroll = scroll_name


# Path: common/httpd.py
# class ThreadedHTTPServer(SocketServer.ThreadingMixIn,
#                          BaseHTTPServer.HTTPServer):
# class BaseRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
#   def url_to_fs_path(self, url):
#   def send_head(self):
# 
# Path: common/util.py
# ANSI_BLUE = '\033[36m'
# ANSI_GREEN = '\033[32m'
# ANSI_RESET = '\033[0;0m'
# class Logger(object):
#   def __init__(self, color):
#   def __call__(self, msg, *args):
# def GetPackageDir():
# def GetUserDir():
# 
# Path: common/spy.py
# class Error(Exception):
# class UsageReporter(object):
# class NullUsageReporter(object):
#   def __init__(self, host_port):
#   def Send(self, msg):
#   def SendDict(self, d):
#   def SendRecord(self, event, d):
#   def Send(self, msg):
#   def SendDict(self, d):
#   def SendRecord(self, event, d):
# def _GetUsageConfig():
# def _ReadAddressFile(address_file=None):
# def GetClientFromConfig(address_file=None):


# Path: webpipe/serve.py
import datetime
import errno
import getpass
import json
import optparse
import os
import Queue
import threading
import string  # for lower case letters
import sys
import handlers
import tnet
from common import httpd
from common import util
from common import spy

  log('received header %r', header)

  next_part = header.get('nextPart')
  if next_part is not None:
    if isinstance(next_part, int):
      waiter.SetCounter(next_part)
      log('received counter state in header: %d', next_part)
    else:
      log('Ignored invalid nextPart %r', next_part)

  q = Queue.Queue()

  r = ReadStdin(q)
  t1 = threading.Thread(target=r)
  t1.setDaemon(True)  # So Ctrl-C works
  t1.start()

  n = Notify(q, waiter)
  t2 = threading.Thread(target=n)
  t2.setDaemon(True)  # So Ctrl-C works
  t2.start()

  scroll_name = os.path.basename(scroll_path)

  handler_class = handlers.WaitingRequestHandler
  handler_class.user_dir = opts.user_dir
  handler_class.package_dir = package_dir
  handler_class.waiters = {scroll_name: waiter}
  handler_class.active_scroll = scroll_name


  s = httpd.ThreadedHTTPServer(('', opts.port), handler_class)