# Path: common/tool_connect.py
# class ToolConnect:
#     def __init__(self, server_name, port):
#     def _ill_formed_request(self, conn, data):
#     def wait_request(self):
#     def send_text_reply(self, conn, data):
#     def send_reply(self, conn, data):
#     def close(self):
# 
# Path: common/job_queue.py
# class JobQueue:
#     def __init__(self, filename = None):
#     def put(self, *args):
#     def remove(self):
#     def get(self):
#     def copy_items(self, get_last = False):
#     def save(self, filename):
#     def empty(self):
#     def _load(self, filename):
#     def expect(func, data, *args):
#     def put_get_save_test():
#     def thread_test():
#         def thread1(jobs):
#         def thread2(jobs):
# 
# Path: common/lifo_cache.py
# class LifoCacheMem(object):
# class LifoCache(LifoCacheMem):
#     def __init__(self, cache_size):
#     def get(self, key):
#     def set(self, key, data):
#     def stat_ratio(self, count, total = None):
#     def access_stat(self, as_type = None):
#     def __init__(self, cache_name, mem_cache_size = 4, disk_cache_size = 32):
#     def get(self, filename):
#     def set(self, filename, data):
#     def access_stat(self, as_type = None):
# 
# Path: common/utils.py
# def read_file(filename):
# def write_file(filename, text):
# def save_obj(filename, data):
# def load_obj(filename):
# def sha1(filename):
# def write_sha1(sha1, filename):
# def url_opener():
# def copy_file_from_url(url, out_file, expect_sha1 = None, max_retry = 4):
# def compress_file_data(out_filename, data, compress_type):
# def compress_file(out_filename, in_filename, compress_type):
# def uncompress_file(filename, compress_type):
# def _retry_on_eintr(func, *args):
# def safe_read(fd):
# def safe_write(fd, text):
# def print_traceback(*kwargs):
# def readline_backward(filename, buf_size=8192):
# 
# Path: common/common_html.py
# def get_head(title, css = None, html5 = False):


import sys
import os
import thread
import time
import pywikibot
import verify_match
from common import tool_connect
from common import job_queue
from common import lifo_cache
from common import utils
from common import common_html
            user = user.replace(' ', '_')

            print (date_s(t) + " REQUEST " + user + ' ' + lang + ' ' + cmd + ' ' + title).encode('utf-8')

            if cmd == "verify":
                queue.put(title, lang, user, t, tools, conn)
            elif cmd == 'status':
                html = do_status(queue)
                tools.send_text_reply(conn, html)
                conn.close()
            elif cmd == 'ping':
                tools.send_reply(conn, ret_val(E_OK, 'pong'))
                conn.close()
            else:
                tools.send_reply(conn, ret_val(E_ERROR, "unknown command: " + cmd))
                conn.close()

    finally:
        tools.close()
        print >> sys.stderr, "STOP"

def date_s(at):
    t = time.gmtime(at)
    return "[%02d/%02d/%d:%02d:%02d:%02d]"%(t[2],t[1],t[0],t[3],t[4],t[5])


def job_thread(queue):
    cache_dir1 = 'verify_match_diff'
    cached_diff = lifo_cache.LifoCache(cache_dir1)
    cache_dir2 = 'verify_match_text_layer'

# Path: common/tool_connect.py
# class ToolConnect:
#     def __init__(self, server_name, port):
#     def _ill_formed_request(self, conn, data):
#     def wait_request(self):
#     def send_text_reply(self, conn, data):
#     def send_reply(self, conn, data):
#     def close(self):
# 
# Path: common/job_queue.py
# class JobQueue:
#     def __init__(self, filename = None):
#     def put(self, *args):
#     def remove(self):
#     def get(self):
#     def copy_items(self, get_last = False):
#     def save(self, filename):
#     def empty(self):
#     def _load(self, filename):
#     def expect(func, data, *args):
#     def put_get_save_test():
#     def thread_test():
#         def thread1(jobs):
#         def thread2(jobs):
# 
# Path: common/lifo_cache.py
# class LifoCacheMem(object):
# class LifoCache(LifoCacheMem):
#     def __init__(self, cache_size):
#     def get(self, key):
#     def set(self, key, data):
#     def stat_ratio(self, count, total = None):
#     def access_stat(self, as_type = None):
#     def __init__(self, cache_name, mem_cache_size = 4, disk_cache_size = 32):
#     def get(self, filename):
#     def set(self, filename, data):
#     def access_stat(self, as_type = None):
# 
# Path: common/utils.py
# def read_file(filename):
# def write_file(filename, text):
# def save_obj(filename, data):
# def load_obj(filename):
# def sha1(filename):
# def write_sha1(sha1, filename):
# def url_opener():
# def copy_file_from_url(url, out_file, expect_sha1 = None, max_retry = 4):
# def compress_file_data(out_filename, data, compress_type):
# def compress_file(out_filename, in_filename, compress_type):
# def uncompress_file(filename, compress_type):
# def _retry_on_eintr(func, *args):
# def safe_read(fd):
# def safe_write(fd, text):
# def print_traceback(*kwargs):
# def readline_backward(filename, buf_size=8192):
# 
# Path: common/common_html.py
# def get_head(title, css = None, html5 = False):


# Path: verify_match/verify_match_web.py
import sys
import os
import thread
import time
import pywikibot
import verify_match
from common import tool_connect
from common import job_queue
from common import lifo_cache
from common import utils
from common import common_html

            user = user.replace(' ', '_')

            print (date_s(t) + " REQUEST " + user + ' ' + lang + ' ' + cmd + ' ' + title).encode('utf-8')

            if cmd == "verify":
                queue.put(title, lang, user, t, tools, conn)
            elif cmd == 'status':
                html = do_status(queue)
                tools.send_text_reply(conn, html)
                conn.close()
            elif cmd == 'ping':
                tools.send_reply(conn, ret_val(E_OK, 'pong'))
                conn.close()
            else:
                tools.send_reply(conn, ret_val(E_ERROR, "unknown command: " + cmd))
                conn.close()

    finally:
        tools.close()
        print >> sys.stderr, "STOP"

def date_s(at):
    t = time.gmtime(at)
    return "[%02d/%02d/%d:%02d:%02d:%02d]"%(t[2],t[1],t[0],t[3],t[4],t[5])


def job_thread(queue):
    cache_dir1 = 'verify_match_diff'
    cached_diff = lifo_cache.LifoCache(cache_dir1)
    cache_dir2 = 'verify_match_text_layer'

    cached_text = lifo_cache.LifoCache(cache_dir2)