diff options
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/freeze/freeze.py | 2 | ||||
-rw-r--r-- | Tools/importbench/importbench.py | 31 | ||||
-rw-r--r-- | Tools/msi/msi.py | 4 | ||||
-rw-r--r-- | Tools/parser/unparse.py | 3 | ||||
-rw-r--r-- | Tools/scripts/parse_html5_entities.py | 105 | ||||
-rwxr-xr-x | Tools/stringbench/stringbench.py | 2 | ||||
-rw-r--r-- | Tools/unicode/makeunicodedata.py | 2 |
7 files changed, 126 insertions, 23 deletions
diff --git a/Tools/freeze/freeze.py b/Tools/freeze/freeze.py index a41267a..769a2d1 100755 --- a/Tools/freeze/freeze.py +++ b/Tools/freeze/freeze.py @@ -125,7 +125,7 @@ def main(): # default the exclude list for each platform if win: exclude = exclude + [ 'dos', 'dospath', 'mac', 'macpath', 'macfs', 'MACFS', 'posix', - 'os2', 'ce', + 'ce', ] fail_import = exclude[:] diff --git a/Tools/importbench/importbench.py b/Tools/importbench/importbench.py index 714c0e4..635dd56 100644 --- a/Tools/importbench/importbench.py +++ b/Tools/importbench/importbench.py @@ -46,8 +46,7 @@ def from_cache(seconds, repeat): module.__package__ = '' with util.uncache(name): sys.modules[name] = module - for result in bench(name, repeat=repeat, seconds=seconds): - yield result + yield from bench(name, repeat=repeat, seconds=seconds) def builtin_mod(seconds, repeat): @@ -56,9 +55,8 @@ def builtin_mod(seconds, repeat): if name in sys.modules: del sys.modules[name] # Relying on built-in importer being implicit. - for result in bench(name, lambda: sys.modules.pop(name), repeat=repeat, - seconds=seconds): - yield result + yield from bench(name, lambda: sys.modules.pop(name), repeat=repeat, + seconds=seconds) def source_wo_bytecode(seconds, repeat): @@ -73,9 +71,8 @@ def source_wo_bytecode(seconds, repeat): loader = (importlib.machinery.SourceFileLoader, importlib.machinery.SOURCE_SUFFIXES, True) sys.path_hooks.append(importlib.machinery.FileFinder.path_hook(loader)) - for result in bench(name, lambda: sys.modules.pop(name), repeat=repeat, - seconds=seconds): - yield result + yield from bench(name, lambda: sys.modules.pop(name), repeat=repeat, + seconds=seconds) finally: sys.dont_write_bytecode = False @@ -89,9 +86,8 @@ def _wo_bytecode(module): os.unlink(bytecode_path) sys.dont_write_bytecode = True try: - for result in bench(name, lambda: sys.modules.pop(name), - repeat=repeat, seconds=seconds): - yield result + yield from bench(name, lambda: sys.modules.pop(name), + repeat=repeat, seconds=seconds) finally: sys.dont_write_bytecode = False @@ -127,8 +123,7 @@ def _writing_bytecode(module): def cleanup(): sys.modules.pop(name) os.unlink(imp.cache_from_source(module.__file__)) - for result in bench(name, cleanup, repeat=repeat, seconds=seconds): - yield result + yield from bench(name, cleanup, repeat=repeat, seconds=seconds) writing_bytecode_benchmark.__doc__ = ( writing_bytecode_benchmark.__doc__.format(name)) @@ -148,9 +143,8 @@ def source_using_bytecode(seconds, repeat): sys.path_hooks.append(importlib.machinery.FileFinder.path_hook(loader)) py_compile.compile(mapping[name]) assert os.path.exists(imp.cache_from_source(mapping[name])) - for result in bench(name, lambda: sys.modules.pop(name), repeat=repeat, - seconds=seconds): - yield result + yield from bench(name, lambda: sys.modules.pop(name), repeat=repeat, + seconds=seconds) def _using_bytecode(module): @@ -158,9 +152,8 @@ def _using_bytecode(module): def using_bytecode_benchmark(seconds, repeat): """Source w/ bytecode: {}""" py_compile.compile(module.__file__) - for result in bench(name, lambda: sys.modules.pop(name), repeat=repeat, - seconds=seconds): - yield result + yield from bench(name, lambda: sys.modules.pop(name), repeat=repeat, + seconds=seconds) using_bytecode_benchmark.__doc__ = ( using_bytecode_benchmark.__doc__.format(name)) diff --git a/Tools/msi/msi.py b/Tools/msi/msi.py index 2ec6951..cd1c60b 100644 --- a/Tools/msi/msi.py +++ b/Tools/msi/msi.py @@ -99,7 +99,9 @@ extensions = [ '_multiprocessing.pyd', '_lzma.pyd', '_decimal.pyd', - '_testbuffer.pyd' + '_testbuffer.pyd', + '_sha3.pyd', + '_testimportmultiple.pyd', ] # Well-known component UUIDs diff --git a/Tools/parser/unparse.py b/Tools/parser/unparse.py index b55e2c6..28b2d5b 100644 --- a/Tools/parser/unparse.py +++ b/Tools/parser/unparse.py @@ -307,6 +307,9 @@ class Unparser: def _Name(self, t): self.write(t.id) + def _NameConstant(self, t): + self.write(repr(t.value)) + def _Num(self, t): # Substitute overflowing decimal literal for AST infinities. self.write(repr(t.n).replace("inf", INFSTR)) diff --git a/Tools/scripts/parse_html5_entities.py b/Tools/scripts/parse_html5_entities.py new file mode 100644 index 0000000..c011328 --- /dev/null +++ b/Tools/scripts/parse_html5_entities.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python3 +""" +Utility for parsing HTML5 entity definitions available from: + + http://dev.w3.org/html5/spec/entities.json + +Written by Ezio Melotti and Iuliia Proskurnia. + +""" + +import os +import sys +import json +from urllib.request import urlopen +from html.entities import html5 + +entities_url = 'http://dev.w3.org/html5/spec/entities.json' + +def get_json(url): + """Download the json file from the url and returns a decoded object.""" + with urlopen(url) as f: + data = f.read().decode('utf-8') + return json.loads(data) + +def create_dict(entities): + """Create the html5 dict from the decoded json object.""" + new_html5 = {} + for name, value in entities.items(): + new_html5[name.lstrip('&')] = value['characters'] + return new_html5 + +def compare_dicts(old, new): + """Compare the old and new dicts and print the differences.""" + added = new.keys() - old.keys() + if added: + print('{} entitie(s) have been added:'.format(len(added))) + for name in sorted(added): + print(' {!r}: {!r}'.format(name, new[name])) + removed = old.keys() - new.keys() + if removed: + print('{} entitie(s) have been removed:'.format(len(removed))) + for name in sorted(removed): + print(' {!r}: {!r}'.format(name, old[name])) + changed = set() + for name in (old.keys() & new.keys()): + if old[name] != new[name]: + changed.add((name, old[name], new[name])) + if changed: + print('{} entitie(s) have been modified:'.format(len(changed))) + for item in sorted(changed): + print(' {!r}: {!r} -> {!r}'.format(*item)) + +def write_items(entities, file=sys.stdout): + """Write the items of the dictionary in the specified file.""" + # The keys in the generated dictionary should be sorted + # in a case-insensitive way, however, when two keys are equal, + # the uppercase version should come first so that the result + # looks like: ['Aacute', 'aacute', 'Aacute;', 'aacute;', ...] + # To do this we first sort in a case-sensitive way (so all the + # uppercase chars come first) and then sort with key=str.lower. + # Since the sorting is stable the uppercase keys will eventually + # be before their equivalent lowercase version. + keys = sorted(entities.keys()) + keys = sorted(keys, key=str.lower) + print('html5 = {', file=file) + for name in keys: + print(' {!r}: {!a},'.format(name, entities[name]), file=file) + print('}', file=file) + + +if __name__ == '__main__': + # without args print a diff between html.entities.html5 and new_html5 + # with --create print the new html5 dict + # with --patch patch the Lib/html/entities.py file + new_html5 = create_dict(get_json(entities_url)) + if '--create' in sys.argv: + print('# map the HTML5 named character references to the ' + 'equivalent Unicode character(s)') + print('# Generated by {}. Do not edit manually.'.format(__file__)) + write_items(new_html5) + elif '--patch' in sys.argv: + fname = 'Lib/html/entities.py' + temp_fname = fname + '.temp' + with open(fname) as f1, open(temp_fname, 'w') as f2: + skip = False + for line in f1: + if line.startswith('html5 = {'): + write_items(new_html5, file=f2) + skip = True + continue + if skip: + # skip the old items until the } + if line.startswith('}'): + skip = False + continue + f2.write(line) + os.remove(fname) + os.rename(temp_fname, fname) + else: + if html5 == new_html5: + print('The current dictionary is updated.') + else: + compare_dicts(html5, new_html5) + print('Run "./python {0} --patch" to update Lib/html/entities.html ' + 'or "./python {0} --create" to see the generated ' 'dictionary.'.format(__file__)) diff --git a/Tools/stringbench/stringbench.py b/Tools/stringbench/stringbench.py index a0a21fa..c72e16d 100755 --- a/Tools/stringbench/stringbench.py +++ b/Tools/stringbench/stringbench.py @@ -808,7 +808,7 @@ standard libraries, and can be learned in a few days. Many Python programmers report substantial productivity gains and feel the language encourages the development of higher quality, more maintainable code. -Python runs on Windows, Linux/Unix, Mac OS X, OS/2, Amiga, Palm +Python runs on Windows, Linux/Unix, Mac OS X, Amiga, Palm Handhelds, and Nokia mobile phones. Python has also been ported to the Java and .NET virtual machines. diff --git a/Tools/unicode/makeunicodedata.py b/Tools/unicode/makeunicodedata.py index d83cf63..2f8e620 100644 --- a/Tools/unicode/makeunicodedata.py +++ b/Tools/unicode/makeunicodedata.py @@ -37,7 +37,7 @@ SCRIPT = sys.argv[0] VERSION = "3.2" # The Unicode Database -UNIDATA_VERSION = "6.1.0" +UNIDATA_VERSION = "6.2.0" UNICODE_DATA = "UnicodeData%s.txt" COMPOSITION_EXCLUSIONS = "CompositionExclusions%s.txt" EASTASIAN_WIDTH = "EastAsianWidth%s.txt" |