Example #1
0
    def test_smart_str(self):
        self.assertTrue(encoding.safe_str(object()))
        self.assertTrue(encoding.safe_str("foo"))
        self.assertTrue(encoding.safe_str(u"foo"))

        class foo(unicode):
            def encode(self, *args, **kwargs):
                raise UnicodeDecodeError("foo")

        self.assertIn("<Unrepresentable", encoding.safe_str(foo()))
    def test_smart_str(self):
        self.assertTrue(encoding.safe_str(object()))
        self.assertTrue(encoding.safe_str("foo"))
        self.assertTrue(encoding.safe_str(u"foo"))

        class foo(unicode):

            def encode(self, *args, **kwargs):
                raise UnicodeDecodeError("foo")

        self.assertIn("<Unrepresentable", encoding.safe_str(foo()))
Example #3
0
File: job.py Project: tobych/celery
    def on_failure(self, exc_info):
        """Handler called if the task raised an exception."""
        state.task_ready(self)

        if self.task.acks_late:
            self.acknowledge()

        if isinstance(exc_info.exception, RetryTaskError):
            return self.on_retry(exc_info)

        # This is a special case as the process would not have had
        # time to write the result.
        if isinstance(exc_info.exception, WorkerLostError):
            if self._store_errors:
                self.task.backend.mark_as_failure(self.task_id,
                                                  exc_info.exception)

        self.send_event("task-failed",
                        uuid=self.task_id,
                        exception=safe_repr(exc_info.exception),
                        traceback=safe_str(exc_info.traceback))

        context = {
            "hostname": self.hostname,
            "id": self.task_id,
            "name": self.task_name,
            "exc": safe_repr(exc_info.exception),
            "traceback": safe_str(exc_info.traceback),
            "args": self.args,
            "kwargs": self.kwargs
        }

        log_with_extra(self.logger,
                       logging.ERROR,
                       self.error_msg.strip() % context,
                       exc_info=exc_info,
                       extra={
                           "data": {
                               "hostname": self.hostname,
                               "id": self.task_id,
                               "name": self.task_name
                           }
                       })

        task_obj = tasks.get(self.task_name, object)
        self.send_error_email(task_obj,
                              context,
                              exc_info.exception,
                              enabled=task_obj.send_error_emails,
                              whitelist=task_obj.error_whitelist)
Example #4
0
 def __repr__(self):
     return '<ModelEntry: {0} {1}(*{2}, **{3}) {{4}}>'.format(
         safe_str(self.name),
         self.task,
         safe_repr(self.args),
         safe_repr(self.kwargs),
         self.schedule,
     )
Example #5
0
 def __repr__(self):
     return "<ModelEntry: %s %s(*%s, **%s) {%s}>" % (
         safe_str(self.name),
         self.task,
         safe_repr(self.args),
         safe_repr(self.kwargs),
         self.schedule,
     )
    def test_safe_str_UnicodeDecodeError(self):
        if sys.version_info >= (3, 0):
            raise SkipTest("py3k: not relevant")

        class foo(unicode):
            def encode(self, *args, **kwargs):
                raise UnicodeDecodeError("foo")

        self.assertIn("<Unrepresentable", encoding.safe_str(foo()))
Example #7
0
    def test_safe_str_UnicodeDecodeError(self):
        if sys.version_info >= (3, 0):
            raise SkipTest('py3k: not relevant')

        class foo(unicode):
            def encode(self, *args, **kwargs):
                raise UnicodeDecodeError('foo')

        self.assertIn('<Unrepresentable', encoding.safe_str(foo()))
Example #8
0
    def test_safe_str_UnicodeDecodeError(self):
        if sys.version_info >= (3, 0):
            raise SkipTest('py3k: not relevant')

        class foo(string):

            def encode(self, *args, **kwargs):
                raise UnicodeDecodeError('foo')

        self.assertIn('<Unrepresentable', encoding.safe_str(foo()))
Example #9
0
    def format(self, record):
        levelname = record.levelname
        color = self.colors.get(levelname)

        if self.use_color and color:
            try:
                record.msg = str(color(safe_str(record.msg)))
            except Exception, exc:
                record.msg = "<Unrepresentable %r: %r>" % (type(record.msg), exc)
                record.exc_info = sys.exc_info()
Example #10
0
    def on_retry(self, exc_info):
        """Handler called if the task should be retried."""
        self.send_event("task-retried", uuid=self.task_id,
                         exception=safe_repr(exc_info.exception.exc),
                         traceback=safe_str(exc_info.traceback))

        self.logger.info(self.retry_msg.strip() % {
                            "id": self.task_id,
                            "name": self.task_name,
                            "exc": safe_repr(exc_info.exception.exc)})
Example #11
0
File: log.py Project: WoLpH/celery
    def format(self, record):
        levelname = record.levelname
        color = self.colors.get(levelname)

        if self.use_color and color:
            try:
                record.msg = str(color(safe_str(record.msg)))
            except Exception, exc:
                record.msg = "<Unrepresentable %r: %r>" % (type(
                    record.msg), exc)
                record.exc_info = sys.exc_info()
