~aptdaemon-developers/aptdaemon/ubuntu-quantal

« back to all changes in this revision

Viewing changes to debian/patches/lp846044.patch

  • Committer: Michael Vogt
  • Date: 2012-10-08 13:57:25 UTC
  • Revision ID: michael.vogt@ubuntu.com-20121008135725-1igkprn7v1omiusi
* debian/patches/lp846044.patch:
  - fix unicode decode error in py2 clients (LP: #846044)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
=== modified file 'aptdaemon/errors.py'
 
2
--- a/aptdaemon/errors.py       2012-05-16 09:16:39 +0000
 
3
+++ b/aptdaemon/errors.py       2012-10-08 07:54:00 +0000
 
4
@@ -106,11 +106,18 @@
 
5
         self.details_args = args
 
6
         AptDaemonError.__init__(self, "%s: %s" % (code, details % args))
 
7
 
 
8
-    def __str__(self):
 
9
+    def __unicode__(self):
 
10
         return "Transaction failed: %s\n%s" % \
 
11
                (aptdaemon.enums.get_error_string_from_enum(self.code),
 
12
                 self.details)
 
13
 
 
14
+    def __str__(self):
 
15
+        if PY3K:
 
16
+            return self.__unicode__()
 
17
+        else:
 
18
+            return self.__unicode__().encode("utf-8")
 
19
+
 
20
+
 
21
 
 
22
 class InvalidMetaDataError(AptDaemonError):
 
23
 
 
24
 
 
25
=== modified file 'tests/_test_py2_string_handling.py'
 
26
--- a/tests/_test_py2_string_handling.py        2012-05-13 16:13:40 +0000
 
27
+++ b/tests/_test_py2_string_handling.py        2012-10-08 07:54:00 +0000
 
28
@@ -87,6 +87,15 @@
 
29
             self.assertRaises(MemoryError, ErrorMessage, Message(), name,
 
30
                               content)
 
31
 
 
32
+    def test_dbus_exception_lp846044(self):
 
33
+        e = TransactionFailed("foo", "bar")
 
34
+        e.details = u"ä"
 
35
+        foo = unicode(e)
 
36
+        self.assertEqual(foo, u"Transaction failed: None\nä")
 
37
+        foo = str(e)
 
38
+        self.assertEqual(foo, u"Transaction failed: None\nä".encode("utf-8"))
 
39
+    
 
40
+
 
41
 
 
42
 if __name__ == "__main__":
 
43
     unittest.main()
 
44
 
 
45
=== added file 'tests/_test_py3_string_handling.py'
 
46
--- a/tests/_test_py3_string_handling.py        1970-01-01 00:00:00 +0000
 
47
+++ b/tests/_test_py3_string_handling.py        2012-10-08 07:54:00 +0000
 
48
@@ -0,0 +1,46 @@
 
49
+#!/usr/bin/env python
 
50
+# -*- coding: utf-8 -*-
 
51
+# Copyright (C) 2011 Michael Vogt <mvo@ubuntu.com>
 
52
+#
 
53
+# Licensed under the GNU General Public License Version 2
 
54
+#
 
55
+# This program is free software; you can redistribute it and/or modify
 
56
+# it under the terms of the GNU General Public License as published by
 
57
+# the Free Software Foundation; either version 2 of the License, or
 
58
+# at your option) any later version.
 
59
+#
 
60
+# This program is distributed in the hope that it will be useful,
 
61
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
62
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
63
+# GNU General Public License for more details.
 
64
+#
 
65
+# You should have received a copy of the GNU General Public License
 
66
+# along with this program; if not, write to the Free Software
 
67
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
68
+# Licensed under the GNU General Public License Version 2
 
69
+
 
70
+"""Regression test for a unicode decoding error in the status_details,
 
71
+progress_download or error_properties attributes of the transaction,
 
72
+see LP #724735.
 
73
+"""
 
74
+
 
75
+__author__  = "Michael Vogt <mvo@glatzor.de>"
 
76
+
 
77
+import unittest
 
78
+
 
79
+from aptdaemon.errors import TransactionFailed
 
80
+from aptdaemon.test import AptDaemonTestCase
 
81
+
 
82
+
 
83
+class TestUnicodeDecodingPy3(AptDaemonTestCase):
 
84
+
 
85
+    def test_dbus_exception_lp846044(self):
 
86
+        e = TransactionFailed("foo", "bar")
 
87
+        e.details = "ä"
 
88
+        self.assertEqual(str(e), "Transaction failed: None\nä")
 
89
+
 
90
+
 
91
+if __name__ == "__main__":
 
92
+    unittest.main()
 
93
+
 
94
+# vim: ts=4 et sts=4
 
95
 
 
96
=== modified file 'tests/test_py2_string_handling.py'
 
97
--- a/tests/test_py2_string_handling.py 2012-05-13 16:13:40 +0000
 
98
+++ b/tests/test_py2_string_handling.py 2012-10-08 13:37:39 +0000
 
99
@@ -31,6 +31,12 @@
 
100
 
 
101
 if sys.version_info.major == 2:
 
102
     from _test_py2_string_handling import *
 
103
+else:
 
104
+    try:
 
105
+        from _test_py3_string_handling import *
 
106
+    except ImportError:
 
107
+        from ._test_py3_string_handling import *
 
108
+
 
109
 
 
110
 if __name__ == "__main__":
 
111
     unittest.main()
 
112