Package: ice35-translators Version: 3.5.1-6+b3 Severity: important Tags: upstream patch
When there are nested modules in the slice files, slice2py generate python code not compatible with python 3.x because it uses implicit relative import. The bug was reported on upstream forums and upstream provided a patch which we applied and tested successfully on the Debian version. The forum thread is here : https://zeroc.com/forums/bug-reports/6186-slice2py- generates-code-not-usable-python-3-3-a.html -- System Information: Debian Release: 8.1 APT prefers stable-updates APT policy: (500, 'stable-updates'), (500, 'stable') Architecture: amd64 (x86_64) Foreign Architectures: i386 Kernel: Linux 3.16.0-4-amd64 (SMP w/1 CPU core) Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Init: systemd (via /run/systemd/system) Versions of packages ice35-translators depends on: ii libc6 2.19-18 ii libgcc1 1:4.9.2-10 ii libiceutil35 3.5.1-6+b3 ii libslice35 3.5.1-6+b3 ii libstdc++6 4.9.2-10 ice35-translators recommends no packages. ice35-translators suggests no packages. -- no debconf information
diff --git a/cpp/src/slice2py/Main.cpp b/cpp/src/slice2py/Main.cpp index 0bb4efe..cd37d02 100644 --- a/cpp/src/slice2py/Main.cpp +++ b/cpp/src/slice2py/Main.cpp @@ -306,9 +306,40 @@ PackageVisitor::readInit(const string& dir, StringList& modules, StringList& sub } else { + // + // This case occurs in old (Ice <= 3.5.1) code that used implicit + // relative imports, such as: + // + // File: outer/__init__.py + // + // import inner + // + // These aren't supported in Python 3. We'll translate these into + // explicit relative imports: + // + // from . import inner + // submodules.push_back(name); } } + else if(s.find("from . import") == 0) + { + if(state != InSubmodules) + { + ostringstream os; + os << "invalid line `" << s << "' in `" << initPath << "'"; + throw os.str(); + } + + if(s.size() < 15) + { + ostringstream os; + os << "invalid line `" << s << "' in `" << initPath << "'"; + throw os.str(); + } + + submodules.push_back(s.substr(14)); + } } if(state != InSubmodules) @@ -351,7 +382,7 @@ PackageVisitor::writeInit(const string& dir, const string& name, const StringLis os << _submoduleTag << endl; for(StringList::const_iterator p = submodules.begin(); p != submodules.end(); ++p) { - os << "import " << *p << endl; + os << "from . import " << *p << endl; } }