コード例 #1
0
ファイル: types.py プロジェクト: stepan-anokhin/comandante
def listof(value_type):
    """List of values."""
    def result_type(value):
        return list(map(value_type, value.split(',')))

    result_type.__name__ = "listof({type})".format(type=getname(value_type))
    return result_type
コード例 #2
0
 def __init__(self, option, value):
     pattern = "Invalid value for option '{name}' of type '{type}': '{value}'"
     error_message = pattern.format(name=option.name,
                                    type=getname(option.type),
                                    value=value)
     super(InvalidOptionValue, self).__init__(error_message)
     self.option = option
     self.value = value
コード例 #3
0
 def __init__(self, argument, value):
     pattern = "Invalid value for argument '{name}' of type '{type}': '{value}'"
     error_message = pattern.format(name=argument.name,
                                    type=getname(argument.type),
                                    value=value)
     super(InvalidArgumentValue, self).__init__(error_message)
     self.argument = argument
     self.value = value
コード例 #4
0
ファイル: bind.py プロジェクト: stepan-anokhin/comandante
 def __getattr__(self, item):
     """Delegate attribute access to items contained by the underlying dict."""
     if hasattr(self._target, item):
         return getattr(self._target, item)
     if item in self._target:
         return self._target[item]
     error_pattern = "'{type}' object has no attribute '{name}'"
     error_message = error_pattern.format(type=getname(type(self._target)), name=item)
     raise AttributeError(error_message)
コード例 #5
0
ファイル: proxy.py プロジェクト: stepan-anokhin/comandante
    def _unsupport(self, *names):
        for name in names:
            pattern = "'{type}' does not support method '{name}'"
            message = pattern.format(type=getname(type(self)), name=name)

            def stub(*_args, **_kwargs):
                raise TypeError(message)

            stub.__name__ = name
            self._set(name, stub)
コード例 #6
0
ファイル: handler.py プロジェクト: stepan-anokhin/comandante
    def __init__(self, name=None):
        """Initialize instance.

        Among other things this constructor will walk through
        all existing methods and collect those marked as
        cli-commands.
        """
        self._name = name or getname(type(self)).lower()
        self._declared_commands = {}
        self._declared_options = {}
        self._short_options = set()
        self._brief, self._descr = self._describe()
        self._discover_commands()
コード例 #7
0
    def summarize_option(self, option):
        """Get option summary."""
        paragraphs = []
        descr_paragraphs = self.paragraphs(self.dedent(option.descr))

        pattern = self.option_pattern(option)
        synopsis = pattern.format(long=option.name,
                                  short=option.short,
                                  type=getname(option.type))
        first_paragraph_text = "{synopsis}\n{text}".format(
            synopsis=synopsis, text=next(iter(descr_paragraphs)).text)
        first_paragraph = Paragraph(first_paragraph_text,
                                    initial_indent='',
                                    subsequent_indent=self._indent_unit)

        paragraphs.append(first_paragraph)
        for paragraph in descr_paragraphs:
            paragraph.indent(self._indent_unit)
            paragraphs.append(paragraph)

        return paragraphs
コード例 #8
0
 def test_listof_name(self):
     list_of_int = cli.listof(int)
     self.assertEqual(getname(list_of_int), 'listof(int)')
コード例 #9
0
 def test_choice_name(self):
     valid = ('first', 'second')
     choice = cli.choice(*valid)
     self.assertEqual(getname(choice), '|'.join(valid))
コード例 #10
0
    def test_getname_value(self):
        def func():
            pass

        self.assertEqual(getname(func), 'func')