Commit 9fd8d136 by Sheng

Added get_password method

parent 48acf09f
...@@ -40,9 +40,6 @@ def parse_encoding(data): ...@@ -40,9 +40,6 @@ def parse_encoding(data):
class MixinHandler(object): class MixinHandler(object):
arguments_required = {} # agruments must be deliverd
empty_allowed = {} # emtpy value alllowed
def get_value(self, name): def get_value(self, name):
is_required = name in self.arguments_required is_required = name in self.arguments_required
...@@ -52,7 +49,7 @@ class MixinHandler(object): ...@@ -52,7 +49,7 @@ class MixinHandler(object):
if is_required: if is_required:
raise raise
else: else:
if not value and is_required and name not in self.empty_allowed: if not value and is_required:
raise ValueError('The {} field is required.'.format(name)) raise ValueError('The {} field is required.'.format(name))
return value return value
...@@ -79,7 +76,6 @@ class MixinHandler(object): ...@@ -79,7 +76,6 @@ class MixinHandler(object):
class IndexHandler(MixinHandler, tornado.web.RequestHandler): class IndexHandler(MixinHandler, tornado.web.RequestHandler):
arguments_required = {'hostname', 'port', 'username', 'password'} arguments_required = {'hostname', 'port', 'username', 'password'}
empty_allowed = {'password'}
def initialize(self, loop, policy, host_keys_settings): def initialize(self, loop, policy, host_keys_settings):
self.loop = loop self.loop = loop
...@@ -152,11 +148,17 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler): ...@@ -152,11 +148,17 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
raise ValueError('Invalid port: {}'.format(value)) raise ValueError('Invalid port: {}'.format(value))
def get_password(self):
try:
return self.get_value('password')
except ValueError:
return ''
def get_args(self): def get_args(self):
hostname = self.get_hostname() hostname = self.get_hostname()
port = self.get_port() port = self.get_port()
username = self.get_value('username') username = self.get_value('username')
password = self.get_value('password') password = self.get_password()
privatekey = self.get_privatekey() privatekey = self.get_privatekey()
pkey = self.get_pkey_obj(privatekey, password, self.filename) \ pkey = self.get_pkey_obj(privatekey, password, self.filename) \
if privatekey else None if privatekey else None
......
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