コード例 #1
0
ファイル: component.py プロジェクト: subokita/Aglyph
    def _resolve(self, arg, assembler):
        """Return the resolved *arg*.

        :param arg:
           represents an argument (positional or keyword) to
           :attr:`factory`
        :param aglyph.assembly.Assembler assembler:
           the assembler that will be used to resolve *arg*
        :return:
           the resolved argument value that will actually be passed to
           :attr:`factory`

        """
        if isinstance(arg, Reference):
            return assembler.assemble(arg)
        elif isinstance(arg, Evaluator):
            return arg(assembler)
        elif isinstance(arg, partial):
            return arg()
        elif isinstance(arg, dict):
            # either keys or values may themselves be References, partials, or
            # Evaluators
            resolve = self._resolve
            return dict(
                [(resolve(key, assembler), resolve(value, assembler))
                    for (key, value) in arg.items()])
        elif hasattr(arg, "__iter__") and not is_string(arg):
            resolve = self._resolve
            # assumption: the iterable class supports initialization with
            # __init__(iterable)
            return arg.__class__([resolve(value, assembler) for value in arg])
        else:
            return arg
コード例 #2
0
ファイル: __init__.py プロジェクト: subokita/Aglyph
def _identify(spec):
    """Determine the unique ID for *spec*.

    :arg spec:
       an **importable** class, function, or module; or a :obj:`str`
    :return:
       *spec* unchanged (if it is a :obj:`str`), else *spec*'s
       importable dotted name
    :rtype:
       :obj:`str`

    If *spec* is a string, it is assumed to already represent a unique
    ID and is returned unchanged. Otherwise, *spec* is assumed to be an
    **importable** class, function, or module, and its dotted name is
    returned (see :func:`format_dotted_name`).

    """
    return spec if is_string(spec) else format_dotted_name(spec)
コード例 #3
0
ファイル: __init__.py プロジェクト: mzipay/Aglyph
def _identify(spec):
    """Determine the unique ID for *spec*.

    :arg spec:
       an **importable** class, function, or module; or a :obj:`str`
    :return:
       *spec* unchanged (if it is a :obj:`str`), else *spec*'s
       importable dotted name
    :rtype:
       :obj:`str`

    If *spec* is a string, it is assumed to already represent a unique
    ID and is returned unchanged. Otherwise, *spec* is assumed to be an
    **importable** class, function, or module, and its dotted name is
    returned (see :func:`format_dotted_name`).

    """
    return spec if is_string(spec) else format_dotted_name(spec)
コード例 #4
0
ファイル: test_is_string.py プロジェクト: mzipay/Aglyph
 def test_none_is_not_string(self):
     self.assertFalse(is_string(None))
コード例 #5
0
ファイル: test_is_string.py プロジェクト: mzipay/Aglyph
 def test_literal_string_is_string_type(self):
     # this is redundant w/r/t one of the previous two tests, depending on
     # the runtime Python version
     self.assertTrue(is_string(""))
コード例 #6
0
ファイル: test_is_string.py プロジェクト: mzipay/Aglyph
 def test_data_type_is_string_type(self):
     self.assertTrue(is_string(DataType()))
コード例 #7
0
ファイル: test_Reference.py プロジェクト: mzipay/Aglyph
 def test_user_class(self):
     ref = Reference(dummy.ModuleClass)
     self.assertTrue(isinstance(ref, Reference))
     self.assertTrue(is_string(ref))
     self.assertEqual("test.dummy.ModuleClass", ref)
コード例 #8
0
 def test_builtin_function(self):
     ref = Reference(hex)
     self.assertTrue(isinstance(ref, Reference))
     self.assertTrue(is_string(ref))
     self.assertEqual("%s.hex" % hex.__module__, ref)
コード例 #9
0
ファイル: test_Reference.py プロジェクト: mzipay/Aglyph
 def test_user_function(self):
     ref = Reference(dummy.factory_function)
     self.assertTrue(isinstance(ref, Reference))
     self.assertTrue(is_string(ref))
     self.assertEqual("test.dummy.factory_function", ref)
