Kaynağa Gözat

Change iteritems -> items.

Jelmer Vernooij 3 yıl önce
ebeveyn
işleme
8603d58d9f
2 değiştirilmiş dosya ile 48 ekleme ve 11 silme
  1. 42 5
      dulwich/config.py
  2. 6 6
      dulwich/tests/test_config.py

+ 42 - 5
dulwich/config.py

@@ -28,6 +28,7 @@ TODO:
 
 import os
 import sys
+import warnings
 
 from typing import BinaryIO, Tuple, Optional
 
@@ -128,6 +129,19 @@ class Config(object):
         """
         raise NotImplementedError(self.get)
 
+    def get_multivar(self, section, name):
+        """Retrieve the contents of a multivar configuration setting.
+
+        Args:
+          section: Tuple with section name and optional subsection namee
+          subsection: Subsection name
+        Returns:
+          Contents of the setting as iterable
+        Raises:
+          KeyError: if the value is not set
+        """
+        raise NotImplementedError(self.get_multivar)
+
     def get_boolean(self, section, name, default=None):
         """Retrieve a configuration setting as boolean.
 
@@ -161,6 +175,16 @@ class Config(object):
         """
         raise NotImplementedError(self.set)
 
+    def items(self, section):
+        """Iterate over the configuration pairs for a specific section.
+
+        Args:
+          section: Tuple with section name and optional subsection namee
+        Returns:
+          Iterator over (name, value) pairs
+        """
+        raise NotImplementedError(self.items)
+
     def iteritems(self, section):
         """Iterate over the configuration pairs for a specific section.
 
@@ -169,14 +193,27 @@ class Config(object):
         Returns:
           Iterator over (name, value) pairs
         """
-        raise NotImplementedError(self.iteritems)
+        warnings.warn(
+            "Use %s.items instead." % type(self).__name__,
+            DeprecationWarning,
+            stacklevel=3,
+        )
+        return self.items(section)
 
     def itersections(self):
+        warnings.warn(
+            "Use %s.items instead." % type(self).__name__,
+            DeprecationWarning,
+            stacklevel=3,
+        )
+        return self.sections()
+
+    def sections(self):
         """Iterate over the sections.
 
         Returns: Iterator over section tuples
         """
-        raise NotImplementedError(self.itersections)
+        raise NotImplementedError(self.sections)
 
     def has_section(self, name):
         """Check if a specified section exists.
@@ -186,7 +223,7 @@ class Config(object):
         Returns:
           boolean indicating whether the section exists
         """
-        return name in self.itersections()
+        return name in self.sections()
 
 
 class ConfigDict(Config, MutableMapping):
@@ -265,10 +302,10 @@ class ConfigDict(Config, MutableMapping):
 
         self._values.setdefault(section)[name] = value
 
-    def iteritems(self, section):
+    def items(self, section):
         return self._values.get(section).items()
 
-    def itersections(self):
+    def sections(self):
         return self._values.keys()
 
 

+ 6 - 6
dulwich/tests/test_config.py

@@ -257,24 +257,24 @@ class ConfigDictTests(TestCase):
         cd[b"a"] = b"b"
         self.assertEqual(cd[b"a"], b"b")
 
-    def test_iteritems(self):
+    def test_items(self):
         cd = ConfigDict()
         cd.set((b"core",), b"foo", b"bla")
         cd.set((b"core2",), b"foo", b"bloe")
 
-        self.assertEqual([(b"foo", b"bla")], list(cd.iteritems((b"core",))))
+        self.assertEqual([(b"foo", b"bla")], list(cd.items((b"core",))))
 
-    def test_iteritems_nonexistant(self):
+    def test_items_nonexistant(self):
         cd = ConfigDict()
         cd.set((b"core2",), b"foo", b"bloe")
 
-        self.assertEqual([], list(cd.iteritems((b"core",))))
+        self.assertEqual([], list(cd.items((b"core",))))
 
-    def test_itersections(self):
+    def test_sections(self):
         cd = ConfigDict()
         cd.set((b"core2",), b"foo", b"bloe")
 
-        self.assertEqual([(b"core2",)], list(cd.itersections()))
+        self.assertEqual([(b"core2",)], list(cd.sections()))
 
 
 class StackedConfigTests(TestCase):