From 4cb6d37d1d9b2463a121f5f0c6ed9aed2d3f2f9a Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sun, 13 Dec 2015 20:00:24 -0800 Subject: assert_python_ok docstring typo fix. --- Lib/test/script_helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/script_helper.py b/Lib/test/script_helper.py index b29392f..d27496b 100644 --- a/Lib/test/script_helper.py +++ b/Lib/test/script_helper.py @@ -107,7 +107,7 @@ def assert_python_ok(*args, **env_vars): variables `env_vars` succeeds (rc == 0) and return a (return code, stdout, stderr) tuple. - If the __cleanenv keyword is set, env_vars is used a fresh environment. + If the __cleanenv keyword is set, env_vars is used as a fresh environment. Python is started in isolated mode (command line option -I), except if the __isolated keyword is set to False. -- cgit v0.12 From 220ba72c20869975ee9e900f78c7a724db13a3ee Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sun, 13 Dec 2015 20:01:44 -0800 Subject: Fix test_cmd_line not to fail if PYTHONHASHSEED is set to a fixed seed due to test_hash_randomization expecting a different seed per process. --- Lib/test/test_cmd_line.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index cb9bbdd..5cad3ec 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -402,12 +402,24 @@ class CmdLineTest(unittest.TestCase): # Verify that -R enables hash randomization: self.verify_valid_flag('-R') hashes = [] - for i in range(2): + if os.environ.get('PYTHONHASHSEED', 'random') != 'random': + env = dict(os.environ) # copy + # We need to test that it is enabled by default without + # the environment variable enabling it for us. + del env['PYTHONHASHSEED'] + env['__cleanenv'] = '1' # consumed by assert_python_ok() + else: + env = {} + for i in range(3): code = 'print(hash("spam"))' - rc, out, err = assert_python_ok('-c', code) + rc, out, err = assert_python_ok('-c', code, **env) self.assertEqual(rc, 0) hashes.append(out) - self.assertNotEqual(hashes[0], hashes[1]) + hashes = sorted(set(hashes)) # uniq + # Rare chance of failure due to 3 random seeds honestly being equal. + self.assertGreater(len(hashes), 1, + msg='3 runs produced an identical random hash ' + ' for "spam": {}'.format(hashes)) # Verify that sys.flags contains hash_randomization code = 'import sys; print("random is", sys.flags.hash_randomization)' -- cgit v0.12 From 0212c4dc6b061a49fd8bc8df8f1bdd8049c292ef Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sun, 13 Dec 2015 20:05:55 -0800 Subject: Re-fix issue #19284: Don't generate the no-op -R command line parameter to "enable" the always on sys.flags.hash_randomization in _args_from_interpreter_flags() used by multiprocessing and some unittests. This simplifies the code. --- Lib/subprocess.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py index abf43e5..04cfb44 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -512,14 +512,11 @@ def _args_from_interpreter_flags(): 'verbose': 'v', 'bytes_warning': 'b', 'quiet': 'q', - 'hash_randomization': 'R', } args = [] for flag, opt in flag_opt_map.items(): v = getattr(sys.flags, flag) if v > 0: - if flag == 'hash_randomization': - v = 1 # Handle specification of an exact seed args.append('-' + opt * v) for opt in sys.warnoptions: args.append('-W' + opt) -- cgit v0.12 804743e23b3f82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights.  These rights are described in the Nokia Qt LGPL
** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

//! [0]
QTextEdit *editor = new QTextEdit;
MyHighlighter *highlighter = new MyHighlighter(editor->document());
//! [0]


//! [1]
void MyHighlighter::highlightBlock(const QString &text)
{
    QTextCharFormat myClassFormat;
    myClassFormat.setFontWeight(QFont::Bold);
    myClassFormat.setForeground(Qt::darkMagenta);
    QString pattern = "\\bMy[A-Za-z]+\\b";

    QRegExp expression(pattern);
    int index = text.indexOf(expression);
    while (index >= 0) {
        int length = expression.matchedLength();
        setFormat(index, length, myClassFormat);
        index = text.indexOf(expression, index + length);
    }
}
//! [1]


//! [2]
QTextCharFormat multiLineCommentFormat;
multiLineCommentFormat.setForeground(Qt::red);

QRegExp startExpression("/\\*");
QRegExp endExpression("\\*/");

setCurrentBlockState(0);

int startIndex = 0;
if (previousBlockState() != 1)
    startIndex = text.indexOf(startExpression);

while (startIndex >= 0) {
   int endIndex = text.indexOf(endExpression, startIndex);
   int commentLength;
   if (endIndex == -1) {
       setCurrentBlockState(1);
       commentLength = text.length() - startIndex;
   } else {
       commentLength = endIndex - startIndex
                       + endExpression.matchedLength();
   }
   setFormat(startIndex, commentLength, multiLineCommentFormat);
   startIndex = text.indexOf(startExpression,
                             startIndex + commentLength);
}
//! [2]


//! [3]
void MyHighlighter::highlightBlock(const QString &text)
{
    QTextCharFormat myClassFormat;
    myClassFormat.setFontWeight(QFont::Bold);
    myClassFormat.setForeground(Qt::darkMagenta);
    QString pattern = "\\bMy[A-Za-z]+\\b";

    QRegExp expression(pattern);
    int index = text.indexOf(expression);
    while (index >= 0) {
        int length = expression.matchedLength();
        setFormat(index, length, myClassFormat);
        index = text.indexOf(expression, index + length);
     }
 }
//! [3]


//! [4]
struct ParenthesisInfo
{
    QChar char;
    int position;
};

struct BlockData : public QTextBlockUserData
{
    QVector<ParenthesisInfo> parentheses;
};
//! [4]