當前位置: 首頁>>代碼示例>>Python>>正文


Python lru_cache.LRUCache方法代碼示例

本文整理匯總了Python中shadowsocks.lru_cache.LRUCache方法的典型用法代碼示例。如果您正苦於以下問題:Python lru_cache.LRUCache方法的具體用法?Python lru_cache.LRUCache怎麽用?Python lru_cache.LRUCache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在shadowsocks.lru_cache的用法示例。


在下文中一共展示了lru_cache.LRUCache方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from shadowsocks import lru_cache [as 別名]
# 或者: from shadowsocks.lru_cache import LRUCache [as 別名]
def __init__(self, server_list=None):
        self._loop = None
        self._hosts = {}
        self._hostname_status = {}
        self._hostname_to_cb = {}
        self._cb_to_hostname = {}
        self._cache = lru_cache.LRUCache(timeout=300)
        self._sock = None
        if server_list is None:
            self._servers = None
            self._parse_resolv()
        else:
            self._servers = server_list
        self._parse_hosts()
        # TODO monitor hosts change and reload hosts
        # TODO parse /etc/gai.conf and follow its rules 
開發者ID:ntfreedom,項目名稱:neverendshadowsocks,代碼行數:18,代碼來源:asyncdns.py

示例2: __init__

# 需要導入模塊: from shadowsocks import lru_cache [as 別名]
# 或者: from shadowsocks.lru_cache import LRUCache [as 別名]
def __init__(self, block_hostname_list=None):
        self._loop = None
        self._hosts = {}
        self._hostname_status = {}
        self._hostname_to_cb = {}
        self._cb_to_hostname = {}
        self._cache = lru_cache.LRUCache(timeout=300)
        
        # block hostname
        if type(block_hostname_list) != list:
            self._block_hostname_list = []
        else:
            self._block_hostname_list = []
            for item in block_hostname_list:
                if type(item) != btyes:
                    item = item.encode('utf-8')
                self._block_hostname_list.appemd(item)
        logging.info("block_hostname_list is as: " + str(self._block_hostname_list))

        self._sock = None
        self._servers = None
        self._parse_resolv()
        self._parse_hosts()
        # TODO monitor hosts change and reload hosts
        # TODO parse /etc/gai.conf and follow its rules 
開發者ID:PaperDashboard,項目名稱:shadowsocks,代碼行數:27,代碼來源:asyncdns.py

示例3: __init__

# 需要導入模塊: from shadowsocks import lru_cache [as 別名]
# 或者: from shadowsocks.lru_cache import LRUCache [as 別名]
def __init__(self, black_hostname_list=None):
        self._loop = None
        self._hosts = {}
        self._hostname_status = {}
        self._hostname_to_cb = {}
        self._cb_to_hostname = {}
        self._cache = lru_cache.LRUCache(timeout=300)
        # read black_hostname_list from config
        if type(black_hostname_list) != list:
            self._black_hostname_list = []
        else:
            self._black_hostname_list = list(map(
                (lambda t: t if type(t) == bytes else t.encode('utf8')),
                black_hostname_list
            ))
        logging.info('black_hostname_list init as : ' + str(self._black_hostname_list))
        self._sock = None
        self._servers = None
        self._parse_resolv()
        self._parse_hosts()
        # TODO monitor hosts change and reload hosts
        # TODO parse /etc/gai.conf and follow its rules 
開發者ID:do21,項目名稱:ssrr,代碼行數:24,代碼來源:asyncdns.py

示例4: __init__

# 需要導入模塊: from shadowsocks import lru_cache [as 別名]
# 或者: from shadowsocks.lru_cache import LRUCache [as 別名]
def __init__(self):
        # 時間循環
        self._loop = None
        # host文件中的IP地址
        self._hosts = {}
        # 記錄請求的hostname的狀態
        self._hostname_status = {}
        # 記錄{hostname:callback}對
        self._hostname_to_cb = {}
        # 記錄{callback:hostname}對
        self._cb_to_hostname = {}
        # LRU緩存
        self._cache = lru_cache.LRUCache(timeout=300)
        # 套接字
        self._sock = None
        # DNS服務器地址
        self._servers = None
        self._parse_resolv()
        self._parse_hosts()
        # TODO monitor hosts change and reload hosts
        # TODO parse /etc/gai.conf and follow its rules 
開發者ID:youkochan,項目名稱:shadowsocks-analysis,代碼行數:23,代碼來源:asyncdns.py

示例5: __init__

# 需要導入模塊: from shadowsocks import lru_cache [as 別名]
# 或者: from shadowsocks.lru_cache import LRUCache [as 別名]
def __init__(self, server_list=None, prefer_ipv6=False):
        self._loop = None
        self._hosts = {}
        self._hostname_status = {}
        self._hostname_to_cb = {}
        self._cb_to_hostname = {}
        self._cache = lru_cache.LRUCache(timeout=300)
        self._sock = None
        if server_list is None:
            self._servers = None
            self._parse_resolv()
        else:
            self._servers = server_list
        if prefer_ipv6:
            self._QTYPES = [QTYPE_AAAA, QTYPE_A]
        else:
            self._QTYPES = [QTYPE_A, QTYPE_AAAA]
        self._parse_hosts()
        # TODO monitor hosts change and reload hosts
        # TODO parse /etc/gai.conf and follow its rules 
