page.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:argparseweb 作者: nirizr 项目源码 文件源码
def get_input_object(self, action, prefix):
    input_parameters = {}
    input_parameters['class'] = self.get_class(prefix)
    input_parameters['name'] = self.get_id(action, prefix)
    input_parameters['id'] = self.get_id(action, prefix)

    input_type = web.form.Textbox

    if self.get_choices(action):
      input_type = web.form.Dropdown
      input_parameters['args'] = [choice for choice in action.choices]
      if self.get_multiple(action):
        input_parameters['multiple'] = 'multiple'
        input_parameters['size'] = 4
    elif isinstance(action, (argparse._StoreTrueAction, argparse._StoreFalseAction, argparse._StoreConstAction)):
      input_type = web.form.Checkbox
      input_parameters['checked'] = True if action.default else False
      input_parameters['value'] = action.const
    else:
      input_parameters['value'] = action.default if action.default else ""

    if isinstance(action, argparse._SubParsersAction):
      input_parameters['onChange'] = "javascript: update_show(this);"
      input_parameters['value'] = action.choices.keys()[0]

    if len(action.option_strings):
      input_parameters['default'] = action.default
      # if optional argument may be present with either 1 or no parameters, the default shifts
      # to being the no parameter's value. this is mearly to properly display actual values to the user
      if action.nargs == '?':
        input_parameters['value'] = action.const

    # TODO: support these actions: append, append_const, count
    self._actions[self.get_id(action, prefix)] = action
    input_object = input_type(**input_parameters)

    input_object.description = self.get_description(action)
    input_object.nargs = self.get_nargs(action)
    input_object.help = self.get_help(action)
    input_object.disposition = self.get_disposition(action)
    input_object.subparser = self.get_subparser(action)
    input_object.choices = self.get_choices(action)

    return input_object
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号