[Pkg-python-debian-commits] trunk r101: Merge case-preservation branch (bug 473254)

John Wright john at movingsucks.org
Mon Apr 28 11:24:53 UTC 2008


------------------------------------------------------------
revno: 101
committer: John Wright <john at movingsucks.org>
branch nick: trunk
timestamp: Mon 2008-04-28 11:24:53 +0000
message:
  Merge case-preservation branch (bug 473254)
modified:
  debian/changelog
  debian_bundle/deb822.py
  tests/test_deb822.py
    ------------------------------------------------------------
    revno: 100.1.1
    committer: john.wright at hp.com
    branch nick: case-preservation
    timestamp: Wed 2008-04-02 02:02:40 -0600
    message:
      Add more case-preservation tests
    modified:
      tests/test_deb822.py
    ------------------------------------------------------------
    revno: 100.1.2
    committer: john.wright at hp.com
    branch nick: case-preservation
    timestamp: Wed 2008-04-02 02:18:17 -0600
    message:
      Do not cache _CaseInsensitiveString objects, since it causes case preservation
      issues under certain circumstances (Closes: #473254)
    modified:
      debian/changelog
      debian_bundle/deb822.py
-------------- next part --------------
=== modified file 'debian/changelog'
--- a/debian/changelog	2008-02-06 14:37:01 +0000
+++ b/debian/changelog	2008-04-02 08:18:17 +0000
@@ -1,3 +1,12 @@
+python-debian (0.1.10) UNRELEASED; urgency=low
+
+  * debian_bundle/deb822.py, tests/test_deb822.py:
+    - Do not cache _CaseInsensitiveString objects, since it causes case
+      preservation issues under certain circumstances (Closes: #473254)
+    - Add a test case
+
+ -- John Wright <jsw at debian.org>  Wed, 02 Apr 2008 02:17:23 -0600
+
 python-debian (0.1.9) unstable; urgency=low
 
   * Promote python-apt from Suggests to Recommends. (Closes: #462845)

=== modified file 'debian_bundle/deb822.py'
--- a/debian_bundle/deb822.py	2007-12-28 17:43:40 +0000
+++ b/debian_bundle/deb822.py	2008-04-02 08:18:17 +0000
@@ -514,29 +514,8 @@
 
 class _CaseInsensitiveString(str):
     """Case insensitive string.
-    
-    Created objects are cached as to not create the same object twice.
     """
 
-    _cache = {}
-
-    def __new__(cls, str_):
-        if isinstance(str_, _CaseInsensitiveString):
-            return str_
-
-        try:
-            lower = str_.lower()
-        except AttributeError:
-            raise TypeError('key must be a string')
-
-        cache = _CaseInsensitiveString._cache
-
-        try:
-            return cache[lower]
-        except KeyError:
-            ret = cache[lower] = str.__new__(cls, str_)
-            return ret
-
     def __init__(self, str_):
         str.__init__(self, str_)
         self.str_lower = str_.lower()

=== modified file 'tests/test_deb822.py'
--- a/tests/test_deb822.py	2007-12-28 17:43:40 +0000
+++ b/tests/test_deb822.py	2008-04-02 08:02:40 +0000
@@ -464,5 +464,25 @@
         changesobj = deb822.Changes(CHANGES_FILE.splitlines())
         self.assertEqual(CHANGES_FILE, changesobj.dump())
 
+    def test_case_preserved_in_input(self):
+        """The field case in the output from dump() should be the same as the
+        input, even if multiple Deb822 objects have been created using
+        different case conventions.
+
+        This is related to bug 473254 - the fix for this issue is probably the
+        same as the fix for that bug.
+        """
+        input1 = "Foo: bar\nBaz: bang\n"
+        input2 = "foo: baz\nQux: thud\n"
+        d1 = deb822.Deb822(input1.splitlines())
+        d2 = deb822.Deb822(input2.splitlines())
+        self.assertEqual(input1, d1.dump())
+        self.assertEqual(input2, d2.dump())
+
+        d3 = deb822.Deb822()
+        if not d3.has_key('some-test-key'):
+            d3['Some-Test-Key'] = 'some value'
+        self.assertEqual(d3.dump(), "Some-Test-Key: some value\n")
+
 if __name__ == '__main__':
     unittest.main()



More information about the pkg-python-debian-commits mailing list