開發者ID:mengskysama,項目名稱:shadowsocks-rm,代碼行數:22,代碼來源:asyncdns.py

示例6: __init__

# 需要導入模塊: from shadowsocks import lru_cache [as 別名]
# 或者: from shadowsocks.lru_cache import LRUCache [as 別名]
def __init__(self, config, dns_resolver, is_local, stat_callback=None):
        self._config = config
        if is_local:
            self._listen_addr = config['local_address']
            self._listen_port = config['local_port']
            self._remote_addr = config['server']
            self._remote_port = config['server_port']
        else:
            self._listen_addr = config['server']
            self._listen_port = config['server_port']
            self._remote_addr = None
            self._remote_port = None
        self._dns_resolver = dns_resolver
        self._password = common.to_bytes(config['password'])
        self._method = config['method']
        self._timeout = config['timeout']
        self._is_local = is_local
        self._cache = lru_cache.LRUCache(timeout=config['timeout'],
                                         close_callback=self._close_client)
        self._client_fd_to_server_addr = \
            lru_cache.LRUCache(timeout=config['timeout'])
        self._dns_cache = lru_cache.LRUCache(timeout=300)
        self._eventloop = None
        self._closed = False
        self._sockets = set()
        if 'forbidden_ip' in config:
            self._forbidden_iplist = config['forbidden_ip']
        else:
            self._forbidden_iplist = None

        addrs = socket.getaddrinfo(self._listen_addr, self._listen_port, 0,
                                   socket.SOCK_DGRAM, socket.SOL_UDP)
        if len(addrs) == 0:
            raise Exception("can't get addrinfo for %s:%d" %
                            (self._listen_addr, self._listen_port))
        af, socktype, proto, canonname, sa = addrs[0]
        server_socket = socket.socket(af, socktype, proto)
        server_socket.bind((self._listen_addr, self._listen_port))
        server_socket.setblocking(False)
        self._server_socket = server_socket
        self._stat_callback = stat_callback 
開發者ID:ntfreedom,項目名稱:neverendshadowsocks,代碼行數:43,代碼來源:udprelay.py

示例7: __init__

# 需要導入模塊: from shadowsocks import lru_cache [as 別名]
# 或者: from shadowsocks.lru_cache import LRUCache [as 別名]
def __init__(self):
        self._loop = None
        self._hosts = {}
        self._hostname_status = {}
        self._hostname_to_cb = {}
        self._cb_to_hostname = {}
        self._cache = lru_cache.LRUCache(timeout=300)
        self._sock = None
        self._servers = None
        self._parse_resolv()
        self._parse_hosts()
        # TODO monitor hosts change and reload hosts
        # TODO parse /etc/gai.conf and follow its rules 
開發者ID:shadowsocksr-backup,項目名稱:shadowsocksr,代碼行數:15,代碼來源:asyncdns.py

示例8: __init__

# 需要導入模塊: from shadowsocks import lru_cache [as 別名]
# 或者: from shadowsocks.lru_cache import LRUCache [as 別名]
def __init__(self):
        self.client_id = lru_cache.LRUCache()
        self.local_client_id = b''
        self.connection_id = 0
        self.set_max_client(64) # max active client count 
開發者ID:hao35954514,項目名稱:shadowsocksR-b,代碼行數:7,代碼來源:auth.py

示例9: update

# 需要導入模塊: from shadowsocks import lru_cache [as 別名]
# 或者: from shadowsocks.lru_cache import LRUCache [as 別名]
def update(self, user_id, client_id, connection_id):
        if user_id not in self.user_id:
            self.user_id[user_id] = lru_cache.LRUCache()
        local_client_id = self.user_id[user_id]

        if client_id in local_client_id:
            local_client_id[client_id].update() 
開發者ID:hao35954514,項目名稱:shadowsocksR-b,代碼行數:9,代碼來源:auth.py

示例10: insert

# 需要導入模塊: from shadowsocks import lru_cache [as 別名]
# 或者: from shadowsocks.lru_cache import LRUCache [as 別名]
def insert(self, user_id, client_id, connection_id):
        if user_id not in self.user_id:
            self.user_id[user_id] = lru_cache.LRUCache()
        local_client_id = self.user_id[user_id]

        if local_client_id.get(client_id, None) is None or not local_client_id[client_id].enable:
            if local_client_id.first() is None or len(local_client_id) < self.max_client:
                if client_id not in local_client_id:
                    #TODO: check
                    local_client_id[client_id] = client_queue(connection_id)
                else:
                    local_client_id[client_id].re_enable(connection_id)
                return local_client_id[client_id].insert(connection_id)

            if not local_client_id[local_client_id.first()].is_active():
                del local_client_id[local_client_id.first()]
                if client_id not in local_client_id:
                    #TODO: check
                    local_client_id[client_id] = client_queue(connection_id)
                else:
                    local_client_id[client_id].re_enable(connection_id)
                return local_client_id[client_id].insert(connection_id)

            logging.warn('auth_aes128: no inactive client')
            return False
        else:
            return local_client_id[client_id].insert(connection_id) 
