def colorize_doctest(s): """ Perform syntax highlighting on the given doctest string, and return the resulting HTML code. This code consists of a C{<pre>} block with class=py-doctest. Syntax highlighting is performed using the following CSS classes: - C{py-prompt} -- the Python PS1 prompt (>>>) - C{py-more} -- the Python PS2 prompt (...) - the CSS classes output by L{colorize_codeblock} """ return tags.pre('\n', *colorize_doctest_body(s), class_='py-doctest')
def bigDiff(self, request, tag): mods = {} for m in self.root.editsbymod: l = [e for e in self.root.editsbymod[m] if e is self.root.editsbyob[e.obj.doctarget][-1]] l.sort(key=lambda x:x.obj.linenumber, reverse=True) mods[m] = FileDiff(m) for e in l: edit0 = self.root.editsbyob[e.obj][0] mods[m].apply_edit(edit0, e) r = [] for mod in sorted(mods, key=lambda x:x.filepath): r.append(tags.pre(mods[mod].diff())) return r
def colorize_codeblock(s): """ Colorize a string containing only Python code. This method differs from L{colorize_doctest} in that it will not search for doctest prompts when deciding how to colorize the string. This code consists of a C{<pre>} block with class=py-doctest. Syntax highlighting is performed using the following CSS classes: - C{py-keyword} -- a Python keyword (for, if, etc.) - C{py-builtin} -- a Python builtin name (abs, dir, etc.) - C{py-string} -- a string literal - C{py-comment} -- a comment - C{py-except} -- an exception traceback (up to the next >>>) - C{py-output} -- the output from a doctest block. - C{py-defname} -- the name of a function or class defined by a C{def} or C{class} statement. """ return tags.pre('\n', *colorize_codeblock_body(s), class_='py-doctest')
def debug_activities(self, request, tag): output = [] for shift in sorted(self.incidents_by_shift): output.append(u"{0}".format(shift)) output.append(u"") incidents_by_activity = self.incidents_by_shift[shift] for activity in Activity.iterconstants(): output.append(u" {0}".format(activity)) for incident in sorted(incidents_by_activity.get( activity, set() )): number = incident.number summary = incident.summaryFromReport() output.append(u" {0}: {1}".format(number, summary)) output.append(u"") output.append(u"") return tags.pre(u"\n".join(output))
def logentries(self, request, tag): logdata = yield self.get_log() rv = [ tag.clone().fillSlots(timestamp=tags.b("Fill Time"), cryo_name=tags.b("Cryo"), comments=tags.b("Comments")) ] for entry in logdata: timestamp = entry[0] cryo_name = entry[1] if self.cryo_name.lower() not in cryo_name.lower(): continue comments = entry[2] try: # convert to human readable date timestamp = datetime.datetime.strptime( timestamp, '%Y-%m-%dT%H:%M:%S.%f').ctime() except ValueError: pass rv.append(tag.clone().fillSlots(timestamp=timestamp, cryo_name=cryo_name, comments=tags.pre(comments))) returnValue(rv)
def preview(self, request, tag): docstring = parse_str(self.docstring) stan, errors = epydoc2stan.doc2stan( self.ob, docstring=docstring) if self.isPreview or errors: if errors: #print stan, errors #assert isinstance(stan, tags.pre) [text] = stan.children lines = text.replace('\r\n', '\n').split('\n') line2err = {} for err in errors: if isinstance(err, str): ln = None else: ln = err.linenum() line2err.setdefault(ln, []).append(err) w = len(str(len(lines))) for i, line in enumerate(lines): i += 1 cls = "preview" if i in line2err: cls += " error" tag(tags.pre(class_=cls)("%*s"%(w, i), ' ', line)) for err in line2err.get(i, []): tag(tags.p(class_="errormessage")(err.descr())) i += 1 for err in line2err.get(i, []): tag(tags.p(class_="errormessage")(err.descr())) items = [] for err in line2err.get(None, []): items.append(tags.li(str(err))) if items: tag(tags.ul(items)) else: tag = tag(stan) return tag(tags.h2("Edit")) else: return ()
def to_stan(self, docstring_linker): return tags.pre(class_='literalblock')('\n', self._text, '\n')
def diff(self, request, tag): fd = FileDiff(self.ob.parentMod) fd.apply_edit(self.root.editsbyob[self.ob][0], self.editA) fd.reset() fd.apply_edit(self.editA, self.editB) return tags.pre(fd.diff())
def _render_results(self, req, cr): assert ICheckResults(cr) c = self._client sb = c.get_storage_broker() r = [] def add(name, value): r.append(tags.li(name + ": ", value)) add("Report", tags.pre("\n".join(self._html(cr.get_report())))) add( "Share Counts", "need %d-of-%d, have %d" % (cr.get_encoding_needed(), cr.get_encoding_expected(), cr.get_share_counter_good())) add("Happiness Level", str(cr.get_happiness())) add("Hosts with good shares", str(cr.get_host_counter_good_shares())) if cr.get_corrupt_shares(): badsharemap = [] for (s, si, shnum) in cr.get_corrupt_shares(): d = tags.tr( tags.td("sh#%d" % shnum), tags.td(tags.div(s.get_nickname(), class_="nickname"), tags.div(tags.tt(s.get_name()), class_="nodeid")), ) badsharemap.append(d) add( "Corrupt shares", tags.table( tags.tr( tags.th("Share ID"), tags.th((tags.div("Nickname"), tags.div("Node ID", class_="nodeid")), class_="nickname-and-peerid")), badsharemap)) else: add("Corrupt shares", "none") add("Wrong Shares", str(cr.get_share_counter_wrong())) sharemap_data = [] shares_on_server = dictutil.DictOfSets() # FIXME: The two tables below contain nickname-and-nodeid # table column markup which is duplicated with each other, # introducer.xhtml, and deep-check-results.xhtml. All of these # (and any other presentations of nickname-and-nodeid) should be combined. for shareid in sorted(cr.get_sharemap().keys()): servers = sorted(cr.get_sharemap()[shareid], key=lambda s: s.get_longname()) for i, s in enumerate(servers): shares_on_server.add(s, shareid) shareid_s = "" if i == 0: shareid_s = str(shareid) d = tags.tr( tags.td(shareid_s), tags.td(tags.div(s.get_nickname(), class_="nickname"), tags.div(tags.tt(s.get_name()), class_="nodeid"))) sharemap_data.append(d) add( "Good Shares (sorted in share order)", tags.table( tags.tr( tags.th("Share ID"), tags.th(tags.div("Nickname"), tags.div("Node ID", class_="nodeid"), class_="nickname-and-peerid")), sharemap_data)) add("Recoverable Versions", str(cr.get_version_counter_recoverable())) add("Unrecoverable Versions", str(cr.get_version_counter_unrecoverable())) # this table is sorted by permuted order permuted_servers = [ s for s in sb.get_servers_for_psi(cr.get_storage_index()) ] num_shares_left = sum( [len(shareids) for shareids in shares_on_server.values()]) servermap = [] for s in permuted_servers: shareids = list(shares_on_server.get(s, [])) shareids.reverse() shareids_s = [ tags.tt(str(shareid), " ") for shareid in sorted(shareids) ] d = tags.tr( tags.td(tags.div(s.get_nickname(), class_="nickname"), tags.div(tags.tt(s.get_name()), class_="nodeid")), tags.td(shareids_s), ) servermap.append(d) num_shares_left -= len(shareids) if not num_shares_left: break add( "Share Balancing (servers in permuted order)", tags.table( tags.tr( tags.th(tags.div("Nickname"), tags.div("Node ID", class_="nodeid"), class_="nickname-and-peerid"), tags.th("Share IDs")), servermap)) return tags.ul(r)
def walkit(p, prev=0): if prev > 20: raise Exception('To much walking') print 'walkit called', p.get_content_type(), p.get_charsets() if p.is_multipart(): print 'is multipart' self.broadcast_dict['multipart'] = True for part in p.walk(): if "multipart" not in part.get_content_type(): print 'subwalk' prev += 1 yield walkit(part, prev) else: pass # print "multipart:", part.get_payload(); else: content_type = p.get_content_type() charset = '' filename = '' body = None if p.get_charsets() is not None: charset = p.get_charsets()[0] if charset is None: charset = '' io = StringIO.StringIO(p.get_payload(decode=True)) print 'content_type:', content_type, ' charset:', charset if content_type == "text/html": try: bs = BeautifulSoup(io) for tl in bs.findAll(True): if tl.name not in VALID_HTML_TAG_NAMES: tl.extract() [s.extract() for s in bs('script')] [s.extract() for s in bs('noscript')] [s.extract() for s in bs('style')] [s.extract() for s in bs('meta')] [s.extract() for s in bs('title')] self.html = bs.prettify(encoding='utf-8') body = tags.span(mail_keys._placeholder) print 'set html element' except Exception as e: print 'html failure:', e elif content_type == "text/plain": try: body = tags.pre(io.getvalue()) except Exception as e: print 'text failure:', e else: print 'attachment:', content_type try: print 'content-disposition:', p['content-disposition'] filename = re.findall( "filename=(\S+)", p['content-disposition'])[0].replace('\"', '') print 'filename:', filename try: filename = p.get_param('filename', None, 'content-disposition') except Exception as e2: print 'deep exception 1:', e2 filename = re.search(mail_keys.email_filename, filename).group(2) except Exception as e: print 'deep exception 2:', e filename = 'unknown' print 'filename:', filename self.broadcast_dict['attachments'] = True self.attachments.append( (filename, io.getvalue(), content_type)) body = mail_keys.sizeof_fmt(io.len) def filename_link(f): if len(f) > 0: t = tags.a(f) t.attributes[ 'href'] = 'http://www.scewpt.com/' + self.broadcast_dict[ 'file_dest'] + "_" + f return t else: return f yield tag.clone().fillSlots(body=body, content_type=content_type, charset=charset, filename=filename_link(filename))
def logentries(self, request, tag): logdata = yield self.get_log() rv = [tag.clone().fillSlots( timestamp=tags.b("Fill Time"), cryo_name=tags.b("Cryo"), comments=tags.b("Comments"))] for entry in logdata: timestamp = entry[0] cryo_name = entry[1] if self.cryo_name.lower() not in cryo_name.lower(): continue comments = entry[2] try: # convert to human readable date timestamp = datetime.datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%f').ctime() except ValueError: pass rv.append(tag.clone().fillSlots(timestamp=timestamp, cryo_name=cryo_name, comments=tags.pre(comments))) returnValue(rv)