Beispiel #1
0
 def __init__(self, config, prefix=None):
     self.manager, self.Manager = None, None
     self.Transport = None
     self.running = False
     self.config = config = Bunch(config)
     
     if prefix is not None:
         self.config = config = Bunch.partial(prefix, config)
     
     try:
         self.manager_config = manager_config = Bunch.partial('manager', config)
     except ValueError:
         self.manager_config = manager_config = Bunch()
     
     try:
         self.transport_config = transport_config = Bunch.partial('transport', config)
     except ValueError:
         self.transport_config = transport_config = Bunch()
     
     try:
         self.message_config = Bunch.partial('message', config)
     except ValueError:
         self.message_config = Bunch()
     
     self.Manager = Manager = self._load(config.manager, 'marrow.mailer.manager')
     
     if not Manager:
         raise LookupError("Unable to determine manager from specification: %r" % (config.manager, ))
     
     self.Transport = Transport = self._load(config.transport, 'marrow.mailer.transport')
     
     if not Transport:
         raise LookupError("Unable to determine transport from specification: %r" % (config.transport, ))
     
     self.manager = Manager(manager_config, partial(Transport, transport_config))
 def __init__(self, config, prefix=None):
     self.manager, self.Manager = None, None
     self.Transport = None
     self.running = False
     self.config = config = Bunch(config)
     
     if prefix is not None:
         self.config = config = Bunch.partial(prefix, config)
     
     try:
         if 'manager' in config and isinstance(config.manager, dict):
             self.manager_config = manager_config = config.manager
         else:
             self.manager_config = manager_config = Bunch.partial('manager', config)
     except ValueError: # pragma: no cover
         self.manager_config = manager_config = Bunch()
     
     if isinstance(config.manager, basestring):
         warnings.warn("Use of the manager directive is deprecated; use manager.use instead.", DeprecationWarning)
         manager_config.use = config.manager
     
     try:
         if 'transport' in config and isinstance(config.transport, dict):
             self.transport_config = transport_config = Bunch(config.transport)
         else:
             self.transport_config = transport_config = Bunch.partial('transport', config)
     except ValueError: # pragma: no cover
         self.transport_config = transport_config = Bunch()
     
     if isinstance(config.transport, basestring):
         warnings.warn("Use of the transport directive is deprecated; use transport.use instead.", DeprecationWarning)
         transport_config.use = config.transport
     
     try:
         if 'message' in config and isinstance(config.message, dict):
             self.message_config = Bunch(config.message)
         else:
             self.message_config = Bunch.partial('message', config)
     except ValueError: # pragma: no cover
         self.message_config = Bunch()
     
     self.Manager = Manager = self._load(manager_config.use if 'use' in manager_config else 'immediate', 'marrow.mailer.manager')
     
     if not Manager:
         raise LookupError("Unable to determine manager from specification: %r" % (config.manager, ))
     
     if not isinstance(Manager, IManager):
         raise TypeError("Chosen manager does not conform to the manager API.")
     
     self.Transport = Transport = self._load(transport_config.use, 'marrow.mailer.transport')
     
     if not Transport:
         raise LookupError("Unable to determine transport from specification: %r" % (config.transport, ))
     
     if not isinstance(Transport, ITransport):
         raise TypeError("Chosen transport does not conform to the transport API.")
     
     self.manager = Manager(manager_config, partial(Transport, transport_config))
Beispiel #3
0
Datei: form.py Projekt: Acen/core
 def native(self, data):
     from marrow.util.bunch import Bunch
     result = dict()
     
     data = data[self.name] if self.name in data else Bunch.partial(self.name, data)
     
     for child in self.children:
         if isinstance(child, NestedWidget):
             result.update(child.native(Bunch.partial(child.name, data))[0])
             continue
         
         result[child.name] = child.native(data)
     
     return {self.name: result}, dict()
Beispiel #4
0
    def native(self, data):
        from marrow.util.bunch import Bunch
        result = dict()

        data = data[self.name] if self.name in data else Bunch.partial(
            self.name, data)

        for child in self.children:
            if isinstance(child, NestedWidget):
                result.update(child.native(Bunch.partial(child.name, data))[0])
                continue

            result[child.name] = child.native(data)

        return {self.name: result}, dict()
Beispiel #5
0
 def test_partial(self):
     d1 = Bunch({'foo.bar': 1, 'foo.baz': 2, 'diz': 3})
     d2 = Bunch.partial('foo', d1)
     
     self.assertEqual(d2.get('diz', None), None)
     self.assertEqual(d2.baz, 2)
     
     d2.bar = 4
     
     self.assertEqual(d1['foo.bar'], 1)
     self.assertEqual(d1.foo.bar, 1)
     
     self.assertRaises(AttributeError, lambda: d1.bar.foo)
Beispiel #6
0
    def __init__(self, config, prefix=None):
        self.manager, self.Manager = None, None
        self.Transport = None
        self.running = False
        self.config = config = Bunch(config)

        if prefix is not None:
            self.config = config = Bunch.partial(prefix, config)

        try:
            if 'manager' in config and isinstance(config.manager, dict):
                self.manager_config = manager_config = config.manager
            else:
                self.manager_config = manager_config = Bunch.partial(
                    'manager', config)
        except ValueError:  # pragma: no cover
            self.manager_config = manager_config = Bunch()

        if isinstance(config.manager, basestring):
            warnings.warn(
                "Use of the manager directive is deprecated; use manager.use instead.",
                DeprecationWarning)
            manager_config.use = config.manager

        try:
            if 'transport' in config and isinstance(config.transport, dict):
                self.transport_config = transport_config = Bunch(
                    config.transport)
            else:
                self.transport_config = transport_config = Bunch.partial(
                    'transport', config)
        except ValueError:  # pragma: no cover
            self.transport_config = transport_config = Bunch()

        if isinstance(config.transport, basestring):
            warnings.warn(
                "Use of the transport directive is deprecated; use transport.use instead.",
                DeprecationWarning)
            transport_config.use = config.transport

        try:
            if 'message' in config and isinstance(config.message, dict):
                self.message_config = Bunch(config.message)
            else:
                self.message_config = Bunch.partial('message', config)
        except ValueError:  # pragma: no cover
            self.message_config = Bunch()

        self.Manager = Manager = self._load(
            manager_config.use if 'use' in manager_config else 'immediate',
            'marrow.mailer.manager')

        if not Manager:
            raise LookupError(
                "Unable to determine manager from specification: %r" %
                (config.manager, ))

        if not isinstance(Manager, IManager):
            raise TypeError(
                "Chosen manager does not conform to the manager API.")

        self.Transport = Transport = self._load(transport_config.use,
                                                'marrow.mailer.transport')

        if not Transport:
            raise LookupError(
                "Unable to determine transport from specification: %r" %
                (config.transport, ))

        if not isinstance(Transport, ITransport):
            raise TypeError(
                "Chosen transport does not conform to the transport API.")

        self.manager = Manager(manager_config,
                               partial(Transport, transport_config))