From d9bf22a0e29c2a70049443a0ae8521a2c0492c8b Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Sun, 11 Dec 2011 06:38:23 -0500 Subject: initial commit for git repository --- .../openid-php-openid-782224d/admin/phpaliases.py | 119 +++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 models/openid-php-openid-782224d/admin/phpaliases.py (limited to 'models/openid-php-openid-782224d/admin/phpaliases.py') diff --git a/models/openid-php-openid-782224d/admin/phpaliases.py b/models/openid-php-openid-782224d/admin/phpaliases.py new file mode 100644 index 000000000..c4ce21684 --- /dev/null +++ b/models/openid-php-openid-782224d/admin/phpaliases.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python + +"""This script searches files for functions that are just aliases in +PHP source code. This is not 100% reliable, so it should not be +automated, but it's useful to run once in a while to make sure that +all of the matches it finds are not really legitimate aliases. + +Usage: + + parse_aliases.py [PHP source code filename]... +""" + +import sys + +# Fetch this URL to get the file that is parsed into the aliases list +alias_url = 'http://www.zend.com/phpfunc/all_aliases.php' + +header_tok = ''; +footer_tok = ''; + +# Example line of the table that we parse: +# 'bzclosephp-src/ext/bz2/bz2.cfclose' + +import re + +line_re = re.compile(r''' +\A + +]+"> + +([^<>]+) + +]+">[^<>]+ + + +(?: + ]+\.php"> + ( [^<>]+ ) + +| ( [^<>]+ ) +) + + + + +\Z +''', re.VERBOSE) + +def parseString(s): + _, rest = s.split(header_tok, 1) + body, _ = rest.split(footer_tok, 1) + + lines = body.split('\n') + assert [s.strip() for s in lines[-2:]] == ['', ''] + assert lines[0].strip().startswith('|\$|)\s*\b(%s)\b' % ('|'.join(aliases.keys()))) + +def checkAliasesFile(alias_re, f): + found = [] + line_num = 1 + for line in f: + for mo in alias_re.finditer(line): + if mo.group(1): + continue + alias = mo.group(2) + found.append((line_num, alias)) + line_num += 1 + return found + +def checkAliases(alias_re, filename): + return checkAliasesFile(alias_re, file(filename, 'r')) + +def checkAliasesFiles(alias_re, filenames): + found = [] + for filename in filenames: + file_found = checkAliases(alias_re, filename) + found.extend([(filename, n, a) for (n, a) in file_found]) + return found + +def dumpResults(aliases, found, out=sys.stdout): + for filename, n, a in found: + print >>out, "%s:%d %s -> %s" % (filename, n, a, aliases[a]) + +def main(alias_file, *filenames): + aliases = parseFileName(alias_file) + alias_re = getAliasRE(aliases) + found = checkAliasesFiles(alias_re, filenames) + dumpResults(aliases, found) + return found + +if __name__ == '__main__': + found = main(*sys.argv[1:]) + if found: + sys.exit(1) -- cgit v1.2.3