Example #12
0
File: job.py Project: brainy/celery
    def on_failure(self, exc_info):
        """Handler called if the task raised an exception."""
        state.task_ready(self)

        if self.task.acks_late:
            self.acknowledge()

        if isinstance(exc_info.exception, RetryTaskError):
            return self.on_retry(exc_info)

        # This is a special case as the process would not have had
        # time to write the result.
        if isinstance(exc_info.exception, WorkerLostError):
            if self._store_errors:
                self.task.backend.mark_as_failure(self.task_id,
                                                  exc_info.exception)

        self.send_event("task-failed", uuid=self.task_id,
                         exception=safe_repr(exc_info.exception),
                         traceback=safe_str(exc_info.traceback))

        context = {"hostname": self.hostname,
                   "id": self.task_id,
                   "name": self.task_name,
                   "exc": safe_repr(exc_info.exception),
                   "traceback": safe_str(exc_info.traceback),
                   "args": self.args,
                   "kwargs": self.kwargs}

        log_with_extra(self.logger, logging.ERROR,
                       self.error_msg.strip() % context,
                       exc_info=exc_info,
                       extra={"data": {"hostname": self.hostname,
                                       "id": self.task_id,
                                       "name": self.task_name}})

        task_obj = tasks.get(self.task_name, object)
        self.send_error_email(task_obj, context, exc_info.exception,
                              enabled=task_obj.send_error_emails,
                              whitelist=task_obj.error_whitelist)
Example #13
0
    def on_retry(self, exc_info):
        """Handler called if the task should be retried."""
        self.send_event("task-retried",
                        uuid=self.task_id,
                        exception=safe_repr(exc_info.exception.exc),
                        traceback=safe_str(exc_info.traceback))

        self.logger.info(
            self.retry_msg.strip() % {
                "id": self.task_id,
                "name": self.task_name,
                "exc": safe_repr(exc_info.exception.exc)
            })
Example #14
0
    def format(self, record):
        levelname = record.levelname
        color = self.colors.get(levelname)

        if self.use_color and color:
            try:
                record.msg = color(safe_str(record.msg))
            except Exception:
                record.msg = "<Unrepresentable %r: %r>" % (
                        type(record.msg), traceback.format_stack())

        # Very ugly, but have to make sure processName is supported
        # by foreign logger instances.
        # (processName is always supported by Python 2.7)
        if "processName" not in record.__dict__:
            process_name = current_process and current_process()._name or ""
            record.__dict__["processName"] = process_name
        t = logging.Formatter.format(self, record)
        if isinstance(t, unicode):
            return t.encode("utf-8", "replace")
        return t
Example #15
0
    def format(self, record):
        levelname = record.levelname
        color = self.colors.get(levelname)

        if self.use_color and color:
            try:
                record.msg = color(safe_str(record.msg))
            except Exception:
                record.msg = "<Unrepresentable %r: %r>" % (
                        type(record.msg), traceback.format_stack())

        # Very ugly, but have to make sure processName is supported
        # by foreign logger instances.
        # (processName is always supported by Python 2.7)
        if "processName" not in record.__dict__:
            process_name = current_process and current_process()._name or ""
            record.__dict__["processName"] = process_name
        t = logging.Formatter.format(self, record)
        if isinstance(t, unicode):
            return t.encode("utf-8", "replace")
        return t
Example #16
0
 def test_safe_str(self):
     self.assertTrue(encoding.safe_str(object()))
     self.assertTrue(encoding.safe_str('foo'))
     self.assertTrue(encoding.safe_str(u'foo'))
Example #17
0
 def __repr__(self):
     return '<ModelEntry: {0} {1}(*{2}, **{3}) {4}>'.format(
         safe_str(self.name), self.task, safe_repr(self.args),
         safe_repr(self.kwargs), self.schedule,
     )
 def test_safe_str(self):
     assert encoding.safe_str(object())
     assert encoding.safe_str('foo')
Example #19
0
 def test_safe_str(self):
     self.assertTrue(encoding.safe_str(object()))
     self.assertTrue(encoding.safe_str('foo'))
Example #20
0
 def __repr__(self):
     return '<ModelEntry: %s %s(*%s, **%s) {%s}>' % (safe_str(
         self.name), self.task, safe_repr(self.args), safe_repr(
             self.kwargs), self.schedule)
 def test_safe_str(self):
     self.assertTrue(encoding.safe_str(object()))
     self.assertTrue(encoding.safe_str("foo"))
     self.assertTrue(encoding.safe_str(u"foo"))
Example #22
0
def shsplit(s):
    if s:
        return shlex.split(safe_str(s))
    return []
Example #23
0
File: __init__.py Project: ask/cyme
def shsplit(s):
    if s:
        return shlex.split(safe_str(s))
    return []
Example #24
0
 def test_safe_str(self):
     assert encoding.safe_str(object())
     assert encoding.safe_str('foo')