Merge lp:~barry/ubuntu/quantal/dbus-python/lp846044 into lp:ubuntu/quantal/dbus-python

Proposed by Barry Warsaw
Status: Needs review
Proposed branch: lp:~barry/ubuntu/quantal/dbus-python/lp846044
Merge into: lp:ubuntu/quantal/dbus-python
Diff against target: 239 lines (+209/-1)
4 files modified
debian/changelog (+7/-0)
debian/control (+2/-1)
debian/patches/fdo-bug-55899.patch (+199/-0)
debian/patches/series (+1/-0)
To merge this branch: bzr merge lp:~barry/ubuntu/quantal/dbus-python/lp846044
Reviewer Review Type Date Requested Status
Michael Vogt (community) Approve
Review via email: mp+130136@code.launchpad.net

Description of the change

Proposing mine so we can just get a diff. I have no preference whether mine or Michael's branch is merged. Both seem to address the problem, pass the tests, etc. Ultimately if possible we should wait until upstream makes a commit to its trunk, and then use that patch.

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

Thanks, that looks great. I uploaded this to quantal-proposed some days ago already and will now upload to raring.

review: Approve

Unmerged revisions

41. By Barry Warsaw

debian/patches/fdo-bug-55899.patch: Support Unicode DBusExceptions
in Python 2. (LP: #846044)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2012-06-25 17:35:50 +0000
3+++ debian/changelog 2012-10-17 14:55:32 +0000
4@@ -1,3 +1,10 @@
5+dbus-python (1.1.1-1ubuntu1) quantal-proposed; urgency=low
6+
7+ * debian/patches/fdo-bug-55899.patch: Support Unicode DBusExceptions
8+ in Python 2. (LP: #846044)
9+
10+ -- Barry Warsaw <barry@ubuntu.com> Tue, 16 Oct 2012 15:25:00 -0400
11+
12 dbus-python (1.1.1-1) unstable; urgency=low
13
14 * New upstream version
15
16=== modified file 'debian/control'
17--- debian/control 2012-06-25 17:35:50 +0000
18+++ debian/control 2012-10-17 14:55:32 +0000
19@@ -1,7 +1,8 @@
20 Source: dbus-python
21 Section: devel
22 Priority: optional
23-Maintainer: Utopia Maintenance Team <pkg-utopia-maintainers@lists.alioth.debian.org>
24+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
25+XSBC-Original-Maintainer: Utopia Maintenance Team <pkg-utopia-maintainers@lists.alioth.debian.org>
26 Uploaders: Sjoerd Simons <sjoerd@debian.org>,
27 Sebastian Dröge <slomo@debian.org>,
28 Simon McVittie <smcv@debian.org>,
29
30=== added directory 'debian/patches'
31=== added file 'debian/patches/fdo-bug-55899.patch'
32--- debian/patches/fdo-bug-55899.patch 1970-01-01 00:00:00 +0000
33+++ debian/patches/fdo-bug-55899.patch 2012-10-17 14:55:32 +0000
34@@ -0,0 +1,199 @@
35+From 09b540bd55fb2fca14d4df7e0c520b8ba0ce4646 Mon Sep 17 00:00:00 2001
36+From: Michael Vogt <mvo@ubuntu.com>
37+Date: Fri, 12 Oct 2012 13:37:51 +0200
38+Subject: [PATCH 1/5] Support unicode messages for DBusException in
39+Python 2
40+
41+[commit message amended -smcv]
42+Bug: https://bugs.freedesktop.org/show_bug.cgi?id=55899
43+Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
44+
45+Barry: actually includes patches 1-5/5.
46+
47+--- a/dbus/exceptions.py
48++++ b/dbus/exceptions.py
49+@@ -27,6 +27,8 @@
50+ 'IntrospectionParserException', 'UnknownMethodException',
51+ 'NameExistsException')
52+
53++from dbus._compat import is_py3
54++
55+
56+ class DBusException(Exception):
57+
58+@@ -49,7 +51,22 @@
59+ % ', '.join(kwargs.keys()))
60+ Exception.__init__(self, *args)
61+
62++ def __unicode__(self):
63++ """Return a unicode error"""
64++ # We can't just use Exception.__unicode__ because it chains up weirdly.
65++ # https://code.launchpad.net/~mvo/ubuntu/quantal/dbus-python/lp846044/+merge/129214
66++ if len(self.args) > 1:
67++ s = unicode(self.args)
68++ else:
69++ s = ''.join(self.args)
70++
71++ if self._dbus_error_name is not None:
72++ return '%s: %s' % (self._dbus_error_name, s)
73++ else:
74++ return s
75++
76+ def __str__(self):
77++ """Return a str error"""
78+ s = Exception.__str__(self)
79+ if self._dbus_error_name is not None:
80+ return '%s: %s' % (self._dbus_error_name, s)
81+@@ -57,9 +74,17 @@
82+ return s
83+
84+ def get_dbus_message(self):
85+- s = Exception.__str__(self)
86++ if len(self.args) > 1:
87++ if is_py3:
88++ s = str(self.args)
89++ else:
90++ s = unicode(self.args)
91++ else:
92++ s = ''.join(self.args)
93++
94+ if isinstance(s, bytes):
95+ return s.decode('utf-8', 'replace')
96++
97+ return s
98+
99+ def get_dbus_name(self):
100+--- a/test/run-test.sh
101++++ b/test/run-test.sh
102+@@ -67,6 +67,12 @@
103+ echo "PYTHONPATH=$PYTHONPATH"
104+ echo "PYTHON=$PYTHON"
105+
106++# the exceptions handling test is version specific
107++PYMAJOR=$($PYTHON -c 'import sys;print(sys.version_info[0])')
108++PYTEST=test-exception-py$PYMAJOR.py
109++echo "running $PYTEST"
110++$PYTHON "$DBUS_TOP_SRCDIR"/test/$PYTEST || die "$PYTEST failed"
111++
112+ echo "running test-standalone.py"
113+ $PYTHON "$DBUS_TOP_SRCDIR"/test/test-standalone.py || die "test-standalone.py failed"
114+
115+--- /dev/null
116++++ b/test/test-exception-py2.py
117+@@ -0,0 +1,62 @@
118++#!/usr/bin/python
119++# -*- coding: utf-8 -*-
120++
121++import sys
122++import unittest
123++
124++import dbus
125++
126++# from test-service.py
127++class ServiceError(dbus.DBusException):
128++ """Exception representing a normal "environmental" error"""
129++ include_traceback = False
130++ _dbus_error_name = 'com.example.Networking.ServerError'
131++
132++
133++class DBusExceptionTestCase(unittest.TestCase):
134++ """Test the DBusException str/unicode behavior with py2"""
135++
136++ def test_dbus_exception_normal(self):
137++ """Test the normal Exception behavior"""
138++ e = dbus.exceptions.DBusException("baaa")
139++ msg = e.get_dbus_message()
140++ self.assertEqual(msg, u"baaa")
141++
142++ def test_dbus_exception_unicode(self):
143++ """Test that DBusExceptions that take a py2 unicode work"""
144++ e = dbus.exceptions.DBusException(u"bäää")
145++ msg = e.get_dbus_message()
146++ self.assertEqual(msg, u"bäää")
147++
148++ def test_dbus_exception_convert_str(self):
149++ """Test that converting a DBusException to str() works as expected"""
150++ e = dbus.exceptions.DBusException(u"bxxx")
151++ self.assertEqual(str(e), "bxxx")
152++
153++ def test_dbus_exception_convert_str_fail(self):
154++ """Test that a non-ascii Exception fails to convert to str"""
155++ if sys.getdefaultencoding() == 'ascii':
156++ self.assertRaises(UnicodeEncodeError,
157++ lambda: str(dbus.exceptions.DBusException(u"bä")))
158++ else:
159++ self.skipTest("you're using a weird non-ascii "
160++ "sys.getdefaultencoding()")
161++
162++ def test_dbus_exception_convert_unicode(self):
163++ """Test that converting a DBusEception to unicode works"""
164++ e = dbus.exceptions.DBusException(u"bäää")
165++ self.assertEqual(e.get_dbus_message(), u"bäää")
166++ self.assertEqual(e.__unicode__(), u"bäää")
167++ self.assertEqual(unicode(e), u"bäää")
168++
169++ def test_subclass_exception_unicode(self):
170++ """Test that DBusExceptions that take a py2 unicode work"""
171++ e = ServiceError(u"bäää")
172++ msg = e.get_dbus_message()
173++ self.assertEqual(msg, u"bäää")
174++ self.assertEqual(
175++ unicode(e), u"com.example.Networking.ServerError: bäää")
176++
177++
178++if __name__ == "__main__":
179++ unittest.main()
180+--- /dev/null
181++++ b/test/test-exception-py3.py
182+@@ -0,0 +1,31 @@
183++#!/usr/bin/python
184++# -*- coding: utf-8 -*-
185++
186++import unittest
187++
188++import dbus
189++
190++# from test-service.py
191++class ServiceError(dbus.DBusException):
192++ """Exception representing a normal "environmental" error"""
193++ include_traceback = False
194++ _dbus_error_name = 'com.example.Networking.ServerError'
195++
196++
197++class DBusExceptionTestCase(unittest.TestCase):
198++
199++ def test_dbus_exception(self):
200++ e = dbus.exceptions.DBusException("bäää")
201++ msg = e.get_dbus_message()
202++ self.assertEqual(msg, "bäää")
203++ self.assertEqual(str(e), "bäää")
204++
205++ def test_subclass_exception(self):
206++ e = ServiceError("bäää")
207++ msg = e.get_dbus_message()
208++ self.assertEqual(msg, "bäää")
209++ self.assertEqual(str(e), "com.example.Networking.ServerError: bäää")
210++
211++
212++if __name__ == "__main__":
213++ unittest.main()
214+--- a/test/test-client.py
215++++ b/test/test-client.py
216+@@ -563,6 +563,8 @@
217+ self.iface.RaiseDBusExceptionNoTraceback()
218+ except Exception as e:
219+ self.assertTrue(isinstance(e, dbus.DBusException), e.__class__)
220++ self.assertEqual(e.get_dbus_name(),
221++ 'com.example.Networking.ServerError')
222+ self.assertEqual(str(e),
223+ 'com.example.Networking.ServerError: '
224+ 'Server not responding')
225+@@ -573,6 +575,8 @@
226+ self.iface.RaiseDBusExceptionWithTraceback()
227+ except Exception as e:
228+ self.assertTrue(isinstance(e, dbus.DBusException), e.__class__)
229++ self.assertEqual(e.get_dbus_name(),
230++ 'com.example.Misc.RealityFailure')
231+ self.assertTrue(str(e).startswith('com.example.Misc.RealityFailure: '
232+ 'Traceback '),
233+ 'Wanted a traceback but got:\n%s' % str(e))
234
235=== added file 'debian/patches/series'
236--- debian/patches/series 1970-01-01 00:00:00 +0000
237+++ debian/patches/series 2012-10-17 14:55:32 +0000
238@@ -0,0 +1,1 @@
239+fdo-bug-55899.patch

Subscribers

People subscribed via source and target branches

to all changes: