def draw_table(self, table, table_num=None): style = 'tt %s %s' % ( table.attrib.get('style', self.defaults['table_style']), table.attrib.get('align', self.defaults['table_align'])) cellpadding = '3' cellspacing = '0' htmltable = E.TABLE(cellpadding=cellpadding, ) htmltable.attrib['cellspacing'] = cellspacing htmltable.attrib['class'] = style # Add caption, if it exists if 'title' in table.attrib and table.attrib['title']: caption = '' if table_num and self.pis['tablecount'] == 'yes': caption = 'Table ' + str(table_num) + ': ' htmltable.append(E.CAPTION(caption + table.attrib['title'])) # Draw headers header_row = E.TR() col_aligns = [] for header in table.findall('ttcol'): th = E.TH() if header.text: th.text = header.text header_align = header.attrib.get('align', self.defaults['ttcol_align']) th.attrib['class'] = header_align # Store alignment information col_aligns.append(header_align) header_row.append(th) htmltable.append(E.THEAD(header_row)) # Draw body body = E.TBODY() tr = E.TR() num_columns = len(col_aligns) for i, cell in enumerate(table.findall('c')): col_num = i % num_columns if col_num == 0 and i != 0: # New row body.append(tr) tr = E.TR() td = E.TD() if cell.text: # Add text td.text = cell.text for child in cell: # Add any inline elements (references) for element in self._expand_ref(child): td.append(element) # Get alignment from header td.attrib['class'] = col_aligns[col_num] tr.append(td) body.append(tr) # Add final row htmltable.append(body) # Add to body buffer self.buf.append(self._serialize(htmltable))
def make_summary_doc(tests_w_results): tbody = B.TBODY( B.TR(B.TH('Test Name'), B.TH('Inserted (in # of blocks)'), B.TH('Deleted (in # of blocks)'), B.TH('Links'), B.TH('Notes'))) for (test, result) in tests_w_results: row = make_summary_row(test, result) tbody.append(row) return B.HTML( B.HEAD(B.TITLE('Readability Test Summary'), B.STYLE(SUMMARY_CSS, type='text/css')), B.BODY(B.TABLE(tbody)))
def html_page_return(board, thread, default_style): html = E.HTML( E.HEAD( E.META(**{'http-equiv':"Default-Style", 'content':default_style, 'id':'stylemetatag'}), E.TITLE("/"+board+"/ - №"+str(thread)), #title E.SCRIPT(type = 'text/javascript', src = '/mainscript.js'), #js *initiate.style_cache ), E.BODY( E.P(E.CLASS("board"), board, id = 'board'), E.P(E.CLASS("thread"), str(thread), id = 'thread'), E.TABLE( E.CLASS("maintable"), E.THEAD(E.TR(E.TD( E.TABLE(E.TR(E.TD(E.CLASS('left'), copy.copy(initiate.board_cache_navigation)), E.TD(E.CLASS('right'), utilfunctions.generate_right_up_corner_menu()), ), id='headblock'), E.HR(E.CLASS("delimeter")), )), id = 'header'), E.TBODY(E.TR(E.TD( E.H2(E.CLASS("boardname"), E.A('/' + board + '/ - '+ initiate.board_cache[board].name, href = '/' + board), ), E.HR(E.CLASS("delimeter")), initiate.board_cache[board].post_form, #need to make it depending on post_form_type E.SCRIPT('function open_form() {document.getElementById("postform").style.display = "block"; document.getElementById("closeform").style.display = "block"; document.getElementById("threadcreate").style.display = "none";}'), E.SCRIPT('function close_form() {document.getElementById("postform").style.display = "none"; document.getElementById("closeform").style.display = "none"; document.getElementById("threadcreate").style.display = "block";}'), E.H3(E.A('Ответить в тред', href = "javascript:open_form();"), id = 'threadcreate'), E.H4(E.A('Скрыть форму', href = "javascript:close_form();"), id = 'closeform'), E.HR(E.CLASS("delimeter")), EM('main', '', id = 'mainframe'), E.DIV('', id = 'optionsdiv'), )), id = 'mainpart'), E.TFOOT(E.TR(E.TD( E.DIV( E.HR(E.CLASS("delimeter"), id = 'end') ), initiate.board_cache_navigation, E.DIV('powered by ', E.A('Farlight Imageboard Engine', href='https://github.com/Alpherie/farlight_board_engine', target='_blank', ), id='credentials'), )), id = 'footer'),#we make it a footer ), onload = 'threadfunc()' ) ) return lxml.html.tostring(html)
def main_page_gen(default_style): html = E.HTML( E.HEAD( E.META(**{'http-equiv':"Default-Style", 'content':default_style, 'id':'stylemetatag'}), E.TITLE("U2ch - Main Page"), E.SCRIPT(type = 'text/javascript', src = '/mainscript.js'), #js *initiate.style_cache ), E.BODY( E.UL(initiate.stats_cache, style = "display: none;", id = "mblstatscache"), E.TABLE( E.CLASS("maintable"), E.THEAD(E.TR(E.TD(E.DIV(E.CLASS("mainslogandiv"), E.SPAN("U2CH"), E.SPAN("", style="display: inline-block; width: 5em;"), E.SPAN("Viewing above imageboards"), ), E.DIV(E.CLASS("mainimagediv"), E.IMG(src="u-2.jpg", style="width:496px;height:334px;"), ), )), id = 'header'), E.TBODY(E.TR(E.TD( E.HR(E.CLASS("delimeter")), E.DIV(E.CLASS("mblcontainer"), E.DIV(E.CLASS("mblcentering"), initiate.board_cache_main_page, ), ), E.HR(E.CLASS("delimeter")), )), id = 'mainpart'), E.TFOOT(E.TR(E.TD( E.DIV('powered by ', E.A('Farlight Imageboard Engine', href='https://github.com/Alpherie/farlight_board_engine', target='_blank', ), id='credentials'), )), id = 'footer'), ), onload = 'mainpagefunc()' ) ) return lxml.html.tostring(html)
def main(): cursor = db.connect(user="******").cursor() query = db.Query("document d", "d.id", "d.title", "d.xml").order(2) query.join("doc_type t", "t.id = d.doc_type") query.where("t.name = 'Filter'") filters = [] for doc_id, doc_title, doc_xml in query.execute(cursor).fetchall(): filters.append(Filter(doc_id, doc_title, doc_xml)) tbody = builder.TBODY() caption = builder.CAPTION(TITLE) for name in sorted(Parameter.parameters, key=str.lower): parm = Parameter.parameters[name] parm.add_rows(tbody) page = builder.HTML( builder.HEAD( builder.TITLE(TITLE), builder.LINK(rel="stylesheet", href="/stylesheets/cdr.css"), builder.STYLE("th { text-align: right; vertical-align: top; }")), builder.BODY(builder.TABLE(caption, tbody), builder.CLASS("report"))) print("Content-type: text/html\n") print(etree.tostring(page, pretty_print=True).decode("ascii"))
def ascii_table(className): table = E.TABLE( E.CLASS(className), E.TBODY() ) cells = ['Dec', 'Hex', 'Oct', 'Char', 'Meaning', 'Dec', 'Hex', 'Oct', 'Char', 'Dec', 'Hex', 'Oct', 'Char', 'Dec', 'Hex', 'Oct', 'Char' ] row = construct_row(cells, True) table.append(row) for i in range(32): cells = [] for j in range(4): code = i + j*32; cells.append('%d' % code) cells.append('%02X' % code) cells.append('%03o' % code) if code in ascii: cells.append(ascii[code]['char']) if 'desc' in ascii[code]: cells.append(ascii[code]['desc']) else: cells.append(chr(code)) row = construct_row(cells) table.append(row) return tostring(table);
def pr_table(token, jira_url, delta): u""" Return an Element that renders all changes in `delta` as a table listing merged PRs.abs Arguments: token: The github token to access the github API with. jira_url: The base url of the JIRA instance to link JIRA tickets to. delta (VersionDelta): The AMIs to compare. """ version = delta.new or delta.base match = re.search(u"github.com/(?P<org>[^/]*)/(?P<repo>.*)", version.repo) api = GitHubAPI(match.group(u'org'), match.group(u'repo'), token) try: prs = api.get_pr_range(delta.base.sha, delta.new.sha) change_details = E.TABLE( E.CLASS(u"wrapped"), E.TBODY( E.TR( E.TH(u"Merged By"), E.TH(u"Author"), E.TH(u"Title"), E.TH(u"PR"), E.TH(u"JIRA"), E.TH(u"Release Notes?"), ), *[ E.TR( E.TD( E.A( pull_request.merged_by.login, href=pull_request.merged_by.html_url, )), E.TD( E.A( pull_request.user.login, href=pull_request.user.html_url, )), E.TD(pull_request.title), E.TD( E.A( str(pull_request.number), href=pull_request.html_url, )), E.TD( format_jira_references(jira_url, pull_request.body)), E.TD(u""), ) for pull_request in sorted( prs, key=lambda pr: pr.merged_by.login) ])) except Exception: # pylint: disable=broad-except LOGGER.exception(u'Unable to get PRs for %r', delta) change_details = E.P("Unable to list changes") return SECTION( E.H3(u"Changes for {} (".format(delta.app), E.A(GITHUB_PREFIX.sub(u'', version.repo), href=version.repo), ")"), E.P(E.STRONG(u"Before: "), E.A(delta.base.sha, href=format_commit_url(delta.base))), E.P(E.STRONG(u"After: "), E.A(delta.new.sha, href=format_commit_url(delta.new))), change_details, )
def write_reference_list(self, list): tbody = E.TBODY() refkeys = [] refdict = {} for i, reference in enumerate(list.findall('reference')): tr = E.TR() # Use anchor or num depending on PI anchor = reference.attrib.get('anchor', str(i + self.ref_start)) if self.pis['symrefs'] == 'yes': bullet = anchor else: bullet = str(i + self.ref_start) bullet_td = E.TD(E.B('[' + bullet + ']', id=anchor)) bullet_td.attrib['class'] = 'reference' ref_td = E.TD() ref_td.attrib['class'] = 'top' last = None authors = reference.findall('front/author') for j, author in enumerate(authors): organization = author.find('organization') email = author.find('address/email') initials, surname = short_author_name_parts(author) initials = self.get_initials(author) or initials or '' a = None if j == len(authors) - 1 and len(authors) > 1: last.tail = ' and ' if surname is not None: if j == len(authors) - 1 and len(authors) > 1: # Last author, render in reverse if len(initials) > 0: name_string = initials + ' ' + surname else: name_string = surname else: if len(initials) > 0: name_string = surname + ', ' + initials else: name_string = surname a = E.A(name_string) if email is not None and email.text: if self.pis['linkmailto'] == 'yes': a.attrib['href'] = 'mailto:' + email.text if organization is not None and organization.text: a.attrib['title'] = organization.text.strip() elif organization is not None and organization.text: # Use organization instead of name a = E.A(organization.text.strip()) else: continue ref_td.append(a) last = a a.tail = ', ' title = reference.find('front/title') if title is not None and title.text: title_string = title.text.strip() else: xml2rfc.log.warn('No title specified in reference', \ reference.attrib.get('anchor', '')) title_string = '' if title_string: if reference.attrib.get("quote-title", "true") == "true": # attribute default value: yes if last is not None: last.tail = ', "' else: ref_td.text = '"' title_a = E.A(title_string) title_a.tail = '"' else: if last is not None: last.tail = ', ' title_a = E.A(title_string) title_a.tail = '' ref_td.append(title_a) for seriesInfo in reference.findall('seriesInfo'): # Create title's link to document from seriesInfo if seriesInfo.attrib.get('name', '') == 'RFC': title_a.attrib['href'] = \ self.html_defaults['references_url'] + \ 'rfc' + seriesInfo.attrib.get('value', '') elif seriesInfo.attrib.get('name', '') == 'Internet-Draft': title_a.attrib['href'] = \ self.html_defaults['references_url'] + \ seriesInfo.attrib.get('value', '') title_a.tail += ', '+seriesInfo.attrib.get('name', '') + ' ' + \ seriesInfo.attrib.get('value', '') if not title_a.attrib.has_key("href"): href = reference.attrib.get("target", None) if href: title_a.attrib['href'] = href date = reference.find('front/date') if date is not None: month = date.attrib.get('month', '') if month.isdigit(): month = calendar.month_name[int(month)] year = date.attrib.get('year', '') if month or year: title_a.tail += ', ' if month: month += ' ' title_a.tail += month + year + '.' tr.append(bullet_td) tr.append(ref_td) refdict[bullet] = tr refkeys.append(bullet) # Render annotation as a separate paragraph annotation = reference.find('annotation') if annotation is not None and annotation.text: p = E.P() self.write_t_rec(annotation, parent=p) ref_td.append(p) if self.pis['sortrefs'] == 'yes' and self.pis['symrefs'] == 'yes': refkeys.sort(key=str.lower) for key in refkeys: tbody.append(refdict[key]) self.ref_start += i + 1 # Add to body buffer self.buf.append(self._serialize(E.TABLE(tbody)))
match = pattern.search(line) if match is None: return trs, position hierarchy.append(match.group(1)) divs, pos = get_boards(lines, position + 1, hierarchy) hierarchy.pop() trs.append(E.TR(E.TD(E.CLASS('header'), match.group(1)))) trs.append(E.TR(E.TD(E.CLASS('list'), *divs))) position = pos return trs, position if __name__ == "__main__": f = open(input_file, 'r') hierarchy = [] trs, end_pos = get_sections(f.readlines(), 0, hierarchy) #trs are tr sections from table html = E.TABLE(E.CLASS('category'), E.TBODY(*trs), width="100%", border="0", cellspacing="0", cellpadding="0") html_code = lxml.html.tostring(html) res_f = open(output_file, 'wb') res_f.write(html_code) res_f.close()