Commit deef92fe by Sheng

Move get_client_addr to MixinHandler

parent e66e5f20
...@@ -48,6 +48,10 @@ class MixinHandler(object): ...@@ -48,6 +48,10 @@ class MixinHandler(object):
raise InvalidValueError('Missing value {}'.format(name)) raise InvalidValueError('Missing value {}'.format(name))
return value return value
def get_client_addr(self):
return self.get_real_client_addr() or self.request.connection.context.\
address
def get_real_client_addr(self): def get_real_client_addr(self):
ip = self.request.remote_ip ip = self.request.remote_ip
...@@ -194,10 +198,6 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler): ...@@ -194,10 +198,6 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
logging.debug(args) logging.debug(args)
return args return args
def get_client_addr(self):
return self.get_real_client_addr() or self.request.connection.stream.\
socket.getpeername()
def get_default_encoding(self, ssh): def get_default_encoding(self, ssh):
try: try:
_, stdout, _ = ssh.exec_command('locale charmap') _, stdout, _ = ssh.exec_command('locale charmap')
...@@ -277,9 +277,6 @@ class WsockHandler(MixinHandler, tornado.websocket.WebSocketHandler): ...@@ -277,9 +277,6 @@ class WsockHandler(MixinHandler, tornado.websocket.WebSocketHandler):
self.loop = loop self.loop = loop
self.worker_ref = None self.worker_ref = None
def get_client_addr(self):
return self.get_real_client_addr() or self.stream.socket.getpeername()
def open(self): def open(self):
self.src_addr = self.get_client_addr() self.src_addr = self.get_client_addr()
logging.info('Connected from {}:{}'.format(*self.src_addr)) logging.info('Connected from {}:{}'.format(*self.src_addr))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment