From 3109abd5187ce49cfc1da9dce285b6872b0725eb Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 23 Jan 2019 12:44:08 +0000 Subject: [PATCH] issue #477: Python <2.6 lacked rpartition(). --- mitogen/core.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/mitogen/core.py b/mitogen/core.py index d0ed0188..e6fb056d 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -307,6 +307,21 @@ def to_text(o): return UnicodeType(o) +def UnicodeType__rpartition(s, splitter): + """ + unicode.rpartition() for Python 2.4/2.5. + """ + idx = s.rfind(splitter) + if idx == -1: + return u'', u'', s + left = s[0:idx] + mid = s[idx:len(splitter)] + return left, mid, s[len(left)+len(mid)] + +if hasattr(UnicodeType, 'rpartition'): + UnicodeType__rpartition = UnicodeType.rpartition + + def has_parent_authority(msg, _stream=None): """Policy function for use with :class:`Receiver` and :meth:`Router.add_handler` that requires incoming messages to originate @@ -1051,7 +1066,8 @@ class Importer(object): _tls.running = True try: _v and LOG.debug('%r.find_module(%r)', self, fullname) - pkgname, dot, _ = fullname.rpartition('.') + fullname = to_text(fullname) + pkgname, dot, _ = UnicodeType__rpartition(fullname, '.') pkg = sys.modules.get(pkgname) if pkgname and getattr(pkg, '__loader__', None) is not self: LOG.debug('%r: %r is submodule of a package we did not load',