Browse Source

fix PEP8

auth
clowwindy 10 years ago
parent
commit
972bf22e6d
  1. 4
      shadowsocks/asyncdns.py
  2. 3
      shadowsocks/common.py
  3. 3
      shadowsocks/encrypt.py
  4. 3
      shadowsocks/encrypt_salsa20.py
  5. 11
      shadowsocks/tcprelay.py
  6. 1
      tests/test_latency.py

4
shadowsocks/asyncdns.py

@ -403,8 +403,8 @@ class DNSResolver(object):
self._request_id = 1 self._request_id = 1
req = build_request(hostname, qtype, self._request_id) req = build_request(hostname, qtype, self._request_id)
for server in self._servers: for server in self._servers:
logging.debug('resolving %s with type %d using server %s', hostname, logging.debug('resolving %s with type %d using server %s',
qtype, server) hostname, qtype, server)
self._sock.sendto(req, (server, 53)) self._sock.sendto(req, (server, 53))
def resolve(self, hostname, callback): def resolve(self, hostname, callback):

3
shadowsocks/common.py

@ -126,7 +126,8 @@ def parse_header(data):
else: else:
logging.warn('header is too short') logging.warn('header is too short')
else: else:
logging.warn('unsupported addrtype %d, maybe wrong password' % addrtype) logging.warn('unsupported addrtype %d, maybe wrong password' %
addrtype)
if dest_addr is None: if dest_addr is None:
return None return None
return addrtype, dest_addr, dest_port, header_length return addrtype, dest_addr, dest_port, header_length

3
shadowsocks/encrypt.py

@ -154,7 +154,8 @@ class Encryptor(object):
iv = iv_ iv = iv_
iv = iv[:m[1]] iv = iv[:m[1]]
if op == 1: if op == 1:
self.cipher_iv = iv[:m[1]] # this iv is for cipher not decipher # this iv is for cipher not decipher
self.cipher_iv = iv[:m[1]]
if method != 'salsa20-ctr': if method != 'salsa20-ctr':
import M2Crypto.EVP import M2Crypto.EVP
return M2Crypto.EVP.Cipher(method.replace('-', '_'), key, iv, return M2Crypto.EVP.Cipher(method.replace('-', '_'), key, iv,

3
shadowsocks/encrypt_salsa20.py

@ -67,7 +67,8 @@ class Salsa20Cipher(object):
def _next_stream(self): def _next_stream(self):
self._nonce &= 0xFFFFFFFFFFFFFFFF self._nonce &= 0xFFFFFFFFFFFFFFFF
self._stream = salsa20.Salsa20_keystream(BLOCK_SIZE, self._stream = salsa20.Salsa20_keystream(BLOCK_SIZE,
struct.pack('<Q', self._nonce), struct.pack('<Q',
self._nonce),
self._key) self._key)
self._nonce += 1 self._nonce += 1

11
shadowsocks/tcprelay.py

@ -201,7 +201,8 @@ class TCPRelayHandler(object):
self._config['fast_open']: self._config['fast_open']:
try: try:
self._fastopen_connected = True self._fastopen_connected = True
remote_sock = self._create_remote_socket(self._chosen_server[0], remote_sock = \
self._create_remote_socket(self._chosen_server[0],
self._chosen_server[1]) self._chosen_server[1])
self._loop.add(remote_sock, eventloop.POLL_ERR) self._loop.add(remote_sock, eventloop.POLL_ERR)
data = ''.join(self._data_to_write_to_local) data = ''.join(self._data_to_write_to_local)
@ -497,8 +498,8 @@ class TCPRelay(object):
self._timeout = config['timeout'] self._timeout = config['timeout']
self._timeouts = [] # a list for all the handlers self._timeouts = [] # a list for all the handlers
self._timeout_offset = 0 # last checked position for timeout
# we trim the timeouts once a while # we trim the timeouts once a while
self._timeout_offset = 0 # last checked position for timeout
self._handler_to_timeouts = {} # key: handler value: index in timeouts self._handler_to_timeouts = {} # key: handler value: index in timeouts
if is_local: if is_local:
@ -606,9 +607,9 @@ class TCPRelay(object):
try: try:
logging.debug('accept') logging.debug('accept')
conn = self._server_socket.accept() conn = self._server_socket.accept()
TCPRelayHandler(self, self._fd_to_handlers, self._eventloop, TCPRelayHandler(self, self._fd_to_handlers,
conn[0], self._config, self._dns_resolver, self._eventloop, conn[0], self._config,
self._is_local) self._dns_resolver, self._is_local)
except (OSError, IOError) as e: except (OSError, IOError) as e:
error_no = eventloop.errno_from_exception(e) error_no = eventloop.errno_from_exception(e)
if error_no in (errno.EAGAIN, errno.EINPROGRESS, if error_no in (errno.EAGAIN, errno.EINPROGRESS,

1
tests/test_latency.py

@ -10,4 +10,3 @@ for line in sys.stdin:
if 'HTTP/1.1 ' in line: if 'HTTP/1.1 ' in line:
diff = time.time() - before diff = time.time() - before
print 'headline %dms' % (diff * 1000) print 'headline %dms' % (diff * 1000)

Loading…
Cancel
Save