Skip to content

Commit d085b29

Browse files
committed
rcc - fix problem with non-utf8 characters in header + pysideuic - py3k port. Original author Miroslav Jezek.
1 parent e9df594 commit d085b29

File tree

15 files changed

+262
-47
lines changed

15 files changed

+262
-47
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ option(BUILD_TESTS "Build tests." TRUE)
1818
# UIC stuff
1919
if (NOT SITE_PACKAGE)
2020
execute_process(
21-
COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; \\
22-
print sysconfig.get_python_lib(1,0,prefix='${CMAKE_INSTALL_PREFIX}')"
21+
COMMAND ${PYTHON_EXECUTABLE} -c "from __future__ import print_function; \\
22+
from distutils import sysconfig; \\
23+
print(sysconfig.get_python_lib(1,0,prefix='${CMAKE_INSTALL_PREFIX}'))"
2324
OUTPUT_VARIABLE SITE_PACKAGE
2425
OUTPUT_STRIP_TRAILING_WHITESPACE)
2526
if (NOT SITE_PACKAGE)

pylupdate/main.cpp

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -101,34 +101,6 @@ static void updateTsFiles( const MetaTranslator& fetchedTor,
101101
}
102102
}
103103

104-
/* The filename may contain double quotes when passing filenames with
105-
* whitespaces. So we need to make it proper to be called with fopen()
106-
* function. Handle them properly.
107-
*/
108-
static inline const QStringList parseFileNames(const QString& line)
109-
{
110-
QStringList retval;
111-
112-
QString s;
113-
unsigned int count = 0;
114-
foreach(QChar c, line) {
115-
if (c == '"') { /* we're still walking through the path... */
116-
count++;
117-
} else if (c.isSpace() && !(count % 2)) { /* path is done! */
118-
/* append it to our list */
119-
retval << s;
120-
s.clear();
121-
} else {
122-
s += c;
123-
}
124-
}
125-
126-
if (s.size())
127-
retval << s; /* append the last path to our list */
128-
129-
return retval;
130-
}
131-
132104
int main( int argc, char **argv )
133105
{
134106
QString defaultContext = "@default";
@@ -208,9 +180,9 @@ int main( int argc, char **argv )
208180
QMap<QString, QString>::Iterator it;
209181

210182
for ( it = tagMap.begin(); it != tagMap.end(); ++it ) {
211-
QStringList toks = parseFileNames(it.value());
212-
183+
QStringList toks = it.value().split(' ');
213184
QStringList::Iterator t;
185+
214186
for ( t = toks.begin(); t != toks.end(); ++t ) {
215187
if ( it.key() == "SOURCES" ) {
216188
fetchtr_py( (*t).toAscii(), &fetchedTor, defaultContext.toAscii(), true, codecForSource );

pyrcc/rcc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ RCCResourceLibrary::writeHeader(FILE *out)
398398
fprintf(out, "# -*- coding: utf-8 -*-\n\n");
399399
fprintf(out, "# Resource object code\n");
400400
fprintf(out, "#\n");
401-
fprintf(out, "# Created: %s\n", QDateTime::currentDateTime().toString().toLatin1().constData());
401+
fprintf(out, "# Created: %s\n", QDateTime::currentDateTime().toString().toUtf8().constData());
402402
fprintf(out, "# by: The Resource Compiler for PySide (Qt v%s)\n", QT_VERSION_STR);
403403
fprintf(out, "#\n");
404404
fprintf(out, "# WARNING! All changes made in this file will be lost!\n");

pyside-uic

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ from pysideuic import __version__ as PySideUicVersion
3232
Version = "PySide User Interface Compiler version %s, running on PySide %s." % (PySideUicVersion, PySideVersion)
3333

3434
def main():
35-
from pysideuic.port_v2.invoke import invoke
35+
if sys.hexversion >= 0x03000000:
36+
from pysideuic.port_v3.invoke import invoke
37+
else:
38+
from pysideuic.port_v2.invoke import invoke
3639

3740
parser = optparse.OptionParser(usage="pyside-uic [options] <ui-file>",
3841
version=Version)

pysideuic/Compiler/qtproxies.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@
2727
from pysideuic.Compiler.indenter import write_code
2828
from pysideuic.Compiler.misc import Literal, moduleMember
2929

30-
from pysideuic.port_v2.proxy_base import ProxyBase
31-
from pysideuic.port_v2.as_string import as_string
30+
if sys.hexversion >= 0x03000000:
31+
from pysideuic.port_v3.proxy_base import ProxyBase
32+
from pysideuic.port_v3.as_string import as_string
33+
else:
34+
from pysideuic.port_v2.proxy_base import ProxyBase
35+
from pysideuic.port_v2.as_string import as_string
3236

3337
i18n_strings = []
3438
i18n_context = ""

pysideuic/objcreator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
import os.path
2525

2626
from pysideuic.exceptions import NoSuchWidgetError, WidgetPluginError
27-
from port_v2.load_plugin import load_plugin
27+
28+
if sys.hexversion >= 0x03000000:
29+
from pysideuic.port_v3.load_plugin import load_plugin
30+
else:
31+
from pysideuic.port_v2.load_plugin import load_plugin
2832

2933

3034
# The list of directories that are searched for widget plugins. This is

pysideuic/port_v3/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This file is part of the PySide project.
2+
#
3+
# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4+
# Copyright (C) 2010 Riverbank Computing Limited.
5+
#
6+
# Contact: PySide team <[email protected]>
7+
#
8+
# This program is free software; you can redistribute it and/or
9+
# modify it under the terms of the GNU General Public License
10+
# version 2 as published by the Free Software Foundation.
11+
#
12+
# This program is distributed in the hope that it will be useful, but
13+
# WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
# General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program; if not, write to the Free Software
19+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
# 02110-1301 USA

pysideuic/port_v3/as_string.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# This file is part of the PySide project.
2+
#
3+
# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4+
# Copyright (C) 2010 Riverbank Computing Limited.
5+
#
6+
# Contact: PySide team <[email protected]>
7+
#
8+
# This program is free software; you can redistribute it and/or
9+
# modify it under the terms of the GNU General Public License
10+
# version 2 as published by the Free Software Foundation.
11+
#
12+
# This program is distributed in the hope that it will be useful, but
13+
# WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
# General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program; if not, write to the Free Software
19+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
# 02110-1301 USA
21+
22+
import re
23+
24+
25+
def as_string(obj, encode=True):
26+
if isinstance(obj, str):
27+
s = '"' + _escape(obj) + '"'
28+
29+
return s
30+
31+
return str(obj)
32+
33+
34+
_esc_regex = re.compile(r"(\"|\'|\\)")
35+
36+
def _escape(text):
37+
# This escapes any escaped single or double quote or backslash.
38+
x = _esc_regex.sub(r"\\\1", text)
39+
40+
# This replaces any '\n' with an escaped version and a real line break.
41+
return re.sub(r'\n', r'\\n"\n"', x)

pysideuic/port_v3/ascii_upper.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file is part of the PySide project.
2+
#
3+
# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4+
# Copyright (C) 2010 Riverbank Computing Limited.
5+
#
6+
# Contact: PySide team <[email protected]>
7+
#
8+
# This program is free software; you can redistribute it and/or
9+
# modify it under the terms of the GNU General Public License
10+
# version 2 as published by the Free Software Foundation.
11+
#
12+
# This program is distributed in the hope that it will be useful, but
13+
# WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
# General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program; if not, write to the Free Software
19+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
# 02110-1301 USA
21+
22+
23+
# A translation table for converting ASCII lower case to upper case.
24+
_ascii_trans_table = bytes.maketrans(b'abcdefghijklmnopqrstuvwxyz',
25+
b'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
26+
27+
28+
# Convert a string to ASCII upper case irrespective of the current locale.
29+
def ascii_upper(s):
30+
return s.translate(_ascii_trans_table)

pysideuic/port_v3/invoke.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This file is part of the PySide project.
2+
#
3+
# Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies).
4+
# Copyright (C) 2010 Riverbank Computing Limited.
5+
# Copyright (C) 2009 Torsten Marek
6+
#
7+
# Contact: PySide team <[email protected]>
8+
#
9+
# This program is free software; you can redistribute it and/or
10+
# modify it under the terms of the GNU General Public License
11+
# version 2 as published by the Free Software Foundation.
12+
#
13+
# This program is distributed in the hope that it will be useful, but
14+
# WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
# General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with this program; if not, write to the Free Software
20+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21+
# 02110-1301 USA
22+
23+
from pysideuic.exceptions import NoSuchWidgetError
24+
25+
26+
def invoke(driver):
27+
""" Invoke the given command line driver. Return the exit status to be
28+
passed back to the parent process.
29+
"""
30+
31+
exit_status = 1
32+
33+
try:
34+
exit_status = driver.invoke()
35+
36+
except IOError as e:
37+
driver.on_IOError(e)
38+
39+
except SyntaxError as e:
40+
driver.on_SyntaxError(e)
41+
42+
except NoSuchWidgetError as e:
43+
driver.on_NoSuchWidgetError(e)
44+
45+
except Exception as e:
46+
driver.on_Exception(e)
47+
48+
return exit_status

0 commit comments

Comments
 (0)