pyhttp-app 2.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,93 @@
1
+ Copyright 2016 The Inter Project Authors (https://github.com/rsms/inter)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,434 @@
1
+ 'use strict';
2
+ // Response viewer: Pretty (collapsible JSON tree / coloured XML), Raw, Preview,
3
+ // wrap toggle, expand/collapse, JSON path filter and in-body search.
4
+ // mountViewer(container, resp, opts) renders into any element.
5
+
6
+ const VIEWER_MAX_TREE = 2_000_000; // chars: above this, Pretty shows plain text
7
+ const VIEWER_INITIAL_DEPTH = 3;
8
+ const VIEWER_NODE_BUDGET = 3000; // nodes rendered before deeper levels start collapsed
9
+
10
+ function detectLang(resp) {
11
+ const ct = (resp && resp.content_type || '').toLowerCase();
12
+ if (resp && resp.is_json) return 'json';
13
+ if (ct.includes('html')) return 'html';
14
+ if (ct.includes('xml')) return 'xml';
15
+ if (ct.includes('json')) return 'json';
16
+ const t = (resp && resp.body_text || '').trimStart();
17
+ if (t.startsWith('{') || t.startsWith('[')) { try { JSON.parse(t); return 'json'; } catch { /* no */ } }
18
+ if (t.startsWith('<!DOCTYPE html') || t.startsWith('<html')) return 'html';
19
+ if (t.startsWith('<?xml') || t.startsWith('<')) return 'xml';
20
+ return 'text';
21
+ }
22
+
23
+ // ------------------------------------------------------------- JSON path
24
+ // Dotted path with [index], [*] and * wildcards: data.items[0].name, data.items[*].id, *.name
25
+ function jsonPathGet(value, path) {
26
+ const p = (path || '').trim().replace(/^\$\.?/, '');
27
+ if (!p) return { ok: true, value };
28
+ const segs = [];
29
+ p.split('.').forEach((seg) => {
30
+ const m = /^([^[\]]*)((?:\[[^\]]*\])*)$/.exec(seg);
31
+ if (!m) { segs.push({ key: seg }); return; }
32
+ if (m[1]) segs.push({ key: m[1] });
33
+ (m[2].match(/\[[^\]]*\]/g) || []).forEach((b) => segs.push({ idx: b.slice(1, -1).trim() }));
34
+ });
35
+ let current = [value];
36
+ for (const s of segs) {
37
+ const next = [];
38
+ for (const v of current) {
39
+ if (s.key !== undefined) {
40
+ if (s.key === '*') { if (Array.isArray(v)) next.push(...v); else if (v && typeof v === 'object') next.push(...Object.values(v)); }
41
+ else if (v && typeof v === 'object' && !Array.isArray(v) && Object.prototype.hasOwnProperty.call(v, s.key)) next.push(v[s.key]);
42
+ else if (v && typeof v === 'object' && !Array.isArray(v)) {
43
+ const k = Object.keys(v).find((x) => x.toLowerCase() === s.key.toLowerCase());
44
+ if (k !== undefined) next.push(v[k]);
45
+ }
46
+ } else {
47
+ if (s.idx === '*' || s.idx === '') { if (Array.isArray(v)) next.push(...v); }
48
+ else if (Array.isArray(v) && /^-?\d+$/.test(s.idx)) { const i = Number(s.idx) < 0 ? v.length + Number(s.idx) : Number(s.idx); if (v[i] !== undefined) next.push(v[i]); }
49
+ else if (v && typeof v === 'object' && s.idx.replace(/^["']|["']$/g, '') in v) next.push(v[s.idx.replace(/^["']|["']$/g, '')]);
50
+ }
51
+ }
52
+ current = next;
53
+ if (!current.length) return { ok: false };
54
+ }
55
+ const wild = segs.some((s) => s.key === '*' || s.idx === '*' || s.idx === '');
56
+ return { ok: true, value: wild ? current : current[0] };
57
+ }
58
+
59
+ // --------------------------------------------------------------- JSON tree
60
+ function jsonTree(root, opts = {}) {
61
+ const box = document.createElement('div');
62
+ box.className = 'jv';
63
+ let rendered = 0;
64
+ const onPath = opts.onPath || null;
65
+
66
+ const typeOf = (v) => v === null ? 'null' : Array.isArray(v) ? 'array' : typeof v;
67
+ const isUrl = (s) => /^https?:\/\/\S+$/i.test(s) && s.length < 2000;
68
+
69
+ function primitive(v) {
70
+ const t = typeOf(v);
71
+ const span = document.createElement('span');
72
+ if (t === 'string') {
73
+ span.className = 'jv-s';
74
+ const text = JSON.stringify(v);
75
+ if (isUrl(v)) {
76
+ const a = document.createElement('a');
77
+ a.href = v; a.target = '_blank'; a.rel = 'noopener'; a.textContent = text;
78
+ span.appendChild(a);
79
+ } else span.textContent = text;
80
+ } else if (t === 'number') { span.className = 'jv-n'; span.textContent = String(v); }
81
+ else if (t === 'boolean') { span.className = 'jv-b'; span.textContent = String(v); }
82
+ else { span.className = 'jv-null'; span.textContent = 'null'; }
83
+ return span;
84
+ }
85
+
86
+ function node(key, value, path, depth, last) {
87
+ const el = document.createElement('div');
88
+ el.className = 'jv-node';
89
+ el.dataset.path = path;
90
+ rendered++;
91
+ const line = document.createElement('div');
92
+ line.className = 'jv-line';
93
+ const t = typeOf(value);
94
+ const container = t === 'object' || t === 'array';
95
+ if (container) {
96
+ const tg = document.createElement('span');
97
+ tg.className = 'jv-toggle';
98
+ tg.textContent = '▾';
99
+ line.appendChild(tg);
100
+ } else {
101
+ const sp = document.createElement('span');
102
+ sp.className = 'jv-toggle blank';
103
+ line.appendChild(sp);
104
+ }
105
+ if (key !== null) {
106
+ const k = document.createElement('span');
107
+ k.className = 'jv-k';
108
+ k.textContent = typeof key === 'number' ? String(key) : JSON.stringify(key);
109
+ if (typeof key === 'number') k.classList.add('idx');
110
+ k.title = 'Click to copy the path ' + path;
111
+ k.addEventListener('click', (e) => { e.stopPropagation(); if (onPath) onPath(path); });
112
+ line.appendChild(k);
113
+ line.appendChild(document.createTextNode(': '));
114
+ }
115
+ if (container) {
116
+ const entries = t === 'array' ? value.map((v, i) => [i, v]) : Object.entries(value);
117
+ const open = document.createElement('span');
118
+ open.className = 'jv-p';
119
+ open.textContent = t === 'array' ? '[' : '{';
120
+ line.appendChild(open);
121
+ const summary = document.createElement('span');
122
+ summary.className = 'jv-summary';
123
+ summary.textContent = entries.length === 0 ? '' : t === 'array' ? `${entries.length} item${entries.length === 1 ? '' : 's'}` : `${entries.length} key${entries.length === 1 ? '' : 's'}`;
124
+ line.appendChild(summary);
125
+ const closeInline = document.createElement('span');
126
+ closeInline.className = 'jv-p jv-close-inline';
127
+ closeInline.textContent = (t === 'array' ? ']' : '}') + (last ? '' : ',');
128
+ line.appendChild(closeInline);
129
+ el.appendChild(line);
130
+ if (entries.length === 0) {
131
+ el.classList.add('leaf');
132
+ summary.remove();
133
+ $('.jv-toggle', line).className = 'jv-toggle blank';
134
+ } else {
135
+ const kids = document.createElement('div');
136
+ kids.className = 'jv-children';
137
+ el.appendChild(kids);
138
+ const close = document.createElement('div');
139
+ close.className = 'jv-closing';
140
+ close.innerHTML = `<span class="jv-toggle blank"></span><span class="jv-p">${t === 'array' ? ']' : '}'}${last ? '' : ','}</span>`;
141
+ el.appendChild(close);
142
+ el._entries = entries;
143
+ el._path = path;
144
+ el._depth = depth;
145
+ el._type = t;
146
+ const expandNow = depth < VIEWER_INITIAL_DEPTH && rendered < VIEWER_NODE_BUDGET;
147
+ if (expandNow) expand(el); else el.classList.add('collapsed');
148
+ line.addEventListener('click', (e) => {
149
+ if (e.target.closest('.jv-k, a')) return;
150
+ toggle(el);
151
+ });
152
+ }
153
+ } else {
154
+ line.appendChild(primitive(value));
155
+ if (!last) line.appendChild(document.createTextNode(','));
156
+ el.appendChild(line);
157
+ el.classList.add('leaf');
158
+ }
159
+ return el;
160
+ }
161
+ function expand(el) {
162
+ const kids = $('.jv-children', el);
163
+ if (!kids) return;
164
+ if (!el._rendered) {
165
+ el._rendered = true;
166
+ const frag = document.createDocumentFragment();
167
+ const entries = el._entries;
168
+ entries.forEach(([k, v], i) => {
169
+ const childPath = el._type === 'array' ? `${el._path}[${k}]` : (el._path ? `${el._path}.${k}` : String(k));
170
+ frag.appendChild(node(k, v, childPath, el._depth + 1, i === entries.length - 1));
171
+ });
172
+ kids.appendChild(frag);
173
+ }
174
+ el.classList.remove('collapsed');
175
+ }
176
+ function toggle(el) { if (el.classList.contains('collapsed')) expand(el); else el.classList.add('collapsed'); }
177
+ function expandAll(limit = 60000) {
178
+ rendered = 0;
179
+ let guard = 0;
180
+ const walk = (el) => {
181
+ if (guard++ > limit) return;
182
+ if (el._entries) { expand(el); $$(':scope > .jv-children > .jv-node', el).forEach(walk); }
183
+ };
184
+ $$(':scope > .jv-node', box).forEach(walk);
185
+ return guard <= limit;
186
+ }
187
+ function collapseAll() {
188
+ $$('.jv-node', box).forEach((el) => { if (el._entries && el._depth > 0) el.classList.add('collapsed'); });
189
+ }
190
+ box.appendChild(node(null, root, '', 0, true));
191
+ box._expandAll = expandAll;
192
+ box._collapseAll = collapseAll;
193
+ return box;
194
+ }
195
+
196
+ // ------------------------------------------------------------ XML / HTML
197
+ function highlightXml(text) {
198
+ const out = [];
199
+ const re = /(<!--[\s\S]*?-->)|(<!\[CDATA\[[\s\S]*?\]\]>)|(<\?[\s\S]*?\?>)|(<!DOCTYPE[^>]*>)|(<\/?)([A-Za-z][\w:.-]*)([^>]*?)(\/?>)/g;
200
+ let last = 0, m;
201
+ while ((m = re.exec(text))) {
202
+ out.push(esc(text.slice(last, m.index)));
203
+ last = re.lastIndex;
204
+ if (m[1]) out.push(`<span class="x-c">${esc(m[1])}</span>`);
205
+ else if (m[2]) out.push(`<span class="x-d">${esc(m[2])}</span>`);
206
+ else if (m[3] || m[4]) out.push(`<span class="x-pi">${esc(m[3] || m[4])}</span>`);
207
+ else {
208
+ const attrs = m[7].replace(/([^\s=]+)(\s*=\s*)("[^"]*"|'[^']*'|[^\s"']+)?/g, (a, n, eq, v) =>
209
+ `<span class="x-a">${esc(n)}</span>${eq ? esc(eq) : ''}${v ? `<span class="x-v">${esc(v)}</span>` : ''}`);
210
+ out.push(`<span class="x-p">${esc(m[5])}</span><span class="x-t">${esc(m[6])}</span>${attrs}<span class="x-p">${esc(m[8])}</span>`);
211
+ }
212
+ }
213
+ out.push(esc(text.slice(last)));
214
+ return out.join('');
215
+ }
216
+
217
+ // ------------------------------------------------------------------ search
218
+ function clearMarks(root) {
219
+ $$('mark.rv-m', root).forEach((m) => {
220
+ const parent = m.parentNode;
221
+ parent.replaceChild(document.createTextNode(m.textContent), m);
222
+ parent.normalize();
223
+ });
224
+ }
225
+ function markMatches(root, query) {
226
+ clearMarks(root);
227
+ if (!query) return [];
228
+ const q = query.toLowerCase();
229
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
230
+ acceptNode: (n) => n.nodeValue.toLowerCase().includes(q) && !n.parentNode.closest('.rv-bar') ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP,
231
+ });
232
+ const nodes = [];
233
+ let n;
234
+ while ((n = walker.nextNode())) nodes.push(n);
235
+ const marks = [];
236
+ nodes.forEach((textNode) => {
237
+ const text = textNode.nodeValue;
238
+ const frag = document.createDocumentFragment();
239
+ let i = 0, idx;
240
+ const lower = text.toLowerCase();
241
+ while ((idx = lower.indexOf(q, i)) !== -1) {
242
+ if (idx > i) frag.appendChild(document.createTextNode(text.slice(i, idx)));
243
+ const mark = document.createElement('mark');
244
+ mark.className = 'rv-m';
245
+ mark.textContent = text.slice(idx, idx + q.length);
246
+ frag.appendChild(mark);
247
+ marks.push(mark);
248
+ i = idx + q.length;
249
+ }
250
+ if (i < text.length) frag.appendChild(document.createTextNode(text.slice(i)));
251
+ textNode.parentNode.replaceChild(frag, textNode);
252
+ });
253
+ return marks;
254
+ }
255
+
256
+ // ---------------------------------------------------------------- viewer
257
+ function mountViewer(container, resp, opts = {}) {
258
+ container.innerHTML = '';
259
+ container.classList.add('rv');
260
+ const text = resp ? (resp.body_text || '') : '';
261
+ const lang = detectLang(resp);
262
+ const state = { view: opts.view || (lang === 'text' && !resp.body_base64 ? 'raw' : 'pretty'), wrap: opts.wrap !== false, filter: '', q: '', marks: [], cur: -1, json: undefined, filtered: null };
263
+ container._viewerState = state;
264
+ container._viewerText = () => text;
265
+ const huge = text.length > VIEWER_MAX_TREE;
266
+ const ct = (resp && resp.content_type || '').toLowerCase();
267
+ const previewable = /html/.test(ct) || (resp && resp.is_binary && (ct.startsWith('image/') || ct === 'application/pdf')) || lang === 'html';
268
+
269
+ const bar = document.createElement('div');
270
+ bar.className = 'rv-bar';
271
+ bar.innerHTML = `
272
+ <div class="seg tiny rv-views" role="tablist">
273
+ <button data-view="pretty" ${resp && resp.is_binary ? 'disabled' : ''}>Pretty</button>
274
+ <button data-view="raw" ${resp && resp.is_binary ? 'disabled' : ''}>Raw</button>
275
+ <button data-view="preview" ${previewable ? '' : 'disabled'} title="${previewable ? 'Render HTML or show the image' : 'No preview for this content type'}">Preview</button>
276
+ </div>
277
+ <span class="rv-lang muted small">${esc(lang.toUpperCase())}${resp && resp.is_binary ? ' · binary' : ''}</span>
278
+ <button class="rv-btn rv-wrap ${state.wrap ? 'on' : ''}" title="Wrap long lines">Wrap</button>
279
+ <button class="rv-btn rv-expand" title="Expand every node">Expand all</button>
280
+ <button class="rv-btn rv-collapse" title="Collapse to the top level">Collapse</button>
281
+ <input class="rv-filter mono" placeholder="Filter path, e.g. data.items[0].name or items[*].id" title="Show only this part of the JSON. Wildcards: items[*].id, *.name" spellcheck="false">
282
+ <span class="grow"></span>
283
+ <span class="rv-search-box">
284
+ <input class="rv-search" placeholder="Search (Ctrl+F)" spellcheck="false">
285
+ <span class="rv-count muted small"></span>
286
+ <button class="rv-btn rv-prev" title="Previous match (Shift+Enter)">▲</button>
287
+ <button class="rv-btn rv-next" title="Next match (Enter)">▼</button>
288
+ </span>`;
289
+ const body = document.createElement('div');
290
+ body.className = 'rv-body' + (state.wrap ? ' wrap' : '');
291
+ container.appendChild(bar);
292
+ container.appendChild(body);
293
+
294
+ function parseJson() {
295
+ if (state.json !== undefined) return state.json;
296
+ try { state.json = lang === 'json' ? JSON.parse(text) : null; } catch { state.json = null; }
297
+ return state.json;
298
+ }
299
+ function copyPath(path) {
300
+ const full = `{{prev.json.${path}}}`;
301
+ copyText(path).then((ok) => toast(ok ? `Copied path: ${path} (use ${full} to chain)` : 'Could not copy', ok ? 'ok' : 'error'));
302
+ }
303
+ function render() {
304
+ $$('.rv-views button', bar).forEach((b) => b.classList.toggle('on', b.dataset.view === state.view));
305
+ const isJsonTree = state.view === 'pretty' && lang === 'json' && !huge;
306
+ $('.rv-expand', bar).hidden = !isJsonTree;
307
+ $('.rv-collapse', bar).hidden = !isJsonTree;
308
+ $('.rv-filter', bar).hidden = !(lang === 'json' && state.view !== 'preview');
309
+ body.innerHTML = '';
310
+ body.className = 'rv-body' + (state.wrap ? ' wrap' : '') + ' v-' + state.view;
311
+ if (!resp) { body.innerHTML = '<div class="rv-empty muted">No response</div>'; return; }
312
+ if (state.view === 'preview') { renderPreview(); return; }
313
+ if (resp.is_binary) {
314
+ body.innerHTML = `<div class="rv-empty muted">Binary content (${esc(resp.content_type || 'unknown type')}, ${fmtBytes(resp.size)}). Use Preview for images, or save the body to a file.</div>`;
315
+ return;
316
+ }
317
+ if (!text) { body.innerHTML = '<div class="rv-empty muted">Empty body</div>'; return; }
318
+ let shown = text;
319
+ if (state.view === 'pretty' && lang === 'json') {
320
+ const data = parseJson();
321
+ if (data === null && lang === 'json') { pre(text); return; }
322
+ let value = data;
323
+ if (state.filter) {
324
+ const r = jsonPathGet(data, state.filter);
325
+ if (!r.ok) { body.innerHTML = `<div class="rv-empty muted">Nothing matches <code>${esc(state.filter)}</code></div>`; return; }
326
+ value = r.value;
327
+ }
328
+ if (huge) { pre(JSON.stringify(value, null, 2)); return; }
329
+ const tree = jsonTree(value, { onPath: copyPath });
330
+ body.appendChild(tree);
331
+ state.tree = tree;
332
+ if (resp.truncated) note('Body truncated in the viewer; the full body is saved with runs.');
333
+ applySearch();
334
+ return;
335
+ }
336
+ if (state.view === 'raw' && lang === 'json' && state.filter) {
337
+ const r = jsonPathGet(parseJson(), state.filter);
338
+ shown = r.ok ? JSON.stringify(r.value, null, 2) : '';
339
+ if (!r.ok) { body.innerHTML = `<div class="rv-empty muted">Nothing matches <code>${esc(state.filter)}</code></div>`; return; }
340
+ }
341
+ if (state.view === 'pretty' && (lang === 'xml' || lang === 'html') && !huge) {
342
+ const p = document.createElement('pre');
343
+ p.className = 'rv-pre mono x';
344
+ p.innerHTML = highlightXml(typeof formatXml === 'function' && text.length < 300000 && !/\n\s*</.test(text) ? formatXml(text) : text);
345
+ body.appendChild(p);
346
+ if (resp.truncated) note('Body truncated in the viewer.');
347
+ applySearch();
348
+ return;
349
+ }
350
+ pre(shown);
351
+ if (resp.truncated) note('Body truncated in the viewer; the full body is saved with runs.');
352
+ applySearch();
353
+ }
354
+ function pre(t) {
355
+ const p = document.createElement('pre');
356
+ p.className = 'rv-pre mono';
357
+ p.textContent = t;
358
+ body.appendChild(p);
359
+ }
360
+ function note(msg) {
361
+ const d = document.createElement('div');
362
+ d.className = 'rv-note muted small';
363
+ d.textContent = msg;
364
+ body.appendChild(d);
365
+ }
366
+ function renderPreview() {
367
+ if (resp.is_binary && resp.body_base64) {
368
+ if (ct.startsWith('image/')) {
369
+ const img = document.createElement('img');
370
+ img.className = 'rv-img';
371
+ img.src = `data:${ct.split(';')[0]};base64,${resp.body_base64}`;
372
+ img.alt = 'Response image';
373
+ body.appendChild(img);
374
+ return;
375
+ }
376
+ if (ct === 'application/pdf') {
377
+ const fr = document.createElement('iframe');
378
+ fr.className = 'rv-frame';
379
+ fr.src = `data:application/pdf;base64,${resp.body_base64}`;
380
+ body.appendChild(fr);
381
+ return;
382
+ }
383
+ }
384
+ if (resp.is_binary) { body.innerHTML = '<div class="rv-empty muted">Too large to preview inline. Save the body to a file instead.</div>'; return; }
385
+ const fr = document.createElement('iframe');
386
+ fr.className = 'rv-frame';
387
+ fr.setAttribute('sandbox', ''); // no scripts, no navigation, no forms
388
+ fr.srcdoc = text;
389
+ fr.title = 'HTML preview';
390
+ body.appendChild(fr);
391
+ }
392
+ function applySearch() {
393
+ const q = state.q.trim();
394
+ const count = $('.rv-count', bar);
395
+ if (!q) { clearMarks(body); state.marks = []; state.cur = -1; count.textContent = ''; return; }
396
+ if (state.tree) state.tree._expandAll(20000);
397
+ state.marks = markMatches(body, q);
398
+ state.cur = state.marks.length ? 0 : -1;
399
+ showCurrent();
400
+ }
401
+ function showCurrent() {
402
+ const count = $('.rv-count', bar);
403
+ state.marks.forEach((m, i) => m.classList.toggle('cur', i === state.cur));
404
+ count.textContent = state.marks.length ? `${state.cur + 1}/${state.marks.length}` : 'no match';
405
+ count.classList.toggle('none', !state.marks.length);
406
+ if (state.cur >= 0) state.marks[state.cur].scrollIntoView({ block: 'center' });
407
+ }
408
+ function step(d) {
409
+ if (!state.marks.length) return;
410
+ state.cur = (state.cur + d + state.marks.length) % state.marks.length;
411
+ showCurrent();
412
+ }
413
+
414
+ $$('.rv-views button', bar).forEach((b) => b.addEventListener('click', () => { if (b.disabled) return; state.view = b.dataset.view; try { localStorage.setItem('pyhttp.rv.view', state.view); } catch { /* ignore */ } render(); }));
415
+ $('.rv-wrap', bar).addEventListener('click', (e) => { state.wrap = !state.wrap; e.currentTarget.classList.toggle('on', state.wrap); body.classList.toggle('wrap', state.wrap); try { localStorage.setItem('pyhttp.rv.wrap', state.wrap ? '1' : '0'); } catch { /* ignore */ } });
416
+ $('.rv-expand', bar).addEventListener('click', () => { if (state.tree && !state.tree._expandAll()) toast('Very large document: only the first 60 000 nodes were expanded'); });
417
+ $('.rv-collapse', bar).addEventListener('click', () => state.tree && state.tree._collapseAll());
418
+ let ft = null;
419
+ $('.rv-filter', bar).addEventListener('input', (e) => { clearTimeout(ft); ft = setTimeout(() => { state.filter = e.target.value.trim(); render(); }, 150); });
420
+ const search = $('.rv-search', bar);
421
+ let st = null;
422
+ search.addEventListener('input', () => { clearTimeout(st); st = setTimeout(() => { state.q = search.value; applySearch(); }, 150); });
423
+ search.addEventListener('keydown', (e) => {
424
+ if (e.key === 'Enter') { e.preventDefault(); step(e.shiftKey ? -1 : 1); }
425
+ if (e.key === 'Escape') { search.value = ''; state.q = ''; applySearch(); search.blur(); }
426
+ });
427
+ $('.rv-prev', bar).addEventListener('click', () => step(-1));
428
+ $('.rv-next', bar).addEventListener('click', () => step(1));
429
+ container._focusSearch = () => { search.focus(); search.select(); };
430
+ if (state.view === 'preview' && !previewable) state.view = 'pretty';
431
+ if (resp && resp.is_binary) state.view = previewable ? 'preview' : 'raw';
432
+ render();
433
+ return container;
434
+ }