Login   Register  
PHP Classes
elePHPant
Icontem

File: testpy.py

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Andrea Giammarchi  >  SourceMap  >  testpy.py  >  Download  
File: testpy.py
Role: Auxiliary data
Content type: text/plain
Description: Python Test File
Class: SourceMap
Tokenize source code in several languages
Author: By
Last change:
Date: 8 years ago
Size: 1,571 bytes
 

Contents

Class file image Download
# import of necessary files
from SourceMap import *
from delimeters import *
from common import *

# SourceMap variable
sourceMap = SourceMap()

# chosed delimeter rules (JavaScript in this case)
rules = jsRules

# source code to map [requires specified JS file]
source = file_get_contents("dojo.js.uncompressed.js")

# Benchmark: start time variable
startTime = getTime(None)

# generated map
codeMap = sourceMap.getMap(source, rules)

# Benchmark: end time variable
endTime = getTime(startTime)

# External output and Verify
tempCode = ""
correctParse = ""
output = ""
b = len(codeMap)
for a in range(0, b):
	tempCode = source[codeMap[a]["start"]:codeMap[a]["end"]]
	correctParse = correctParse + tempCode
	output = output + "<strong>" + codeMap[a]["name"] + "</strong><pre>" + tempCode.replace("<", "&lt;").replace(">", "&gt;") + "</pre>"
	if a + 1 < b:
		output = output + "<hr />";
if correctParse == source:
	output = "<h3>Source file successfull mapped [" + str(endTime) + " sec.] - Map length: " + str(b) + "</h3><hr />" + output
else:
	output = "<h3>WARNING, map failure or invalid source code [" + str(endTime) + " sec.] - Map length: " + str(b) + "</h3><hr />" + output
output = """<html>
	<head>
		<title>Class SourceMap :: Python Version</title>
		<style type="text/css">
		* {
			margin:2;
			padding:0;
			font-family: Verdana, Helvetica, sans-serif;
			font-size: 8pt;
		}
		</style>
	</head>
	<body>
		""" + output + """
	</body>
</html>"""
fp = file("testpy.html", "w")
fp.write(output)
fp.close()