コード例 #1
0
 def getMultiAdapter(self, objects, interface, name=u''):
     adapter = self.adapters.queryMultiAdapter(objects, interface, name)
     if adapter is None:
         raise ComponentLookupError(objects, interface, name)
     return adapter
コード例 #2
0
ファイル: ObjectManager.py プロジェクト: cpinamtz/Zope
 def getSiteManager(self):
     if self._components is None:
         raise ComponentLookupError('No component registry defined.')
     return self._components
コード例 #3
0
 def getUtility(self, provided, name=u''):
     utility = self.utilities.lookup((), provided, name)
     if utility is None:
         raise ComponentLookupError(provided, name)
     return utility
コード例 #4
0
ファイル: _api.py プロジェクト: SamHesler/AddressSearch
def getAdapterInContext(object, interface, context):
    adapter = queryAdapterInContext(object, interface, context)
    if adapter is None:
        raise ComponentLookupError(object, interface)
    return adapter
コード例 #5
0
ファイル: _api.py プロジェクト: SamHesler/AddressSearch
def getAdapter(object, interface=Interface, name=u'', context=None):
    adapter = queryAdapter(object, interface, name, None, context)
    if adapter is None:
        raise ComponentLookupError(object, interface, name)
    return adapter
コード例 #6
0
ファイル: _api.py プロジェクト: SamHesler/AddressSearch
def getUtility(interface, name='', context=None):
    utility = queryUtility(interface, name, context=context)
    if utility is not None:
        return utility
    raise ComponentLookupError(interface, name)
コード例 #7
0
 def getAdapter(self, object, interface, name=_u('')):
     adapter = self.adapters.queryAdapter(object, interface, name)
     if adapter is None:
         raise ComponentLookupError(object, interface, name)
     return adapter
コード例 #8
0
ファイル: site.py プロジェクト: leanhvu86/matrix-server
 def getSiteManager(self):
     if self._sm is not None:
         return self._sm
     raise ComponentLookupError('no site manager defined')
コード例 #9
0
    def __call__(self):
        mailhost = getToolByName(aq_inner(self.context), 'MailHost')
        if not mailhost:
            raise ComponentLookupError(
                'You must have a Mailhost utility to execute this action'
            )

        email_charset = self.mail_settings.email_charset
        obj = self.event.object
        interpolator = IStringInterpolator(obj)
        source = self.element.source

        if source:
            source = interpolator(source).strip()

        if not source:
            # no source provided, looking for the site wide from email
            # address
            from_address = self.mail_settings.email_from_address
            if not from_address:
                # the mail can't be sent. Try to inform the user
                request = getRequest()
                if request:
                    messages = IStatusMessage(request)
                    msg = _(
                        u'Error sending email from content rule. You must '
                        u'provide a source address for mail '
                        u'actions or enter an email in the portal properties'
                    )
                    messages.add(msg, type=u'error')
                return False

            from_name = self.mail_settings.email_from_name.strip('"')
            if six.PY2 and isinstance(from_name, six.text_type):
                from_name = from_name.encode('utf8')
            source = '"{0}" <{1}>'.format(from_name, from_address)

        recip_string = interpolator(self.element.recipients)
        if recip_string:  # check recipient is not None or empty string
            recipients = set([
                str(mail.strip()) for mail in recip_string.split(',')
                if mail.strip()
            ])
        else:
            recipients = set()

        if self.element.exclude_actor:
            mtool = getToolByName(aq_inner(self.context), 'portal_membership')
            actor_email = mtool.getAuthenticatedMember().getProperty(
                'email',
                ''
            )
            if actor_email in recipients:
                recipients.remove(actor_email)

        # prepend interpolated message with \n to avoid interpretation
        # of first line as header
        message = u'\n{0}'.format(interpolator(self.element.message))

        subject = interpolator(self.element.subject)

        for email_recipient in recipients:
            try:
                # XXX: We're using "immediate=True" because otherwise we won't
                # be able to catch SMTPException as the smtp connection is made
                # as part of the transaction apparatus.
                # AlecM thinks this wouldn't be a problem if mail queuing was
                # always on -- but it isn't. (stevem)
                # so we test if queue is not on to set immediate
                mailhost.send(message, email_recipient, source,
                              subject=subject, charset=email_charset,
                              immediate=not mailhost.smtp_queue)
            except (MailHostError, SMTPException):
                logger.exception(
                    'mail error: Attempt to send mail in content rule failed'
                )

        return True
コード例 #10
0
 def _adapter_hook(interface, object, name, default):
     _called.append((interface, object, name, default))
     raise ComponentLookupError('testing')