Format: application/x-python-code
1 o
2
3 ��h�� � @ sx d Z ddlZddlZddlZddlZddlmZ ddlmZ ddlm Z ddl
4 mZ dd lm
5 Z
6 dd
7 lmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZ dd
8 lmZ G dd� de �Zdd� Z G dd� de!�Z"edd� �Z#G dd� dej$d�Z%dd� Z&dd� Z'e
9 de(d�Z)G dd � d e �Z*G d!d"� d"e*�Z+G d#d$� d$e*�Z,G d%d&� d&e*�Z-G d'd(� d(e*�Z.G d)d*� d*e*�Z/G d+d,� d,e*�Z0G d-d.� d.e*�Z1G d/d0� d0e*�Z2G d1d2� d2e*�Z3G d3d4� d4e*�Z4G d5d6� d6e*�Z5G d7d8� d8e*�Z6e%�7e*� e%�7e+� e%�7e,� e%�7e-� e%�7e.� e%�7e/� e%�7e4� e%�7e0� e%�7e1� e%�7e2� e%�7e3� e%�7e5� e%�7e6� d;d9d:�Z8dS )<a� Display formatters.
10
11 This module defines the base instances in order to implement custom
12 formatters/mimetypes
13 got objects:
14
15 As we want to see internal IPython working we are going to use the following
16 function to diaply objects instead of the normal print or display method:
17
18 >>> ip = get_ipython()
19 >>> ip.display_formatter.format(...)
20 ({'text/plain': 'Ellipsis'}, {})
21
22 This return a tuple with the mimebumdle for the current object, and the
23 associated metadata.
24
25
26 We can now define our own formatter and register it:
27
28
29 >>> from IPython.core.formatters import BaseFormatter, FormatterABC
30
31
32 >>> class LLMFormatter(BaseFormatter):
33 ...
34 ... format_type = 'x-vendor/llm'
35 ... print_method = '_repr_llm_'
36 ... _return_type = (dict, str)
37
38 >>> llm_formatter = LLMFormatter(parent=ip.display_formatter)
39
40 >>> ip.display_formatter.formatters[LLMFormatter.format_type] = llm_formatter
41
42 Now any class that define `_repr_llm_` will return a x-vendor/llm as part of
43 it's display data:
44
45 >>> class A:
46 ...
47 ... def _repr_llm_(self, *kwargs):
48 ... return 'This a A'
49 ...
50
51 >>> ip.display_formatter.format(A())
52 ({'text/plain': '<IPython.core.formatters.A at ...>', 'x-vendor/llm': 'This a A'}, {})
53
54 As usual, you can register methods for third party types (see
55 :ref:`third_party_formatting`)
56
57 >>> def llm_int(obj):
58 ... return 'This is the integer %s, in between %s and %s'%(obj, obj-1, obj+1)
59
60 >>> llm_formatter.for_type(int, llm_int)
61
62 >>> ip.display_formatter.format(42)
63 ({'text/plain': '42', 'x-vendor/llm': 'This is the integer 42, in between 41 and 43'}, {})
64
65
66 Inheritance diagram:
67
68 .. inheritance-diagram:: IPython.core.formatters
69 :parts: 3
70 � N)�StringIO)� decorator)�Configurable� )�get_ipython� )�Sentinel)�get_real_method)�pretty)
71 �Bool�Dict�Integer�Unicode�CUnicode�
72 ObjectName�List�ForwardDeclaredInstance�default�observe)�Anyc @ s� e Zd Zee� dd�jdd�Zed�dd� �Ze d�dd � �Z
73 ed
74 �Zed�dd
75 � �Z
76 ed
77 �Zed�dd� �Ze� Zed�dd� �Zddd�Zedd� �ZdS )�DisplayFormatterz�List of currently active mime-types to display.
78 You can use this to set a white-list for formats to display.
79
80 Most users will not need to change this value.
81 ��helpT��config�active_typesc C s | j S �N)�format_types��self� r �Mc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/formatters.py�_active_types_defaultd s z&DisplayFormatter._active_types_defaultc C s2 | j �� D ]\}}||d v rd|_qd|_qd S )N�newTF)�
82 formatters�items�enabled)r �change�key� formatterr r r! �_active_types_changedh s
83 �z&DisplayFormatter._active_types_changed�FormatterABC�ipython_display_formatterc C �
84 t | d�S �N��parent)�IPythonDisplayFormatterr r r r! �_default_formatterr �
85 z#DisplayFormatter._default_formatter�mimebundle_formatterc C r- r. )�MimeBundleFormatterr r r r! �_default_mime_formatterx r3 z(DisplayFormatter._default_mime_formatterr$ c
86 C s>