On Fri, Jul 30, 2010 at 12:45:07PM +0200, Jelmer Vernooij wrote:
> Attached patch updates the changelog as well and removes the conflict
> with older versions of apt.

Thanks - how about this one?  It's a little simpler since the only thing
we use apt_pkg for in deb822 is TagFile.

Also...are you just using the deb822 module on its own?  There are
plenty of dependencies in python-debian that aren't satisfiable in
Dapper.  Also, I just added a feature that depends on UnicodeWarning
being available, but that's only in python2.5.  Thinking about it,
though, it's better to make a new warning class anyway, hence the second
patch.  With both patches, I think at least deb822 should work fine in a
Dapper environment.

Shall I commit?

-- 
John Wright <j...@debian.org>
From 67702928d49e3381f8c39c954da231c1ce0c82a1 Mon Sep 17 00:00:00 2001
From: John Wright <j...@debian.org>
Date: Sun, 1 Aug 2010 01:06:42 -0700
Subject: [PATCH 1/2] Support installation together with older versions of python-apt

The deb822 module only uses apt_pkg for its TagFile interface, which is
only supported in later versions of python-apt.  But it's simple enough
to detect whether TagFile is available and fall back to the native
parser, rather than conflicting with earlier versions of python-apt.

Original patch by Jelmer Vernooij.

Closes: #590805
---
 debian/changelog     |    7 +++++++
 debian/control       |    4 ++--
 lib/debian/deb822.py |    4 +++-
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 7e1188a..5d164a5 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+python-debian (0.1.18) UNRELEASED; urgency=low
+
+  * Support installation together with older versions of python-apt.
+    Original patch by Jelmer Vernooij. (Closes: #590805)
+
+ -- John Wright <j...@debian.org>  Sun, 01 Aug 2010 01:01:41 -0700
+
 python-debian (0.1.17) unstable; urgency=low
 
   [ James Westby ]
diff --git a/debian/control b/debian/control
index d52ab3e..e8ad071 100644
--- a/debian/control
+++ b/debian/control
@@ -20,10 +20,10 @@ Depends: ${python:Depends}, ${misc:Depends}, python-chardet
 Recommends: python-apt
 Suggests: gpgv
 Provides: python-deb822
-Conflicts: python-deb822, python-apt (<< 0.7.94~)
+Conflicts: python-deb822
 Replaces: python-deb822
 Description: Python modules to work with Debian-related data formats
- This package provides Python modules that abstract many formats of Debian 
+ This package provides Python modules that abstract many formats of Debian
  related files. Currently handled are:
   * Debtags information (debian.debtags module)
   * debian/changelog (debian.changelog module)
diff --git a/lib/debian/deb822.py b/lib/debian/deb822.py
index 1a21e62..a0cad69 100644
--- a/lib/debian/deb822.py
+++ b/lib/debian/deb822.py
@@ -26,8 +26,10 @@ from deprecation import function_deprecated_by
 
 try:
     import apt_pkg
+    # This module uses apt_pkg only for its TagFile interface.
+    apt_pkg.TagFile
     _have_apt_pkg = True
-except ImportError:
+except (ImportError, AttributeError):
     _have_apt_pkg = False
 
 import chardet
-- 
1.7.1

From 251967b8cf08cfb7acde8602977b83a2f8ec2619 Mon Sep 17 00:00:00 2001
From: John Wright <j...@debian.org>
Date: Sun, 1 Aug 2010 01:25:36 -0700
Subject: [PATCH 2/2] Use our own warning class when auto-detecting string encoding

We used UnicodeWarning initially, but that has specific meaning in the
Python documentation.  Furthermore, it's not available in Python 2.4,
and while for Debian we don't need to support older Python versions,
this is the first 2.5-specific dependency in the deb822 module, and it
doesn't provide any benefit.
---
 debian/changelog     |    1 +
 lib/debian/deb822.py |    7 ++++++-
 tests/test_deb822.py |    3 ++-
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 5d164a5..01f7732 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,6 +2,7 @@ python-debian (0.1.18) UNRELEASED; urgency=low
 
   * Support installation together with older versions of python-apt.
     Original patch by Jelmer Vernooij. (Closes: #590805)
+  * Use our own warning class when auto-detecting string encoding.
 
  -- John Wright <j...@debian.org>  Sun, 01 Aug 2010 01:01:41 -0700
 
diff --git a/lib/debian/deb822.py b/lib/debian/deb822.py
index a0cad69..500cbda 100644
--- a/lib/debian/deb822.py
+++ b/lib/debian/deb822.py
@@ -42,6 +42,11 @@ import warnings
 import StringIO
 import UserDict
 
+
+class Deb822EncodingWarning(Warning):
+    """Attempting to detect string encoding using chardet"""
+
+
 class TagSectionWrapper(object, UserDict.DictMixin):
     """Wrap a TagSection object, using its find_raw method to get field values
 
@@ -188,7 +193,7 @@ class Deb822Dict(object, UserDict.DictMixin):
                 # user specified.  Try detecting it.
                 warnings.warn('decoding from %s failed; attempting to detect '
                               'the true encoding' % self.encoding,
-                              UnicodeWarning)
+                              Deb822EncodingWarning)
                 result = chardet.detect(value)
                 try:
                     value = value.decode(result['encoding'])
diff --git a/tests/test_deb822.py b/tests/test_deb822.py
index 891f4cd..d476f38 100755
--- a/tests/test_deb822.py
+++ b/tests/test_deb822.py
@@ -713,7 +713,8 @@ Description: python modules to work with Debian-related data formats
         """
 
         # Avoid spitting out the encoding warning during testing.
-        warnings.filterwarnings(action='ignore', category=UnicodeWarning)
+        warnings.filterwarnings(action='ignore',
+                                category=deb822.Deb822EncodingWarning)
 
         filename = 'test_Sources.mixed_encoding'
         for paragraphs in [deb822.Sources.iter_paragraphs(file(filename)),
-- 
1.7.1

Reply via email to