[pygobject] Fix __path__ module attribute
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Fix __path__ module attribute
- Date: Mon, 16 Jul 2012 13:39:13 +0000 (UTC)
commit f6cc039e014448a553d626aac4020ee69717edab
Author: Martin Pitt <martinpitt gnome org>
Date: Mon Jul 16 15:38:05 2012 +0200
Fix __path__ module attribute
get_typelib_path() returns bytes, not strings, so in Python 3 we need to decode
it to get a proper __path__ attribute.
gi/module.py | 17 +++++++++++++++++
tests/test_gi.py | 10 ++++++++++
2 files changed, 27 insertions(+), 0 deletions(-)
---
diff --git a/gi/module.py b/gi/module.py
index 4e60c85..566b40d 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -22,6 +22,10 @@
from __future__ import absolute_import
+import sys
+
+_have_py3 = (sys.version_info.major >= 3)
+
from . import _glib, _gobject
try:
maketrans = ''.maketrans
@@ -96,6 +100,9 @@ class IntrospectionModule(object):
repository.require(self._namespace, self._version)
self.__path__ = repository.get_typelib_path(self._namespace)
+ if _have_py3:
+ # get_typelib_path() delivers bytes, not a string
+ self.__path__ = self.__path__.decode('UTF-8')
if self._version is None:
self._version = repository.get_version(self._namespace)
@@ -200,6 +207,9 @@ class IntrospectionModule(object):
def __repr__(self):
path = repository.get_typelib_path(self._namespace)
+ if _have_py3:
+ # get_typelib_path() delivers bytes, not a string
+ path = path.decode('UTF-8')
return "<IntrospectionModule %r from %r>" % (self._namespace, path)
def __dir__(self):
@@ -230,6 +240,9 @@ class DynamicModule(object):
overrides_modules = __import__('gi.overrides', fromlist=[self._namespace])
self._overrides_module = getattr(overrides_modules, self._namespace, None)
self.__path__ = repository.get_typelib_path(self._namespace)
+ if _have_py3:
+ # get_typelib_path() delivers bytes, not a string
+ self.__path__ = self.__path__.decode('UTF-8')
def __getattr__(self, name):
if self._overrides_module is not None:
@@ -260,6 +273,10 @@ class DynamicModule(object):
def __repr__(self):
path = repository.get_typelib_path(self._namespace)
+ if _have_py3:
+ # get_typelib_path() delivers bytes, not a string
+ path = path.decode('UTF-8')
+
return "<%s.%s %r from %r>" % (self.__class__.__module__,
self.__class__.__name__,
self._namespace,
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 428e7fd..419f806 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -2250,3 +2250,13 @@ class TestKeywords(unittest.TestCase):
def test_uppercase(self):
self.assertEqual(GLib.IOCondition.IN.value_nicks, ['in'])
+
+
+class TestModule(unittest.TestCase):
+ def test_path(self):
+ self.assertTrue(GIMarshallingTests.__path__.endswith('GIMarshallingTests-1.0.typelib'),
+ GIMarshallingTests.__path__)
+
+ def test_str(self):
+ self.assertTrue("'GIMarshallingTests' from '" in str(GIMarshallingTests),
+ str(GIMarshallingTests))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]