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 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)
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 __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()))
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()))
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()))
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()
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)})
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()
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)
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) })
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
def test_safe_str(self): self.assertTrue(encoding.safe_str(object())) self.assertTrue(encoding.safe_str('foo')) self.assertTrue(encoding.safe_str(u'foo'))
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')
def test_safe_str(self): self.assertTrue(encoding.safe_str(object())) self.assertTrue(encoding.safe_str('foo'))
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"))
def shsplit(s): if s: return shlex.split(safe_str(s)) return []