Mon, 25 Mar 2013 03:28:43 +0100
Minimum modifications to start Eric5 with Py2.
--- a/Debugger/DebugServer.py Mon Mar 25 03:11:06 2013 +0100 +++ b/Debugger/DebugServer.py Mon Mar 25 03:28:43 2013 +0100 @@ -178,8 +178,16 @@ self.debugging = False self.running = False self.clientProcess = None + self.clientType = \ - Preferences.Prefs.settings.value('DebugClient/Type', 'Python3') + Preferences.Prefs.settings.value('DebugClient/Type') + if self.clientType == None: + import sys + if sys.version_info[0] == 2: + self.clientType = 'Python2' + else: + self.clientType = 'Python3' + self.lastClientType = '' self.__autoClearShell = False
--- a/PluginManager/PluginInstallDialog.py Mon Mar 25 03:11:06 2013 +0100 +++ b/PluginManager/PluginInstallDialog.py Mon Mar 25 03:28:43 2013 +0100 @@ -14,7 +14,10 @@ import shutil import zipfile import compileall -import urllib.parse +try: #Py3 + import urllib.parse as parse +except (ImportError): + import urlparse as parse from PyQt4.QtCore import pyqtSlot, Qt, QDir, QFileInfo from PyQt4.QtGui import QWidget, QDialogButtonBox, QAbstractButton, QApplication, \ @@ -247,7 +250,7 @@ self.destinationCombo.itemData(self.destinationCombo.currentIndex()) # check if archive is a local url - url = urllib.parse.urlparse(archive) + url = parse.urlparse(archive) if url[0].lower() == 'file': archive = url[2] @@ -429,7 +432,7 @@ self.trUtf8("Error installing plugin. Reason: {0}").format(str(why)), \ False except: - print("Unspecific exception installing plugin.", file=sys.stderr) + sys.stderr.write("Unspecific exception installing plugin.\n") self.__rollback() return False, \ self.trUtf8("Unspecific exception installing plugin."), \
--- a/QScintilla/Editor.py Mon Mar 25 03:11:06 2013 +0100 +++ b/QScintilla/Editor.py Mon Mar 25 03:28:43 2013 +0100 @@ -7,6 +7,10 @@ Module implementing the editor component of the eric5 IDE. """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: + chr = unichr +except (NameError): + pass import os import re @@ -6620,7 +6624,8 @@ if not commandLine.startswith("@@"): continue - command, *args = commandLine.split() + args = commandLine.split() + command = args.pop(0) pos, l1, l2 = [int(arg) for arg in args] if command == "@@i": txt = sep.join(commands[0:l1]) + sep
--- a/UI/SymbolsWidget.py Mon Mar 25 03:11:06 2013 +0100 +++ b/UI/SymbolsWidget.py Mon Mar 25 03:28:43 2013 +0100 @@ -10,7 +10,11 @@ from __future__ import unicode_literals # __IGNORE_WARNING__ import unicodedata -import html.entities +try: # Py3 + import html.entities as html_entities +except (ImportError): + chr = unichr + import htmlentitydefs as html_entities # __IGNORE_WARNING__ from PyQt4.QtCore import pyqtSlot, pyqtSignal, QAbstractTableModel, QModelIndex, Qt, \ qVersion @@ -232,8 +236,8 @@ elif col == 2: return "0x{0:04x}".format(id) elif col == 3: - if id in html.entities.codepoint2name: - return "&{0};".format(html.entities.codepoint2name[id]) + if id in html_entities.codepoint2name: + return "&{0};".format(html_entities.codepoint2name[id]) elif col == 4: return unicodedata.name(chr(id), '').title()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Utilities/compatibility_fixes.py Mon Mar 25 03:28:43 2013 +0100 @@ -0,0 +1,89 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2013 Tobias Rzepka <tobias.rzepka@gmail.com> +# + +""" +Module implementing the open behavior of Python3 for use with Eric5. +The from Eric5 used features are emulated only. The not emulated features +should throw a NotImplementedError exception. +""" + +from __future__ import unicode_literals # __IGNORE_WARNING__ + +import __builtin__ +import codecs + + +def open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True): + return File(file, mode, buffering, encoding, errors, newline, closefd) + + +class File(file): + def __init__(self, filein, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True): + self.__encoding = encoding + self.__newline = newline + self.__closefd = closefd + if newline is not None: + if 'r' in mode: + raise NotImplementedError + else: + mode = mode.replace('t', 'b') + + if closefd == False: + raise NotImplementedError + + if errors is None: + self.__errors = 'strict' + else: + self.__errors = errors + + file.__init__(self, filein, mode, buffering) + + def read(self, n=-1): + txt = super(File, self).read(n) + if self.__encoding is None: + return txt + else: + return codecs.decode(txt, self.__encoding) + + def readline(self, limit=-1): + txt = super(File, self).readline(limit) + if self.__encoding is None: + return txt + else: + return codecs.decode(txt, self.__encoding) + + def readlines(self, hint=-1): + if self.__encoding is None: + return super(File, self).readlines(hint) + else: + return [codecs.decode(txt, self.__encoding) for txt in super(File, self).readlines(hint)] + + def write(self, txt): + if self.__encoding is not None: + txt = codecs.encode(txt, self.__encoding, self.__errors) + + if self.__newline in ['\r\n', '\r']: + txt = txt.replace('\n', self.__newline) + + super(File, self).write(txt) + + def next(self): + txt = super(File, self).next() + if self.__encoding is None: + return txt + else: + return codecs.decode(txt, self.__encoding) + + +__builtin__.open = open + +if __name__ == '__main__': + fp = open('compatibility_fixes.py', encoding='latin1') + print(fp.read()) + fp.close() + + with open('compatibility_fixes.py', encoding='UTF-8') as fp: + rlines = fp.readlines() + print(rlines[-1])
--- a/eric5.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5.py Mon Mar 25 03:28:43 2013 +0100 @@ -13,10 +13,19 @@ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + sip.setapi('QTextStream', 2) + import StringIO as io + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + import io # __IGNORE_WARNING__ + import sys import os import traceback -import io import time import logging
--- a/eric5_api.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_api.py Mon Mar 25 03:28:43 2013 +0100 @@ -13,6 +13,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import glob import os
--- a/eric5_compare.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_compare.py Mon Mar 25 03:28:43 2013 +0100 @@ -13,6 +13,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import sys
--- a/eric5_configure.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_configure.py Mon Mar 25 03:28:43 2013 +0100 @@ -11,6 +11,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import sys import os
--- a/eric5_diff.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_diff.py Mon Mar 25 03:28:43 2013 +0100 @@ -13,6 +13,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import sys
--- a/eric5_doc.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_doc.py Mon Mar 25 03:28:43 2013 +0100 @@ -13,6 +13,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import glob import os
--- a/eric5_editor.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_editor.py Mon Mar 25 03:28:43 2013 +0100 @@ -13,6 +13,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import sys import os
--- a/eric5_iconeditor.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_iconeditor.py Mon Mar 25 03:28:43 2013 +0100 @@ -13,6 +13,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import sys
--- a/eric5_plugininstall.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_plugininstall.py Mon Mar 25 03:28:43 2013 +0100 @@ -11,6 +11,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import sys
--- a/eric5_pluginrepository.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_pluginrepository.py Mon Mar 25 03:28:43 2013 +0100 @@ -11,6 +11,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import sys
--- a/eric5_pluginuninstall.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_pluginuninstall.py Mon Mar 25 03:28:43 2013 +0100 @@ -11,6 +11,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import sys
--- a/eric5_qregexp.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_qregexp.py Mon Mar 25 03:28:43 2013 +0100 @@ -13,6 +13,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import sys
--- a/eric5_re.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_re.py Mon Mar 25 03:28:43 2013 +0100 @@ -13,6 +13,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import sys
--- a/eric5_snap.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_snap.py Mon Mar 25 03:28:43 2013 +0100 @@ -12,6 +12,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import sys
--- a/eric5_sqlbrowser.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_sqlbrowser.py Mon Mar 25 03:28:43 2013 +0100 @@ -12,6 +12,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import sys
--- a/eric5_tray.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_tray.py Mon Mar 25 03:28:43 2013 +0100 @@ -13,6 +13,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import sys
--- a/eric5_trpreviewer.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_trpreviewer.py Mon Mar 25 03:28:43 2013 +0100 @@ -13,6 +13,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import sys
--- a/eric5_uipreviewer.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_uipreviewer.py Mon Mar 25 03:28:43 2013 +0100 @@ -13,6 +13,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import sys
--- a/eric5_unittest.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_unittest.py Mon Mar 25 03:28:43 2013 +0100 @@ -13,6 +13,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import sys
--- a/eric5_webbrowser.py Mon Mar 25 03:11:06 2013 +0100 +++ b/eric5_webbrowser.py Mon Mar 25 03:28:43 2013 +0100 @@ -13,6 +13,13 @@ """ from __future__ import unicode_literals # __IGNORE_WARNING__ +try: # Only for Py2 + import sip + sip.setapi('QString', 2) + sip.setapi('QVariant', 2) + import Utilities.compatibility_fixes # __IGNORE_WARNING__ +except (ImportError): + pass import sys import os