3326 |
3326 |
3327 |
3327 |
3328 if __name__ == '__main__': |
3328 if __name__ == '__main__': |
3329 import pprint |
3329 import pprint |
3330 import re |
3330 import re |
3331 import urllib |
3331 import urllib.request, urllib.parse, urllib.error |
3332 _function_re = re.compile('<B\s+CLASS="function"\s*>(.*?)\(\)</B\s*>(?uism)') |
3332 _function_re = re.compile('<B\s+CLASS="function"\s*>(.*?)\(\)</B\s*>(?uism)') |
3333 |
3333 |
3334 def get_php_functions(): |
3334 def get_php_functions(): |
3335 uf = urllib.urlopen('http://de.php.net/manual/en/index.functions.php') |
3335 uf = urllib.request.urlopen('http://de.php.net/manual/en/index.functions.php') |
3336 data = uf.read() |
3336 data = uf.read() |
3337 uf.close() |
3337 uf.close() |
3338 results = set() |
3338 results = set() |
3339 for match in _function_re.finditer(data): |
3339 for match in _function_re.finditer(data): |
3340 fn = match.group(1) |
3340 fn = match.group(1) |
3345 results.sort() |
3345 results.sort() |
3346 return results |
3346 return results |
3347 |
3347 |
3348 def get_function_module(func_name): |
3348 def get_function_module(func_name): |
3349 fn = func_name.replace('_', '-') |
3349 fn = func_name.replace('_', '-') |
3350 uf = urllib.urlopen('http://de.php.net/manual/en/function.%s.php' % fn) |
3350 uf = urllib.request.urlopen('http://de.php.net/manual/en/function.%s.php' % fn) |
3351 regex = re.compile('<li class="header up">' |
3351 regex = re.compile('<li class="header up">' |
3352 '<a href="ref\..*?\.php">([a-zA-Z0-9\s]+)</a></li>') |
3352 '<a href="ref\..*?\.php">([a-zA-Z0-9\s]+)</a></li>') |
3353 for line in uf: |
3353 for line in uf: |
3354 match = regex.search(line) |
3354 match = regex.search(line) |
3355 if match: |
3355 if match: |
3356 return match.group(1) |
3356 return match.group(1) |
3357 |
3357 |
3358 print '>> Downloading Function Index' |
3358 print('>> Downloading Function Index') |
3359 functions = get_php_functions() |
3359 functions = get_php_functions() |
3360 total = len(functions) |
3360 total = len(functions) |
3361 print '%d functions found' % total |
3361 print('%d functions found' % total) |
3362 modules = {} |
3362 modules = {} |
3363 idx = 1 |
3363 idx = 1 |
3364 for function_name in get_php_functions(): |
3364 for function_name in get_php_functions(): |
3365 print '>> %r (%d/%d)' % (function_name, idx, total) |
3365 print('>> %r (%d/%d)' % (function_name, idx, total)) |
3366 m = get_function_module(function_name) |
3366 m = get_function_module(function_name) |
3367 if m is None: |
3367 if m is None: |
3368 print 'NOT_FOUND' |
3368 print('NOT_FOUND') |
3369 m = 'unknown' |
3369 m = 'unknown' |
3370 else: |
3370 else: |
3371 print repr(m) |
3371 print(repr(m)) |
3372 modules.setdefault(m, []).append(function_name) |
3372 modules.setdefault(m, []).append(function_name) |
3373 idx += 1 |
3373 idx += 1 |
3374 |
3374 |
3375 # extract useful sourcecode from this file |
3375 # extract useful sourcecode from this file |
3376 f = open(__file__) |
3376 f = open(__file__) |