コード例 #1
0
ファイル: __init__.py プロジェクト: canopy/understory
 def parse(self, block):
     """"""
     text = dedent(block)
     if text.startswith(">>> "):
         lexer = pygments.lexers.PythonConsoleLexer()
         lexer.add_filter("codetagify")
         formatter = pygments.formatters.HtmlFormatter(cssclass="doctest")
         code = pygments.highlight(text, lexer, formatter)
         html = lxml.html.fromstring(code)
     else:
         html = E.PRE(text)
     return html
コード例 #2
0
ファイル: legacy_html.py プロジェクト: larseggert/xml2rfc
    def write_raw(self, text, align='left', blanklines=0, delimiter=None, source_line=None):
        if text:
            # Add padding with delimiter/blanklines, if specified
            edge = delimiter and [delimiter] or ['']
            edge.extend([''] * blanklines)
            fill = '\n'.join(edge)
            fill += text
            edge.reverse()
            fill += '\n'.join(edge)

            # Run through template, add to body buffer
            pre = E.PRE(fill)
            self.buf.append(self._serialize(pre))
コード例 #3
0
ファイル: core.py プロジェクト: siralmat/matrix-bot
    async def on_room_message(self, room, event):
        if event.sender == self.client.user:
            return

        for module in self.modules:
            try:
                await module.handle_room_message(self, room, event)
            except Exception as e:
                if self.debug:
                    msg = E.PRE(traceback.format_exc())
                    html_data = lxml.html.tostring(msg).decode('utf-8')
                    await self.send_room_html(room=room, content=html_data)
                else:
                    await self.send_room_text(room=room,
                                              content="There was an error.")
コード例 #4
0
ファイル: CheckDevData.py プロジェクト: NCIOCPL/cdr-tools
def diff_xml(old, new, verbose=False):
    differ = Differ()
    before = old.replace("\r", "").splitlines()
    after = new.replace("\r", "").splitlines()
    diffs = differ.compare(before, after)
    lines = []
    changes = False
    for line in diffs:
        line = line.rstrip("\n")
        color = COLORS.get(line[0], "white")
        if line and line[0] in COLORS:
            changes = True
            span = builder.SPAN(f"{line}\n",
                                style=f"background-color: {color}")
            lines.append(span)
        elif verbose:
            lines.append(builder.SPAN(line))
    if changes:
        return builder.PRE(FIXED, *lines)
    return None
コード例 #5
0
ファイル: runserver.py プロジェクト: keitheis/tulip-talk
def transform_code(div):
    path = op.join(FILEBASE, div.get('code'))
    code = open(path).read()
    replace(div, E.PRE(code))
コード例 #6
0
ファイル: CheckDevData.py プロジェクト: NCIOCPL/cdr-tools
def compare_table(body, name, old, new):
    items = []
    ot = old.tables[name]
    nt = new.tables[name]
    if set(ot.cols) != set(nt.cols):
        ul = builder.UL()
        item = builder.LI("TABLE STRUCTURE MISMATCH", ul)
        ul.append(builder.LI(f"old: {ot.cols:!r}"))
        ul.append(builder.LI(f"new: {nt.cols:!r}"))
        items.append(item)
    if ot.names:
        for key in sorted(ot.names):
            if key not in nt.names:
                items.append(builder.LI("row for ", builder.B(key), " lost"))
                continue
            old_row = ot.names[key].copy()
            new_row = nt.names[key].copy()
            if "id" in old_row:
                old_row.pop("id")
                new_row.pop("id")
            if old_row != new_row:
                cols = builder.UL()
                item = builder.LI("row for ", builder.B(key), " changed", cols)
                items.append(item)
                for col in old_row:
                    ov = old_row[col]
                    nv = new_row[col]
                    if ov != nv:
                        if name == "query" and col == "value":
                            ov = builder.PRE(ov.replace("\r", ""))
                            nv = builder.PRE(nv.replace("\r", ""))
                        else:
                            ov = repr(ov)
                            nv = repr(nv)
                        changes = builder.LI(f"{col!r} column changed")
                        cols.append(changes)
                        if col not in ("hashedpw", "password"):
                            changes.append(
                                builder.UL(builder.LI(f"old: {ov}"),
                                           builder.LI(f"new: {nv}")))
    elif name in ("grp_action", "grp_usr"):
        old_rows = [getattr(old, name)(row) for row in ot.rows]
        new_rows = [getattr(new, name)(row) for row in nt.rows]
        for row in sorted(set(old_rows) - set(new_rows)):
            items.append(builder.LI(f"row for {row} lost"))
    else:
        if name in dir(old):
            old_rows = set([getattr(old, name)(row) for row in ot.rows])
            new_rows = set([getattr(new, name)(row) for row in nt.rows])
        else:
            old_rows = set(ot.rows)
            new_rows = set(nt.rows)
        old_only = [(row, "lost") for row in (old_rows - new_rows)]
        new_only = [(row, "added") for row in (new_rows - old_rows)]
        deltas = old_only + new_only
        try:
            for row, which_set in sorted(deltas, key=lambda v: str(v)):
                items.append(builder.LI(f"{which_set}: {row}"))
        except:
            print(deltas)
            raise
    if items:
        body.append(builder.UL(*items))
    else:
        body.append(builder.P(CHECK, OK))