コード例 #10
0
ファイル: test_is_string.py プロジェクト: subokita/Aglyph
 def test_none_is_not_string(self):
     self.assertFalse(is_string(None))
コード例 #11
0
ファイル: test_is_string.py プロジェクト: subokita/Aglyph
 def test_data_type_is_string_type(self):
     self.assertTrue(is_string(DataType()))
コード例 #12
0
ファイル: test_is_string.py プロジェクト: subokita/Aglyph
 def test_literal_string_is_string_type(self):
     # this is redundant w/r/t one of the previous two tests, depending on
     # the runtime Python version
     self.assertTrue(is_string(""))
コード例 #13
0
ファイル: test_is_string.py プロジェクト: subokita/Aglyph
 def test_text_type_is_string_type(self):
     self.assertTrue(is_string(TextType()))
コード例 #14
0
ファイル: test_Reference.py プロジェクト: mzipay/Aglyph
 def test_module(self):
     ref = Reference(dummy)
     self.assertTrue(isinstance(ref, Reference))
     self.assertTrue(is_string(ref))
     self.assertEqual("test.dummy", ref)
コード例 #15
0
ファイル: test_Reference.py プロジェクト: mzipay/Aglyph
 def test_builtin_function(self):
     ref = Reference(hex)
     self.assertTrue(isinstance(ref, Reference))
     self.assertTrue(is_string(ref))
     self.assertEqual("%s.hex" % hex.__module__, ref)
コード例 #16
0
ファイル: test_is_string.py プロジェクト: mzipay/Aglyph
 def test_number_is_not_string(self):
     self.assertFalse(is_string(79))
コード例 #17
0
 def test_string(self):
     ref = Reference("test-component-id")
     self.assertTrue(isinstance(ref, Reference))
     self.assertTrue(is_string(ref))
     self.assertEqual("test-component-id", ref)
コード例 #18
0
ファイル: test_is_string.py プロジェクト: mzipay/Aglyph
 def test_reference_is_string(self):
     self.assertTrue(is_string(Reference("test")))
コード例 #19
0
 def test_builtin_class(self):
     ref = Reference(float)
     self.assertTrue(isinstance(ref, Reference))
     self.assertTrue(is_string(ref))
     self.assertEqual("%s.float" % float.__module__, ref)
コード例 #20
0
ファイル: test_is_string.py プロジェクト: subokita/Aglyph
 def test_number_is_not_string(self):
     self.assertFalse(is_string(79))
コード例 #21
0
ファイル: test_Reference.py プロジェクト: mzipay/Aglyph
 def test_builtin_class(self):
     ref = Reference(float)
     self.assertTrue(isinstance(ref, Reference))
     self.assertTrue(is_string(ref))
     self.assertEqual("%s.float" % float.__module__, ref)
コード例 #22
0
 def test_user_class(self):
     ref = Reference(dummy.ModuleClass)
     self.assertTrue(isinstance(ref, Reference))
     self.assertTrue(is_string(ref))
     self.assertEqual("test.dummy.ModuleClass", ref)
コード例 #23
0
ファイル: test_is_string.py プロジェクト: subokita/Aglyph
 def test_reference_is_string(self):
     self.assertTrue(is_string(Reference("test")))
コード例 #24
0
 def test_user_function(self):
     ref = Reference(dummy.factory_function)
     self.assertTrue(isinstance(ref, Reference))
     self.assertTrue(is_string(ref))
     self.assertEqual("test.dummy.factory_function", ref)
コード例 #25
0
ファイル: test_is_string.py プロジェクト: mzipay/Aglyph
 def test_text_type_is_string_type(self):
     self.assertTrue(is_string(TextType()))
コード例 #26
0
 def test_module(self):
     ref = Reference(dummy)
     self.assertTrue(isinstance(ref, Reference))
     self.assertTrue(is_string(ref))
     self.assertEqual("test.dummy", ref)
コード例 #27
0
ファイル: test_Reference.py プロジェクト: mzipay/Aglyph
 def test_string(self):
     ref = Reference("test-component-id")
     self.assertTrue(isinstance(ref, Reference))
     self.assertTrue(is_string(ref))
     self.assertEqual("test-component-id", ref)