"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/extras/swig/testmod.py" (12 May 2020, 3148 Bytes) of package /windows/www/highlight-3.57-x64.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # -*- coding: utf-8 -*-
    2 # More advanced SWIG module test script
    3 #
    4 # Import highlight.py, which is the interface for the _highlight.so module.
    5 # See highlight.py for all available attributes and class members.
    6 #
    7 # Example: python2.7 testmod.py -Sperl -O odt testmod.pl testmod.pl.odt
    8 
    9 import highlight
   10 import sys
   11 from optparse import OptionParser
   12 
   13 formatList = { "html":  highlight.HTML,
   14        "xhtml": highlight.XHTML,
   15        "latex": highlight.LATEX,
   16        "rtf":   highlight.RTF,
   17        "tex":   highlight.TEX,
   18        "ansi":  highlight.ESC_ANSI,
   19        "xterm256": highlight.ESC_XTERM256,
   20        "truecolor": highlight.ESC_TRUECOLOR,
   21        "odt":   highlight.ODTFLAT,
   22        "bbcode":   highlight.BBCODE,
   23        "svg":   highlight.SVG,
   24        "pango": highlight.PANGO
   25      }
   26 
   27 HL_DIR="/usr/share/highlight/"
   28 
   29 def highlightFile():
   30 
   31     parser = OptionParser("usage: %prog [options] input-file output-file")
   32     parser.add_option("-O", "--format", default="html",
   33                     choices=("html","xhtml","latex","tex","rtf","ansi","xterm256", "svg", "odt", "bbcode", "pango", "truecolor"),
   34             help="Output format (html, xhtml, latex, tex, rtf, ansi, xterm256, truecolor, odt, bbcode, svg, pango)")
   35     parser.add_option("-d", "--doc-title", default="Source file",
   36             help="document title")
   37     parser.add_option("-f", "--fragment", action="store_true", default = False, 
   38             help="omit file header and footer")
   39     parser.add_option("-F", "--reformat",
   40             choices=('allman','gnu','java','kr','linux', 'banner','stroustrup','whitesmith', 'google', 'pico', 'lisp', 'vtk'),
   41             help="reformats and indents output in given style")
   42     parser.add_option("-l", "--linenumbers", action="store_true", default = False,
   43             help="print line numbers in output file")
   44     parser.add_option("-S", "--syntax",
   45             help="specify type of source code")
   46     parser.add_option("-s", "--theme", default="seashell",
   47             help="defines colour theme")
   48     parser.add_option("-u", "--encoding", default="ISO-8859-1",
   49             help="define output encoding which matches input file encoding")
   50 
   51     (options, args) = parser.parse_args(sys.argv[1:])
   52     if len(args)!=2:
   53         parser.print_help()
   54         return
   55 
   56     formatName=options.format.lower()
   57     outFormat = formatName in formatList and formatList[formatName] or highlight.HTML
   58 
   59     (infile, outfile) = args
   60 
   61     gen=highlight.CodeGenerator.getInstance(outFormat)
   62     datadir=highlight.DataDir()
   63     datadir.initSearchDirectories(HL_DIR)
   64 
   65     #initialize the generator with a colour theme and the language definition
   66     gen.initTheme(datadir.getThemePath("%s.theme" % options.theme))
   67 
   68     if options.reformat:
   69         gen.initIndentationScheme(options.reformat)
   70 
   71     if (options.syntax):
   72         syntax = options.syntax
   73     else:
   74         syntax = infile[infile.rindex(".")+1:]
   75 
   76     gen.loadLanguage(datadir.getLangPath("%s.lang" % syntax))
   77 
   78     gen.setIncludeStyle(True)
   79     gen.setTitle(options.doc_title)
   80     gen.setFragmentCode(options.fragment)
   81     gen.setPrintLineNumbers(options.linenumbers)
   82     gen.setEncoding(options.encoding)
   83 
   84     gen.generateFile(infile, outfile)
   85 
   86     # clear the instance
   87     highlight.CodeGenerator.deleteInstance(gen)
   88 
   89 ###############################################################################
   90 if __name__ == "__main__":
   91     highlightFile()
   92