From 7ca78b8a8fb8db2fb4d876dc9764097ede776610 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Wed, 14 Sep 2016 10:59:27 +0300 Subject: Issue #26830: Refactor Tools/scripts/google.py Patch by Francisco Couzo. --- Tools/scripts/google.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'Tools/scripts') diff --git a/Tools/scripts/google.py b/Tools/scripts/google.py index 12152bb5f8..82fb287188 100755 --- a/Tools/scripts/google.py +++ b/Tools/scripts/google.py @@ -1,23 +1,25 @@ #! /usr/bin/env python3 -import sys, webbrowser +"""Script to search with Google -def main(): - args = sys.argv[1:] - if not args: - print("Usage: %s querystring" % sys.argv[0]) - return - list = [] - for arg in args: - if '+' in arg: - arg = arg.replace('+', '%2B') +Usage: + python3 google.py [search terms] +""" + +import sys +import urllib.parse +import webbrowser + + +def main(args): + def quote(arg): if ' ' in arg: arg = '"%s"' % arg - arg = arg.replace(' ', '+') - list.append(arg) - s = '+'.join(list) - url = "http://www.google.com/search?q=%s" % s + return urllib.parse.quote_plus(arg) + + qstring = '+'.join(quote(arg) for arg in args) + url = urllib.parse.urljoin('https://www.google.com/search', '?q=' + qstring) webbrowser.open(url) if __name__ == '__main__': - main() + main(sys.argv[1:]) -- cgit v1.2.1 From 7e2a8d2f96760f0a214bbaac407d3cb16d0b0029 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 21 Sep 2016 17:12:50 +0200 Subject: regrtest: add -u for unbuffered stdout/stderr --- Tools/scripts/run_tests.py | 1 + 1 file changed, 1 insertion(+) (limited to 'Tools/scripts') diff --git a/Tools/scripts/run_tests.py b/Tools/scripts/run_tests.py index b582e13250..30283023b6 100644 --- a/Tools/scripts/run_tests.py +++ b/Tools/scripts/run_tests.py @@ -26,6 +26,7 @@ def is_resource_use_flag(arg): def main(regrtest_args): args = [sys.executable, + '-u', # Unbuffered stdout and stderr '-W', 'default', # Warnings set to 'default' '-bb', # Warnings about bytes/bytearray '-E', # Ignore environment variables -- cgit v1.2.1 From b8ad27d039282ea11af31b14995640a53b4e0a66 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 25 Nov 2016 11:59:52 +0100 Subject: Fix a ResourceWarning in generate_opcode_h.py Use a context manager to close the Python file. Replace also open() with tokenize.open() to handle coding cookie if any in Lib/opcode.py. --- Tools/scripts/generate_opcode_h.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Tools/scripts') diff --git a/Tools/scripts/generate_opcode_h.py b/Tools/scripts/generate_opcode_h.py index 948b56f900..bbc3aab553 100644 --- a/Tools/scripts/generate_opcode_h.py +++ b/Tools/scripts/generate_opcode_h.py @@ -32,10 +32,14 @@ enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py_LE, PyCmp_EQ=Py_EQ, PyCmp_NE=Py_NE, #endif /* !Py_OPCODE_H */ """ +import tokenize + def main(opcode_py, outfile='Include/opcode.h'): opcode = {} - exec(open(opcode_py).read(), opcode) + with tokenize.open(opcode_py) as fp: + code = fp.read() + exec(code, opcode) opmap = opcode['opmap'] with open(outfile, 'w') as fobj: fobj.write(header) -- cgit v1.2.1 From e6e6fa8231b3e0cb8de20c3bc4625ef1d5f775de Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 28 Nov 2016 18:13:52 +0100 Subject: Reintroduce Python2 support in generate_opcode_h.py Issue #28821. Add also a message to show that the command did something :-) --- Tools/scripts/generate_opcode_h.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'Tools/scripts') diff --git a/Tools/scripts/generate_opcode_h.py b/Tools/scripts/generate_opcode_h.py index bbc3aab553..6622a3c815 100644 --- a/Tools/scripts/generate_opcode_h.py +++ b/Tools/scripts/generate_opcode_h.py @@ -1,6 +1,8 @@ # This script generates the opcode.h header file. import sys +import tokenize + header = """/* Auto-generated by Tools/scripts/generate_opcode_h.py */ #ifndef Py_OPCODE_H #define Py_OPCODE_H @@ -32,12 +34,14 @@ enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py_LE, PyCmp_EQ=Py_EQ, PyCmp_NE=Py_NE, #endif /* !Py_OPCODE_H */ """ -import tokenize - def main(opcode_py, outfile='Include/opcode.h'): opcode = {} - with tokenize.open(opcode_py) as fp: + if hasattr(tokenize, 'open'): + fp = tokenize.open(opcode_py) # Python 3.2+ + else: + fp = open(opcode_py) # Python 2.7 + with fp: code = fp.read() exec(code, opcode) opmap = opcode['opmap'] @@ -51,6 +55,8 @@ def main(opcode_py, outfile='Include/opcode.h'): ('HAVE_ARGUMENT', opcode['HAVE_ARGUMENT'])) fobj.write(footer) + print("%s regenerated from %s" % (outfile, opcode_py)) + if __name__ == '__main__': main(sys.argv[1], sys.argv[2]) -- cgit v1.2.1