[ Avaa Bypassed ]




Upload:

Command:

www-data@3.133.117.5: ~ $
"""Helps you output colourised code snippets in ReportLab documents.

Platypus has an 'XPreformatted' flowable for handling preformatted
text, with variations in fonts and colors.   If Pygments is installed,
calling 'pygments2xpre' will return content suitable for display in
an XPreformatted object.  If it's not installed, you won't get colours.

For a list of available lexers see http://pygments.org/docs/

"""
__all__ = ('pygments2xpre',)
from reportlab.lib.utils import isPy3, asBytes, getBytesIO, getStringIO, asUnicode, isUnicode
import re

def _2xpre(s,styles):
    "Helper to transform Pygments HTML output to ReportLab markup"
    s = s.replace('<div class="highlight">','')
    s = s.replace('</div>','')
    s = s.replace('<pre>','')
    s = s.replace('</pre>','')
    for k,c in styles+[('p','#000000'),('n','#000000'),('err','#000000')]:
        s = s.replace('<span class="%s">' % k,'<span color="%s">' % c)
        s = re.sub(r'<span class="%s\s+.*">'% k,'<span color="%s">' % c,s)
    s = re.sub(r'<span class=".*">','<span color="#0f0f0f">',s)
    return s

def pygments2xpre(s, language="python"):
    "Return markup suitable for XPreformatted"
    try:
        from pygments import highlight
        from pygments.formatters import HtmlFormatter
    except ImportError:
        return s

    from pygments.lexers import get_lexer_by_name
    rconv = lambda x: x
    if isPy3:
        out = getStringIO()
    else:
        if isUnicode(s):
            s = asBytes(s)
            rconv = asUnicode
        out = getBytesIO()

    l = get_lexer_by_name(language)
    
    h = HtmlFormatter()
    highlight(s,l,h,out)
    styles = [(cls, style.split(';')[0].split(':')[1].strip())
                for cls, (style, ttype, level) in h.class2style.items()
                if cls and style and style.startswith('color:')]
    return rconv(_2xpre(out.getvalue(),styles))

def convertSourceFiles(filenames):
    "Helper function - makes minimal PDF document"

    from reportlab.platypus import Paragraph, SimpleDocTemplate, Spacer, XPreformatted
    from reportlab.lib.styles import getSampleStyleSheet
    styT=getSampleStyleSheet()["Title"]
    styC=getSampleStyleSheet()["Code"]
    doc = SimpleDocTemplate("pygments2xpre.pdf")
    S = [].append
    for filename in filenames:
        S(Paragraph(filename,style=styT))
        src = open(filename, 'r').read()
        fmt = pygments2xpre(src)
        S(XPreformatted(fmt, style=styC))
    doc.build(S.__self__)
    print('saved pygments2xpre.pdf')

if __name__=='__main__':
    import sys
    filenames = sys.argv[1:]
    if not filenames:
        print('usage:  pygments2xpre.py file1.py [file2.py] [...]')
        sys.exit(0)
    convertSourceFiles(filenames)

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
PyFontify.py File 4.86 KB 0644
__init__.py File 258 B 0755
_rl_accel.cpython-38-x86_64-linux-gnu.so File 44.7 KB 0644
abag.py File 1.1 KB 0644
arciv.py File 7.43 KB 0644
attrmap.py File 5.37 KB 0644
boxstuff.py File 2.86 KB 0644
codecharts.py File 12.76 KB 0644
colors.py File 40.1 KB 0644
corp.py File 26.53 KB 0755
enums.py File 296 B 0644
extformat.py File 2.17 KB 0644
fontfinder.py File 13.24 KB 0644
fonts.py File 3.44 KB 0755
formatters.py File 3.73 KB 0755
geomutils.py File 1.14 KB 0644
hyphen.mashed File 35.6 KB 0644
logger.py File 1.71 KB 0755
normalDate.py File 21.9 KB 0755
pagesizes.py File 1.96 KB 0755
pdfencrypt.py File 30.48 KB 0644
pygments2xpre.py File 2.66 KB 0644
randomtext.py File 22.63 KB 0755
rl_accel.py File 12.72 KB 0644
rl_safe_eval.py File 42.75 KB 0644
rltempfile.py File 1.09 KB 0644
rparsexml.py File 17.4 KB 0644
sequencer.py File 9.98 KB 0644
styles.py File 16.38 KB 0644
testutils.py File 11.57 KB 0644
textsplit.py File 9.5 KB 0644
units.py File 919 B 0755
utils.py File 50.57 KB 0644
validators.py File 10.42 KB 0644
yaml.py File 5.58 KB 0644