/usr/lib/python3/dist-packages/twisted/python
NameSizeModeActions
test/-0755rm
_pydoctortemplates/-0755rm
__pycache__/-0755rm
compat.py169310644editdlrm
components.py141990644editdlrm
constants.py5130644editdlrm
context.py40540644editdlrm
deprecate.py276680644editdlrm
failure.py270070644editdlrm
fakepwd.py67320644editdlrm
filepath.py540230644editdlrm
formmethod.py121070644editdlrm
htmlizer.py36260644editdlrm
lockfile.py80260644editdlrm
log.py223020644editdlrm
logfile.py101190644editdlrm
modules.py267150644editdlrm
monkey.py21640644editdlrm
procutils.py13710644editdlrm
randbytes.py34590644editdlrm
rebuild.py71220644editdlrm
reflect.py204800644editdlrm
release.py11040644editdlrm
roots.py71780644editdlrm
runtime.py59240644editdlrm
sendmsg.py26820644editdlrm
shortcut.py23020644editdlrm
syslog.py36520644editdlrm
systemd.py29870644editdlrm
text.py54170644editdlrm
threadable.py33270644editdlrm
threadpool.py102030644editdlrm
twisted-completion.zsh13710644editdlrm
url.py2440644editdlrm
urlpath.py84470644editdlrm
usage.py345770644editdlrm
util.py274320644editdlrm
versions.py2730644editdlrm
win32.py47940644editdlrm
zippath.py90280644editdlrm
zipstream.py96800644editdlrm
_appdirs.py8200644editdlrm
_inotify.py34960644editdlrm
_pydoctor.py67350644editdlrm
_release.py188790644editdlrm
_shellcomp.py252790644editdlrm
_textattributes.py90970644editdlrm
_tzhelper.py31280644editdlrm
_url.py2280644editdlrm
__init__.py5980644editdlrm
Edit: /usr/lib/python3/dist-packages/twisted/python/htmlizer.py (3626B)
# -*- test-case-name: twisted.python.test.test_htmlizer -*- # Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ HTML rendering of Python source. """ import keyword import tokenize from html import escape from typing import List from . import reflect class TokenPrinter: """ Format a stream of tokens and intermediate whitespace, for pretty-printing. """ currentCol, currentLine = 0, 1 lastIdentifier = parameters = 0 encoding = "utf-8" def __init__(self, writer): """ @param writer: A file-like object, opened in bytes mode. """ self.writer = writer def printtoken(self, type, token, sCoordinates, eCoordinates, line): if hasattr(tokenize, "ENCODING") and type == tokenize.ENCODING: self.encoding = token return if not isinstance(token, bytes): token = token.encode(self.encoding) (srow, scol) = sCoordinates (erow, ecol) = eCoordinates if self.currentLine < srow: self.writer(b"\n" * (srow - self.currentLine)) self.currentLine, self.currentCol = srow, 0 self.writer(b" " * (scol - self.currentCol)) if self.lastIdentifier: type = "identifier" self.parameters = 1 elif type == tokenize.NAME: if keyword.iskeyword(token): type = "keyword" else: if self.parameters: type = "parameter" else: type = "variable" else: type = tokenize.tok_name.get(type) assert type is not None type = type.lower() self.writer(token, type) self.currentCol = ecol self.currentLine += token.count(b"\n") if self.currentLine != erow: self.currentCol = 0 self.lastIdentifier = token in (b"def", b"class") if token == b":": self.parameters = 0 class HTMLWriter: """ Write the stream of tokens and whitespace from L{TokenPrinter}, formating tokens as HTML spans. """ noSpan: List[str] = [] def __init__(self, writer): self.writer = writer noSpan: List[str] = [] reflect.accumulateClassList(self.__class__, "noSpan", noSpan) self.noSpan = noSpan def write(self, token, type=None): if isinstance(token, bytes): token = token.decode("utf-8") token = escape(token) token = token.encode("utf-8") if (type is None) or (type in self.noSpan): self.writer(token) else: self.writer( b'' + token + b"" ) class SmallerHTMLWriter(HTMLWriter): """ HTMLWriter that doesn't generate spans for some junk. Results in much smaller HTML output. """ noSpan = ["endmarker", "indent", "dedent", "op", "newline", "nl"] def filter(inp, out, writer=HTMLWriter): out.write(b"
")
    printer = TokenPrinter(writer(out.write).write).printtoken
    try:
        for token in tokenize.tokenize(inp.readline):
            (tokenType, string, start, end, line) = token
            printer(tokenType, string, start, end, line)
    except tokenize.TokenError:
        pass
    out.write(b"
\n") def main(): import sys stdout = getattr(sys.stdout, "buffer", sys.stdout) with open(sys.argv[1], "rb") as f: filter(f, stdout) if __name__ == "__main__": main()