開發者ID:hao35954514,項目名稱:shadowsocksR-b,代碼行數:29,代碼來源:auth.py

示例11: __init__

# 需要導入模塊: from shadowsocks import lru_cache [as 別名]
# 或者: from shadowsocks.lru_cache import LRUCache [as 別名]
def __init__(self):
        self.client_data = lru_cache.LRUCache(60 * 5)
        self.client_id = os.urandom(32)
        self.startup_time = int(time.time() - 60 * 30) & 0xFFFFFFFF
        self.ticket_buf = {} 
開發者ID:hao35954514,項目名稱:shadowsocksR-b,代碼行數:7,代碼來源:obfs_tls.py

示例12: insert

# 需要導入模塊: from shadowsocks import lru_cache [as 別名]
# 或者: from shadowsocks.lru_cache import LRUCache [as 別名]
def insert(self, user_id, client_id, connection_id):
        if user_id not in self.user_id:
            self.user_id[user_id] = lru_cache.LRUCache()
        local_client_id = self.user_id[user_id]

        if local_client_id.get(client_id, None) is None or not local_client_id[client_id].enable:
            if local_client_id.first() is None or len(local_client_id) < self.max_client:
                if client_id not in local_client_id:
                    #TODO: check
                    local_client_id[client_id] = client_queue(connection_id)
                else:
                    local_client_id[client_id].re_enable(connection_id)
                return local_client_id[client_id].insert(connection_id)

            if not local_client_id[local_client_id.first()].is_active():
                del local_client_id[local_client_id.first()]
                if client_id not in local_client_id:
                    #TODO: check
                    local_client_id[client_id] = client_queue(connection_id)
                else:
                    local_client_id[client_id].re_enable(connection_id)
                return local_client_id[client_id].insert(connection_id)

            logging.warn(self.name + ': no inactive client')
            return False
        else:
            return local_client_id[client_id].insert(connection_id) 
開發者ID:hao35954514,項目名稱:shadowsocksR-b,代碼行數:29,代碼來源:auth_chain.py

示例13: __init__

# 需要導入模塊: from shadowsocks import lru_cache [as 別名]
# 或者: from shadowsocks.lru_cache import LRUCache [as 別名]
def __init__(self):
		import threading
		self.event = threading.Event()
		self.key_list = ['port', 'u', 'd', 'transfer_enable', 'passwd', 'enable']
		self.last_get_transfer = {} #上一次的實際流量
		self.last_update_transfer = {} #上一次更新到的流量(小於等於實際流量)
		self.force_update_transfer = set() #強製推入數據庫的ID
		self.port_uid_table = {} #端口到uid的映射(僅v3以上有用)
		self.onlineuser_cache = lru_cache.LRUCache(timeout=60*30) #用戶在線狀態記錄
		self.pull_ok = False #記錄是否已經拉出過數據
		self.mu_ports = {} 
開發者ID:hao35954514,項目名稱:shadowsocksR-b,代碼行數:13,代碼來源:db_transfer.py

示例14: __init__

# 需要導入模塊: from shadowsocks import lru_cache [as 別名]
# 或者: from shadowsocks.lru_cache import LRUCache [as 別名]
def __init__(self):
        self.client_data = lru_cache.LRUCache(60 * 5)
        self.client_id = os.urandom(32)
        self.startup_time = int(time.time() - 60 * 30) & 0xFFFFFFFF 
開發者ID:AlphaBrock,項目名稱:ssr-ml,代碼行數:6,代碼來源:obfs_tls.py

示例15: __init__

# 需要導入模塊: from shadowsocks import lru_cache [as 別名]
# 或者: from shadowsocks.lru_cache import LRUCache [as 別名]
def __init__(self):
		import threading
		self.event = threading.Event()
		self.key_list = ['port', 'u', 'd', 'transfer_enable', 'passwd', 'enable']
		self.last_get_transfer = {} #上一次的實際流量
		self.last_update_transfer = {} #上一次更新到的流量(小於等於實際流量)
		self.force_update_transfer = set() #強製推入數據庫的ID
		self.port_uid_table = {} #端口到uid的映射(僅v3以上有用)
		self.onlineuser_cache = lru_cache.LRUCache(timeout=60*30) #用戶在線狀態記錄
		self.pull_ok = False #記錄是否已經拉出過數據 
開發者ID:AlphaBrock,項目名稱:ssr-ml,代碼行數:12,代碼來源:db_transfer.py


注:本文中的shadowsocks.lru_cache.LRUCache方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。