コード例 #7
0
ファイル: andoc.py プロジェクト: endpnt/andoc
    def doc(self, action='', id=None):
        if action == 'list' and id is None:
            list_tmpl = self._env.get_template('doc/list.html')
            return list_tmpl.render(title='Document List',
                                    documents=self._docs.get_list())

        d = Document(self._redis, id=id)
        if not d.content:
            raise cherrypy.HTTPError(404, "No such document")

        if action == 'raw':
            raw_tmpl = self._env.get_template('doc/raw.html')
            return raw_tmpl.render(title='Raw Document', doc=d)

        elif action == 'struc':
            struc_tmpl = self._env.get_template('doc/struc.html')
            elements = self._render(d.id)
            # TODO migrate this to jinja or keep lxml?
            if elements:
                html = []
                for start, end, sel in elements:
                    if len(d.content[start:end].strip()) > 0:
                        cclass = b.CLASS('s' + str(start) + 'e' + str(end))
                        if sel is not None and sel.docid == d.id:
                            node = b.E(NAMESPACE[sel.ref], cclass)
                            node.text = d.content[start:end]
                            html.append(node)
                        else:
                            html.append(b.PRE(d.content[start:end], cclass))

                return struc_tmpl.render(title="Document Semantic",
                                         doc=d,
                                         struc=lxhtml.tostring(b.DIV(*html)))
            else:
                return struc_tmpl.render(title="Document Semantic",
                                         doc=d,
                                         struc='Nothing here jet')

        elif action == 'view':
            view_tmpl = self._env.get_template('doc/view.html')
            elements = self._render(d.id)
            if elements:
                content_html = []
                meta_html = []
                metalist = {}
                for start, end, sel in elements:
                    if len(d.content[start:end]) > 0:
                        if sel is not None and sel.docid == d.id:
                            node = b.E(NAMESPACE[sel.ref])
                            node.text = d.content[start:end].strip()
                            content_html.append(node)
                        else:
                            content_html.append(
                                b.PRE(d.content[start:end].strip()))

                for pre in ('person', 'place', 'date', 'event'):
                    metalist[pre] = set()

                #for sel, sub, pre, obj, start, end in self._triples:
                #    if sel is not None and sel.docid == d.id:
                #        metalist[pre].add(obj)

                for pre in ('person', 'place', 'date', 'event'):
                    metali = []
                    for m in sorted(metalist[pre]):
                        metali.append(b.LI(m))
                    meta_html.append(b.H3(pre))
                    meta_html.append(b.UL(*metali))

                content = lxhtml.tostring(b.DIV(*content_html))
                meta = lxhtml.tostring(b.DIV(*meta_html))

                return view_tmpl.render(title='Document View',
                                        doc=d,
                                        content=content,
                                        meta=meta)
            else:
                return view_tmpl.render(title='Document View',
                                        doc=d,
                                        content='Nothing to render',
                                        meta='')
        else:
            raise cherrypy.HTTPError(400, 'No such action')
コード例 #8
0
                '<tbody>%s</tbody></table>' % (thresholds[0], thresholds[1], rows)
    except ValueError:
        table = ''
else:
    table = ''

# read in original page
ET = etree.parse('result.html', parser=etree.HTMLParser())
port = int(ET.findall('//meta[@name="port"]')[0].get('content'))

# fetch div of motif search results
div = ET.findall('//div[@id="motif_result"]')[0]
div.clear()

# insert matches, mrca info, file link and stats into HTML
div.append(E.PRE(E.CODE(txt)))
div.append(
    E.P(
        mrca,
        E.SPAN('see ',
               E.A('file', href='http://*****:*****@id="logo"]')[0].set(
    'src', 'http://*****:*****@id="favicon"]')[0].set(
    'href', 'http://*****:*****@id="msa_viz"]')
if len(msa_path) > 0: