def test_is_namespace(self): """ `is_namespace` returns ``True`` only for namespaced names. """ self.assertThat(is_namespace(42), Is(False)) self.assertThat(is_namespace((u'foo', u'bar')), Is(False)) self.assertThat(is_namespace(namespaced(u'foo')), Is(False)) self.assertThat(is_namespace(namespaced(u'foo')(u'bar')), Is(True))
def get_name(task): if isinstance(task, text_type): return escape_control_characters(task) elif isinstance(task, tuple): key = task[0] if is_namespace(key): key = key.name name = escape_control_characters(key) if isinstance(task[1], dict): return name elif isinstance(task[1], text_type): return u'{}: {}'.format( colors.prop(name), # No need to escape this because we assume the value # formatter did that already. task[1]) else: return colors.root(name) else: name = escape_control_characters(task.name) if task.success is True: return colors.success(name) elif task.success is False: return colors.failure(name) return name
def format_node(format_value, theme, node): """ Format a node for display purposes. Different representations exist for the various types of node: - `eliot.parse.Task`: A task UUID. - `eliot.parse.WrittenAction`: An action's type, level and status. - `eliot.parse.WrittenMessage`: A message's type and level. - ``tuple``: A field name and value. """ if isinstance(node, Task): return u'{}'.format( theme.root(format.escape_control_characters( node.root().task_uuid))) elif isinstance(node, WrittenAction): return message_name(theme, format_value, node.start_message, node.end_message) elif isinstance(node, WrittenMessage): return message_name(theme, format_value, node) elif isinstance(node, tuple): key, value = node if isinstance(value, (dict, list)): value = u'' else: value = format_value(value, key) if is_namespace(key): key = format_namespace(key) return u'{}: {}'.format( theme.prop_key(format.escape_control_characters(key)), theme.prop_value(text_type(value))) raise NotImplementedError()
def _sortkey(x): k = x[0] return format_namespace(k) if is_namespace(k) else k