Exemplo n.º 1
0
 def _smtp_send(self, from_, to, contents):
     smtp = smtplib.SMTP(self.host, self.port)
     try:
         smtp.sendmail(from_, to, contents)
     except Exception as e:
         log.exception(e)
     finally:
         smtp.close()
Exemplo n.º 2
0
Arquivo: mail.py Projeto: bcroq/kansha
 def _smtp_send(self, from_, to, contents):
     smtp = smtplib.SMTP(self.host, self.port)
     try:
         smtp.sendmail(from_, to, contents)
     except Exception as e:
         log.exception(e)
     finally:
         smtp.close()
Exemplo n.º 3
0
    def on_callback_lookuperror(self, request, response, async):
        """A callback was not found

        In:
          - ``request`` -- the web request object
          - ``response`` -- the web response object
          - ``async`` -- is an XHR request ?
        """
        log.exception("\n%s" % request)
        if self.debug:
            raise
Exemplo n.º 4
0
    def on_callback_lookuperror(self, request, response, async):
        """A callback was not found

        In:
          - ``request`` -- the web request object
          - ``response`` -- the web response object
          - ``async`` -- is an XHR request ?
        """
        log.exception("\n%s" % request)
        if self.debug:
            raise
Exemplo n.º 5
0
 def _smtp_send(self, from_, to, contents):
     try:
         smtp = smtplib.SMTP(self.host, self.port)
     except IOError as e:
         log.exception(e)
         return False
     try:
         smtp.sendmail(from_, to, contents)
     except Exception as e:
         log.exception(e)
         return False
     finally:
         smtp.close()
     return True
Exemplo n.º 6
0
    def _validate_thumbnail(self, f):
        if is_string(f):
            return None

        if f.done == -1:
            raise ValueError(_(u'Transfer was interrupted'))

        # finds out the filename (I.E. 4 returns the on-disk path)
        self.thumbnail_filename = f.filename.split('\\')[-1]

        try:
            return tools.create_thumbnail(f.file, 870, 271)
        except IOError as e:
            errno, strerror = e
            log.exception('thumbnail reception error: %s', strerror)
            raise IOError(errno, _(u'Reception error'))
Exemplo n.º 7
0
    def _validate_thumbnail(self, f):
        if is_string(f):
            return None

        if f.done == -1:
            raise ValueError(_(u'Transfer was interrupted'))

        # finds out the filename (I.E. 4 returns the on-disk path)
        self.thumbnail_filename = f.filename.split('\\')[-1]

        try:
            return tools.create_thumbnail(f.file, 870, 271)
        except IOError as e:
            errno, strerror = e
            log.exception('thumbnail reception error: %s', strerror)
            raise IOError(errno, _(u'Reception error'))
Exemplo n.º 8
0
 def on_exception(self, request, response):
     exc_class, e = sys.exc_info()[:2]
     for k, v in request.POST.items():
         if isinstance(v, cgi.FieldStorage):
             request.POST[k] = u'Content not displayed'
     log.exception(e)
     response.headers['Content-Type'] = 'text/html'
     package = pkg_resources.Requirement.parse('kansha')
     error = pkg_resources.resource_string(package,
                                           'static/html/error.html')
     error = unicode(error, 'utf8')
     response.charset = 'utf8'
     data = {
         'text': u'',
         'status': 200,
         'go_back': _(u'Go back'),
         'app_title': self.app_title,
         'theme': self.theme
     }
     if exc_class == Unauthorized:
         status = 403
         text = _(u"You are not authorized to access this board")
     elif exc_class == exceptions.BoardNotFound:
         status = 404
         text = _(u"This board doesn't exists")
     elif exc_class == exceptions.NotFound:
         status = 404
         text = _(u"Page not found")
     elif exc_class == exceptions.KanshaException:
         status = 500
         text = _(unicode(e.message))
     else:
         status = 500
         text = _(u"Unable to proceed. Please contact us.")
     # Raise exception if debug
     if self.debug:
         raise
     data['status'] = status
     data['text'] = text
     response.status = status
     if request.is_xhr:
         response.body = json.dumps({'details': text, 'status': status})
     else:
         response.text = error % data
     return response
Exemplo n.º 9
0
 def on_exception(self, request, response):
     exc_class, e = sys.exc_info()[:2]
     for k, v in request.POST.items():
         if isinstance(v, cgi.FieldStorage):
             request.POST[k] = u'Content not displayed'
     log.exception(e)
     response.headers['Content-Type'] = 'text/html'
     package = pkg_resources.Requirement.parse('kansha')
     error = pkg_resources.resource_string(
         package, 'static/html/error.html')
     error = unicode(error, 'utf8')
     response.charset = 'utf8'
     data = {'text': u'', 'status': 200,
             'go_back': _(u'Go back'),
             'app_title': self.app_title,
             'theme': self.theme}
     if exc_class == Unauthorized:
         status = 403
         text = _(u"You are not authorized to access this board")
     elif exc_class == exceptions.BoardNotFound:
         status = 404
         text = _(u"This board doesn't exists")
     elif exc_class == exceptions.NotFound:
         status = 404
         text = _(u"Page not found")
     elif exc_class == exceptions.KanshaException:
         status = 500
         text = _(unicode(e.message))
     else:
         status = 500
         text = _(u"Unable to proceed. Please contact us.")
     # Raise exception if debug
     if self.debug:
         raise
     data['status'] = status
     data['text'] = text
     response.status = status
     if request.is_xhr:
         response.body = json.dumps({'details': text, 'status': status})
     else:
         response.text = error % data
     return response