<s> from . base import Socks5Connection <EOL> from fukei . config import Config <EOL> import socket <EOL> import struct <EOL> import logging <EOL> import functools <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> class LocalConnection ( Socks5Connection ) : <EOL> """<STR_LIT>""" <EOL> def do_connect ( self ) : <EOL> config = Config . current ( ) <EOL> logger . debug ( "<STR_LIT>" % ( config . server , config . server_port ) ) <EOL> logger . debug ( "<STR_LIT>" % self . dest ) <EOL> dest = ( config . server , config . server_port ) <EOL> self . upstream = self . upstream_cls ( dest , socket . AF_INET , <EOL> self . on_upstream_connect , self . on_upstream_error , <EOL> self . on_upstream_data , self . on_upstream_close ) <EOL> def on_upstream_connect ( self , _dummy ) : <EOL> config = Config . current ( ) <EOL> self . write_reply ( <NUM_LIT> , socket . inet_aton ( '<STR_LIT>' ) <EOL> + struct . pack ( "<STR_LIT>" , config . server_port ) ) <EOL> self . write_request ( ) <EOL> on_finish = functools . partial ( self . on_socks_data , finished = True ) <EOL> self . stream . read_until_close ( on_finish , self . on_socks_data ) <EOL> def write_request ( self , data = None ) : <EOL> logger . debug ( '<STR_LIT>' ) <EOL> address_type = self . atyp <EOL> if data is None : <EOL> if self . dest : <EOL> data = self . raw_dest_addr + self . raw_dest_port <EOL> else : <EOL> data = struct . pack ( "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> else : <EOL> if self . atyp == <NUM_LIT> : <EOL> address_type = <NUM_LIT> <EOL> self . upstream . write ( struct . pack ( "<STR_LIT>" , address_type ) + data ) </s>
