# Path: ss/settings.py
# class Settings(object):
#     DEFAULT_TIMEOUT = 300
#     _LOCK = RLock()
#     def __init__(self):
#     def __getitem__(self, name):
#     def __setitem__(self, name, val):
#     def get(self, name, default=None):
#     def __contains__(self, name):
#     def update(self, config):
#     def dict(self):
#     def __repr__(self):
# 
# Path: ss/utils.py
# PY2 = sys.version_info[0] == 2
# def compat_ord(s):
# def compat_chr(d):
# def to_bytes(s):
# def to_str(s):
# def inet_ntop(family, ipstr):
# def inet_pton(family, addr):
# def is_ip(address):
# def patch_socket():
# def pack_addr(address):
# def errno_from_exception(e):
# def get_sock_error(sock):
# def merge_prefix(deque, size):
# 
# Path: ss/encrypt.py
# CIPHERS_TO_TEST = [
#     'aes-128-cfb',
#     'aes-256-cfb',
#     'rc4-md5',
#     'salsa20',
#     'chacha20',
#     'table',
# ]


import json
import os
import sys
import base64
import tkinter as tk
    import tkMessageBox as messagebox
    import logging
from tkinter import ttk
from functools import partial
from threading import Thread
from ss.settings import settings
from ss import utils
from ss.encrypt import CIPHERS_TO_TEST
    from urllib import urlopen, urlencode
    from tkinter import messagebox
    from urllib.request import urlopen
    from urllib.parse import urlencode
                from ss.config import set_proxy_mode
        from ss.wrapper import onexit_callbacks
        from ss.cli import parse_cli
        from ss.management import run_local
        from ss.ioloop import IOLoop, TIMEOUT_PRECISION
        from ss.watcher import Pac
    def on_select_conf(self, *v):
        try:
            bindvar = self.form.get_bindvar_by_name("conf")
            val = bindvar.get()
            with open(self.confile(val), "rb") as f:
                raw_conf = json.load(f)

            rhost = raw_conf.pop("rhost")
            rhost, rport = rhost.split(":")
            raw_conf["rhost"] = rhost
            raw_conf["rport"] = int(rport)

            for key, val in raw_conf.items():
                self.form.get_bindvar_by_name(key).set(val)

        except Exception as err:
            messagebox.showerror("警告", err)

    def startop_proxy(self):
        if self._proxy_started:
            self.stop_proxy()
        else:
            self.start_proxy()

    def _start_proxy(self, confile):
        try:
            parse_cli(["local", "-c", confile])
            t = Thread(target=run_local, name="proxy", args=(None, ))
            t.setDaemon(True)
            t.start()

# Path: ss/settings.py
# class Settings(object):
#     DEFAULT_TIMEOUT = 300
#     _LOCK = RLock()
#     def __init__(self):
#     def __getitem__(self, name):
#     def __setitem__(self, name, val):
#     def get(self, name, default=None):
#     def __contains__(self, name):
#     def update(self, config):
#     def dict(self):
#     def __repr__(self):
# 
# Path: ss/utils.py
# PY2 = sys.version_info[0] == 2
# def compat_ord(s):
# def compat_chr(d):
# def to_bytes(s):
# def to_str(s):
# def inet_ntop(family, ipstr):
# def inet_pton(family, addr):
# def is_ip(address):
# def patch_socket():
# def pack_addr(address):
# def errno_from_exception(e):
# def get_sock_error(sock):
# def merge_prefix(deque, size):
# 
# Path: ss/encrypt.py
# CIPHERS_TO_TEST = [
#     'aes-128-cfb',
#     'aes-256-cfb',
#     'rc4-md5',
#     'salsa20',
#     'chacha20',
#     'table',
# ]


# Path: ss/gui/app.py
import json
import os
import sys
import base64
import tkinter as tk
    import tkMessageBox as messagebox
    import logging
from tkinter import ttk
from functools import partial
from threading import Thread
from ss.settings import settings
from ss import utils
from ss.encrypt import CIPHERS_TO_TEST
    from urllib import urlopen, urlencode
    from tkinter import messagebox
    from urllib.request import urlopen
    from urllib.parse import urlencode
                from ss.config import set_proxy_mode
        from ss.wrapper import onexit_callbacks
        from ss.cli import parse_cli
        from ss.management import run_local
        from ss.ioloop import IOLoop, TIMEOUT_PRECISION
        from ss.watcher import Pac

    def on_select_conf(self, *v):
        try:
            bindvar = self.form.get_bindvar_by_name("conf")
            val = bindvar.get()
            with open(self.confile(val), "rb") as f:
                raw_conf = json.load(f)

            rhost = raw_conf.pop("rhost")
            rhost, rport = rhost.split(":")
            raw_conf["rhost"] = rhost
            raw_conf["rport"] = int(rport)

            for key, val in raw_conf.items():
                self.form.get_bindvar_by_name(key).set(val)

        except Exception as err:
            messagebox.showerror("警告", err)

    def startop_proxy(self):
        if self._proxy_started:
            self.stop_proxy()
        else:
            self.start_proxy()

    def _start_proxy(self, confile):
        try:
            parse_cli(["local", "-c", confile])
            t = Thread(target=run_local, name="proxy", args=(None, ))
            t.setDaemon(True)
            t.start()

            self._prev_proxy_mode = settings["proxy_mode"]