Browse Source

add typing hint and reformat code

akkariiin/Experimental
Akkariiin 6 years ago
parent
commit
813e518c48
  1. 5
      shadowsocks/asyncdns.py
  2. 14
      shadowsocks/manager.py
  3. 3
      shadowsocks/server.py
  4. 6
      shadowsocks/shell.py

5
shadowsocks/asyncdns.py

@ -23,6 +23,7 @@ import socket
import struct
import re
import logging
import typing
if __name__ == '__main__':
import sys
@ -269,7 +270,7 @@ STATUS_IPV6 = 1
class DNSResolver(object):
def __init__(self, black_hostname_list=None):
def __init__(self, black_hostname_list: typing.Optional[typing.List[bytes]] = None):
self._loop = None
self._hosts = {}
self._hostname_status = {}
@ -388,7 +389,7 @@ class DNSResolver(object):
ip = None
for answer in response.answers:
if answer[1] in (QTYPE_A, QTYPE_AAAA) and \
answer[2] == QCLASS_IN:
answer[2] == QCLASS_IN:
ip = answer[0]
break
if IPV6_CONNECTION_SUPPORT:

14
shadowsocks/manager.py

@ -24,17 +24,17 @@ import socket
import logging
import json
import collections
import typing
from shadowsocks import common, eventloop, tcprelay, udprelay, asyncdns, shell
BUF_SIZE = 1506
STAT_SEND_LIMIT = 50
class Manager(object):
def __init__(self, config):
def __init__(self, config: typing.Dict[str, any]):
self._config = config
self._relays = {} # (tcprelay, udprelay)
self._loop = eventloop.EventLoop()
@ -168,7 +168,7 @@ class Manager(object):
send_data(r)
r.clear()
i = 0
if len(r) > 0 :
if len(r) > 0:
send_data(r)
self._statistics.clear()
@ -190,7 +190,7 @@ class Manager(object):
self._loop.run()
def run(config):
def run(config: typing.Dict[str, any]):
Manager(config).run()
@ -207,9 +207,9 @@ def test():
eventloop.TIMEOUT_PRECISION = 1
def run_server():
config = shell.get_config(True)
config: typing.Dict[str, any] = shell.get_config(True)
config = config.copy()
a_config = {
a_config: typing.Dict[str, any] = {
'server': '127.0.0.1',
'local_port': 1081,
'port_password': {
@ -223,7 +223,7 @@ def test():
'verbose': 2
}
config.update(a_config)
manager = Manager(config)
manager: Manager = Manager(config)
enc.append(manager)
manager.run()

3
shadowsocks/server.py

@ -22,6 +22,7 @@ import sys
import os
import logging
import signal
import typing
if __name__ == '__main__':
import inspect
@ -36,7 +37,7 @@ from shadowsocks import shell, daemon, eventloop, tcprelay, udprelay, \
def main():
shell.check_python()
config = shell.get_config(False)
config: typing.Dict[str, any] = shell.get_config(False)
shell.log_shadowsocks_version()

6
shadowsocks/shell.py

@ -23,6 +23,8 @@ import json
import sys
import getopt
import logging
import typing
from shadowsocks.common import to_bytes, to_str, IPNetwork, PortRange
from shadowsocks import encrypt
@ -132,9 +134,9 @@ def check_config(config, is_local):
encrypt.try_cipher(config['password'], config['method'])
def get_config(is_local):
def get_config(is_local) -> typing.Dict[str, any]:
global verbose
config = {}
config: typing.Dict[str, any] = {}
config_path = None
logging.basicConfig(level=logging.INFO,
format='%(levelname)-s: %(message)s')

Loading…
Cancel
Save