Example #1
0
 def __init__(self, cmd="", inputs=None, outputs=None, desc="", **kwds):
     self._inputs = as_tuple(inputs)
     self._outputs = as_tuple(outputs)
     desc_kw = dict(i=self._inputs, o=self._outputs)
     desc_kw.update(kwds)
     desc = desc.format(**desc_kw)
     cmd_kw = dict(i=shquote(self._inputs), o=shquote(self._outputs))
     cmd_kw.update(kwds)
     cmd = vformat_list(string.Formatter(), cmd, [], cmd_kw)
     if not desc:
         desc = cmd
     super().__init__(cmd=cmd, desc=desc)
Example #2
0
def _parse_template(format_strings, cls_name, cls_members, cls_bases):
    """Parse the template in *format_strings* in the given class context.

    The new placeholders are inserted in the *cls_members* namespace
    modifying it in-place.
    """
    ctxt = _ClsContext(cls_name, cls_members, cls_bases)
    parser = _TemplateParser(ctxt)
    parser.parse(as_tuple(format_strings))
Example #3
0
def vformat_template(format_strings, command, kwds=None):
    """Format *format_string* using *command* as a mapping.

    *kwds* can be used as an alternative mapping to the default one
    provided by the FormatView of the given *command*. If *kwds* is not a
    sub-class of FormatView, that class is used instead.
    """
    if isinstance(kwds, Mapping):
        kwds = FormatView(command, kwds)
    if not kwds:
        kwds = FormatView
    if isinstance(kwds, type) and issubclass(kwds, FormatView):
        kwds = kwds(command)
    format_strings = as_tuple(format_strings)
    # Filter out empty string and join with one space.
    return vformat_list(Formatter(), format_strings, [], kwds)
Example #4
0
 def test_set(self):
     self.assertCountEqual(as_tuple(set(("foo", "bar"))), ("foo", "bar"))
Example #5
0
 def test_tuple(self):
     self.assertEqual(as_tuple(("foo", "bar")), ("foo", "bar"))
Example #6
0
 def test_list(self):
     self.assertEqual(as_tuple(["foo", "bar"]), ("foo", "bar"))
Example #7
0
 def test_singleton(self):
     self.assertEqual(as_tuple("foo"), ("foo",))
Example #8
0
 def test_none(self):
     self.assertEqual(as_tuple(None), ())
Example #9
0
 def parse(self, format_strings):
     for format_string in as_tuple(format_strings):
         self._formatter.vformat(format_string, [], self._view)