PK!?AAhtmlviewer/__init__.pyfrom .pagination import PagedViewer from .core import view_table PK!#~ htmlviewer/core.pyfrom jinja2 import Environment, PackageLoader from uuid import uuid4 import os from threading import Timer from IPython.display import IFrame from .util import is_html env = Environment( loader=PackageLoader('htmlviewer', 'templates') ) def generate_html(data, **kwargs): rowHeader = kwargs.get('rowHeader', None) colHeader = [] renderer = dict() for record in data: for k, v in record.items(): if k not in colHeader: if k == rowHeader: colHeader.insert(0, k) else: colHeader.append(k) if kwargs.get('detectHTML', False): if isinstance(v, str) and is_html(v): renderer[k] = v config = { 'colHeader': colHeader, 'data': data, 'maxColWidth': 200, 'maxRowHeight': 500, 'renderer': renderer } config.update(kwargs) template = env.get_template('viewer.html') return template.render(config=config) def view_table(data, width=1000, height=500, filename=None, autodelete=True, **kwargs): # A TemporaryFile does not work with Jupyter Notebook if filename is None: filename = str(uuid4()) + '.html' try: with open(filename, 'w') as f: f.write(generate_html(data=data, width=width, height=height, **kwargs)) return IFrame(filename, width=width, height=height) finally: if autodelete: Timer(5, os.unlink, args=[filename]).start() PK!htmlviewer/pagination.pyfrom IPython.display import display import math from .core import view_table class PagedViewer: chunk_size = 10 page_number = 0 def __init__(self, records, chunk_size=10, **kwargs): self.records = list(records) self.chunk_size = chunk_size self.viewer_kwargs = kwargs @property def page_count(self): return math.ceil(self.record_count / self.chunk_size) @property def record_count(self): return len(self.records) def __len__(self): return self.record_count def _repr_html_(self): display(self.view()) return '' def view(self, page_number=None, start=None): """Choose a page number to view Keyword Arguments: page_number {int >= -1} -- Page number to view (default: {self.page_number}) start {int} -- Sequence of the record to start viewing (default: {None}) Returns: Viewer function object """ if page_number is None: page_number = self.page_number elif page_number == -1: page_number = self.page_count - 1 self.page_number = page_number if start is None: start = page_number * self.chunk_size return view_table(self.records[start: start + self.chunk_size], **self.viewer_kwargs) def next(self): """Shows the next page Returns: Viewer function object """ if len(self.records) < (self.page_number + 1) * self.chunk_size: self.page_number = 0 else: self.page_number += 1 return self.view() def previous(self): """Show the previous page Returns: Viewer function object """ self.page_number -= 1 if self.page_number < 0: self.page_number = self.page_count - 1 return self.view() def first(self): """Shows the first page Returns: Viewer function object """ return self.view(0) def last(self): """Shows the last page Returns: Viewer function object """ return self.view(-1) PK!,htmlviewer/templates/colResizable-1.6.min.js// colResizable 1.6 - a jQuery plugin by Alvaro Prieto Lauroba http://www.bacubacu.com/colresizable/ !function(t){var e,i=t(document),r=t("head"),o=null,s={},d=0,n="id",a="px",l="JColResizer",c="JCLRFlex",f=parseInt,h=Math,p=navigator.userAgent.indexOf("Trident/4.0")>0;try{e=sessionStorage}catch(g){}r.append("");var u=function(e,i){var o=t(e);if(o.opt=i,o.mode=i.resizeMode,o.dc=o.opt.disabledColumns,o.opt.disable)return w(o);var a=o.id=o.attr(n)||l+d++;o.p=o.opt.postbackSafe,!o.is("table")||s[a]&&!o.opt.partialRefresh||("e-resize"!==o.opt.hoverCursor&&r.append(""),o.addClass(l).attr(n,a).before('
'),o.g=[],o.c=[],o.w=o.width(),o.gc=o.prev(),o.f=o.opt.fixed,i.marginLeft&&o.gc.css("marginLeft",i.marginLeft),i.marginRight&&o.gc.css("marginRight",i.marginRight),o.cs=f(p?e.cellSpacing||e.currentStyle.borderSpacing:o.css("border-spacing"))||2,o.b=f(p?e.border||e.currentStyle.borderLeftWidth:o.css("border-left-width"))||1,s[a]=o,v(o))},w=function(t){var e=t.attr(n),t=s[e];t&&t.is("table")&&(t.removeClass(l+" "+c).gc.remove(),delete s[e])},v=function(i){var r=i.find(">thead>tr:first>th,>thead>tr:first>td");r.length||(r=i.find(">tbody>tr:first>th,>tr:first>th,>tbody>tr:first>td, >tr:first>td")),r=r.filter(":visible"),i.cg=i.find("col"),i.ln=r.length,i.p&&e&&e[i.id]&&m(i,r),r.each(function(e){var r=t(this),o=-1!=i.dc.indexOf(e),s=t(i.gc.append('
')[0].lastChild);s.append(o?"":i.opt.gripInnerHtml).append('
'),e==i.ln-1&&(s.addClass("JCLRLastGrip"),i.f&&s.html("")),s.bind("touchstart mousedown",J),o?s.addClass("JCLRdisabledGrip"):s.removeClass("JCLRdisabledGrip").bind("touchstart mousedown",J),s.t=i,s.i=e,s.c=r,r.w=r.width(),i.g.push(s),i.c.push(r),r.width(r.w).removeAttr("width"),s.data(l,{i:e,t:i.attr(n),last:e==i.ln-1})}),i.cg.removeAttr("width"),i.find("td, th").not(r).not("table th, table td").each(function(){t(this).removeAttr("width")}),i.f||i.removeAttr("width").addClass(c),C(i)},m=function(t,i){var r,o,s=0,d=0,n=[];if(i){if(t.cg.removeAttr("width"),t.opt.flush)return void(e[t.id]="");for(r=e[t.id].split(";"),o=r[t.ln+1],!t.f&&o&&(t.width(o*=1),t.opt.overflow&&(t.css("min-width",o+a),t.w=o));d*{cursor:"+n.opt.dragCursor+"!important}"),a.addClass(n.opt.draggingClass),o=a,n.c[d.i].l)for(var f,h=0;h
PK!F877htmlviewer/templates/viewer.jsString.prototype.hashCode = function() { var hash = 0, i, chr; if (this.length === 0) return hash; for (i = 0; i < this.length; i++) { chr = this.charCodeAt(i); hash = ((hash << 5) - hash) + chr; hash |= 0; // Convert to 32bit integer } return hash; }; defaultConfig = { maxColWidth: 400, minColWidth: 50 } Object.assign(config, defaultConfig); Object.keys(config).forEach(key=>{ if(key.charAt(key.length - 1) === 's'){ config[key.slice(0, -1)] = config[key] } }); $(function () { $('.table').colResizable({ liveDrag: true, resizeMode: 'overflow', onDrag: ()=>{ const $body = $('body'); const maxWidth = $(this).width(); if($body.width() < maxWidth){ $body.width(maxWidth); } } }); // $('body').removeAttr('style'); }); makeTable(config); function makeTable(config){ const colHeader = config.colHeader; let table = document.createElement('table'); table.className = 'table table-striped table-bordered'; let thead = document.createElement('thead'); let tr = document.createElement('tr'); colHeader.forEach(key=>{ let th = document.createElement('th'); th.scope = 'col'; th.id = 'col' + key.hashCode(); switch(whatIsIt(config.maxColWidth)){ case "Object": th.style.maxWidth = config.maxColWidth[key] + 'px'; break; case "string": th.style.maxWidth = config.maxColWidth; break; case "number": th.style.maxWidth = config.maxColWidth + 'px'; break; } switch(whatIsIt(config.minColWidth)){ case "Object": th.style.minWidth = config.minColWidth[key] + 'px'; break; case "string": th.style.minWidth = config.minColWidth; break; case "number": th.style.minWidth = config.minColWidth + 'px'; break; } if (config.colWidth[key]){ th.style.maxWidth = (screen.width / 2) + 'px'; } th.innerHTML = key; tr.appendChild(th); }); thead.appendChild(tr); table.appendChild(thead); let tbody = document.createElement('tbody'); config.data.forEach(record=>{ let tr = document.createElement('tr'); colHeader.forEach(key=>{ let td = document.createElement('td'); let wrapped = document.createElement('div'); wrapped.className = 'wrapped' let wrapper = document.createElement('div'); wrapper.className = 'wrapper' wrapper.appendChild(wrapped); td.appendChild(wrapper); switch(whatIsIt(record[key])){ case "Object": wrapped.innerHTML = '
' + JSON.stringify(record[key], null, 2) + '
'; break; case "Array": wrapped.innerHTML = '
' + JSON.stringify(record[key]) + '
'; break; case "number": wrapped.textContent = record[key]; break; case "string": switch(whatIsIt(config.renderer)){ case "Object": switch(config.renderer[key]){ case 'html': wrapped.innerHTML = record[key]; break; default: wrapped.innerHTML = textToHTML(record[key]); } break; case "string": switch(config.renderer) { case 'html': wrapped.innerHTML = record[key]; break; default: wrapped.innerHTML = textToHTML(record[key]); } break; default: wrapped.innerHTML = textToHTML(record[key]); } break; default: if(record[key]) wrapped.innerHTML = textToHTML(record[key]); } tr.appendChild(td); }); tbody.appendChild(tr); }); table.appendChild(tbody); document.getElementById('tableArea').appendChild(table); let style = document.createElement('style'); document.head.appendChild(style); style.sheet.insertRule(` .wrapper { max-height: ${config.maxRowHeight}px; } `, 0); let totalWidth = 0; colHeader.forEach(key=>{ const el = document.getElementById('col' + key.hashCode()); if (config.colWidth[key]){ el.style.width = config.colWidth[key] + 'px'; totalWidth += config.colWidth[key]; } else { let width = el.clientWidth; const maxWidth = parseFloat(el.style.maxWidth); const minWidth = parseFloat(getComputedStyle(el).fontSize) * el.textContent.length; if (width > maxWidth) width = maxWidth; else if (width < minWidth) width = minWidth; el.style.width = width + 'px'; totalWidth += width; } }); document.getElementById('body').style.width = totalWidth + 'px'; } function whatIsIt(object) { var arrayConstructor = [].constructor; var objectConstructor = {}.constructor; if (object === null) { return "null"; } else if (object === undefined) { return "undefined"; } else if (object.constructor === arrayConstructor) { return "Array"; } else if (object.constructor === objectConstructor) { return "Object"; } else { return typeof object; } } function textToHTML(text) { return ((text || "") + "") // make sure it is a string; .replace(/&/g, "&") .replace(//g, ">") .replace(/\t/g, " ") .replace(/ /g, "​ ​") .replace(/\r\n|\r|\n/g, "
"); } PK!Qhtmlviewer/util.pyimport re RE_IS_HTML = re.compile(r"(?:)|(?:<[^<]+/>)") def is_html(s): return RE_IS_HTML.search(s) is not None PK! ::"htmlviewer-0.1.7.dist-info/LICENSEMIT License Copyright (c) 2018 Pacharapol Withayasakpunt Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!H WX htmlviewer-0.1.7.dist-info/WHEEL A н#Z."jm)Afb~ڠO68oF04UhoAf f4=4h0k::wXPK!H1M` #htmlviewer-0.1.7.dist-info/METADATAVmO8_1[>ktvEWv?zIv CHu<<3<3340=fSfL }2(yt2N0 KAOQtfLda\$pFEÆLf4 0Y;GEs+ HzpMH@TӇhK?c㐓jǜ!Q\ pJNYl1¼V2Q4ΩH ll1bܰWLN6=wڅ!j<v/||nPO! I`vu:e:Ry{POU"*Kv z )Hlr T1im@겥4(1LCD1 '\ 2,m>`,hώunmA_hSrOrϚ,/r%/s)RRM%GGG0V2[RQ K YzjûOw7OnNMxaFU+;BA+ V $b1- [1{M,t_<{L#ѿ 6e o_(b??#P֪D>+$4> i T#Z:, X!~gYЬodbд38cŌ[:,ђԧvyGd3:s QLL1$ lfF0#;ɞKR{;ր%6eZؙBYU yCq8gA-Jk^v۝L'=gn"h>pD$cV #dcDz/]$xWEgZ?9iԇ^5^5U֯[T֭Q)j)WDMȻNVov5{ ?ľZ`k}%m|Ro4m6^L_BPK!HG+M!htmlviewer-0.1.7.dist-info/RECORD}˒@< 0 " nr 77j˝&҂T〈J_k eU_,1_~AV EiD{a-:8PVl)6ۑXov@gpgĴ e1 DǼÐ`x