Skip to content

Commit

Permalink
Use class attribute formater
Browse files Browse the repository at this point in the history
  • Loading branch information
huashengdun committed Aug 26, 2018
1 parent b69bdef commit 9b38d11
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions webssh/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class InvalidException(Exception):

class MixinHandler(object):

formater = 'Missing value {}'

def write_error(self, status_code, **kwargs):
exc_info = kwargs.get('exc_info')
if exc_info and len(exc_info) > 1:
Expand All @@ -52,10 +54,10 @@ def write_error(self, status_code, **kwargs):
self._reason = info.split(':', 1)[-1].strip()
super(MixinHandler, self).write_error(status_code, **kwargs)

def get_value(self, name, formater='Missing value {}'):
def get_value(self, name):
value = self.get_argument(name)
if not value:
raise InvalidException(formater.format(name))
raise InvalidException(self.formater.format(name))
return value

def get_real_client_addr(self):
Expand Down Expand Up @@ -262,7 +264,7 @@ def open(self):
self.src_addr = self.get_client_addr()
logging.info('Connected from {}:{}'.format(*self.src_addr))
try:
worker_id = self.get_value('id', formater=self.formater)
worker_id = self.get_value('id')
except (tornado.web.MissingArgumentError, InvalidException) as exc:
self.close(reason=str(exc).split(':', 1)[-1].strip())
else:
Expand Down

0 comments on commit 9b38d11

Please sign in to comment.