Use RFC 8040 URL for 'odl-mdsal-lowlevel-*' RPCs
[integration/test.git] / csit / libraries / Counter.py
index 67400204035cf9e14b66fe71de09ad7faca11f16..b23e689df9ec9c565a8d88ecd6d8b6d564f94f1a 100644 (file)
@@ -4,17 +4,17 @@ from itertools import repeat, ifilter
 
 
 class Counter(dict):
 
 
 class Counter(dict):
-    '''Dict subclass for counting hashable objects.  Sometimes called a bag
+    """Dict subclass for counting hashable objects.  Sometimes called a bag
     or multiset.  Elements are stored as dictionary keys and their counts
     are stored as dictionary values.
 
     >>> Counter('zyzygy')
     Counter({'y': 3, 'z': 2, 'g': 1})
 
     or multiset.  Elements are stored as dictionary keys and their counts
     are stored as dictionary values.
 
     >>> Counter('zyzygy')
     Counter({'y': 3, 'z': 2, 'g': 1})
 
-    '''
+    """
 
     def __init__(self, iterable=None, **kwds):
 
     def __init__(self, iterable=None, **kwds):
-        '''Create a new, empty Counter object.  And if given, count elements
+        """Create a new, empty Counter object.  And if given, count elements
         from an input iterable.  Or, initialize the count from another mapping
         of elements to their counts.
 
         from an input iterable.  Or, initialize the count from another mapping
         of elements to their counts.
 
@@ -23,26 +23,26 @@ class Counter(dict):
         >>> c = Counter({'a': 4, 'b': 2})           # a new counter from a mapping
         >>> c = Counter(a=4, b=2)                   # a new counter from keyword args
 
         >>> c = Counter({'a': 4, 'b': 2})           # a new counter from a mapping
         >>> c = Counter(a=4, b=2)                   # a new counter from keyword args
 
-        '''
+        """
         self.update(iterable, **kwds)
 
     def __missing__(self, key):
         return 0
 
     def most_common(self, n=None):
         self.update(iterable, **kwds)
 
     def __missing__(self, key):
         return 0
 
     def most_common(self, n=None):
-        '''List the n most common elements and their counts from the most
+        """List the n most common elements and their counts from the most
         common to the least.  If n is None, then list all element counts.
 
         >>> Counter('abracadabra').most_common(3)
         [('a', 5), ('r', 2), ('b', 2)]
 
         common to the least.  If n is None, then list all element counts.
 
         >>> Counter('abracadabra').most_common(3)
         [('a', 5), ('r', 2), ('b', 2)]
 
-        '''
+        """
         if n is None:
             return sorted(self.iteritems(), key=itemgetter(1), reverse=True)
         return nlargest(n, self.iteritems(), key=itemgetter(1))
 
     def elements(self):
         if n is None:
             return sorted(self.iteritems(), key=itemgetter(1), reverse=True)
         return nlargest(n, self.iteritems(), key=itemgetter(1))
 
     def elements(self):
-        '''Iterator over elements repeating each as many times as its count.
+        """Iterator over elements repeating each as many times as its count.
 
         >>> c = Counter('ABCABC')
         >>> sorted(c.elements())
 
         >>> c = Counter('ABCABC')
         >>> sorted(c.elements())
@@ -51,7 +51,7 @@ class Counter(dict):
         If an element's count has been set to zero or is a negative number,
         elements() will ignore it.
 
         If an element's count has been set to zero or is a negative number,
         elements() will ignore it.
 
-        '''
+        """
         for elem, count in self.iteritems():
             for _ in repeat(None, count):
                 yield elem
         for elem, count in self.iteritems():
             for _ in repeat(None, count):
                 yield elem
@@ -61,10 +61,11 @@ class Counter(dict):
     @classmethod
     def fromkeys(cls, iterable, v=None):
         raise NotImplementedError(
     @classmethod
     def fromkeys(cls, iterable, v=None):
         raise NotImplementedError(
-            'Counter.fromkeys() is undefined.  Use Counter(iterable) instead.')
+            "Counter.fromkeys() is undefined.  Use Counter(iterable) instead."
+        )
 
     def update(self, iterable=None, **kwds):
 
     def update(self, iterable=None, **kwds):
-        '''Like dict.update() but add counts instead of replacing them.
+        """Like dict.update() but add counts instead of replacing them.
 
         Source can be an iterable, a dictionary, or another Counter instance.
 
 
         Source can be an iterable, a dictionary, or another Counter instance.
 
@@ -75,9 +76,9 @@ class Counter(dict):
         >>> c['h']                      # four 'h' in which, witch, and watch
         4
 
         >>> c['h']                      # four 'h' in which, witch, and watch
         4
 
-        '''
+        """
         if iterable is not None:
         if iterable is not None:
-            if hasattr(iterable, 'iteritems'):
+            if hasattr(iterable, "iteritems"):
                 if self:
                     self_get = self.get
                     for elem, count in iterable.iteritems():
                 if self:
                     self_get = self.get
                     for elem, count in iterable.iteritems():
@@ -92,19 +93,19 @@ class Counter(dict):
             self.update(kwds)
 
     def copy(self):
             self.update(kwds)
 
     def copy(self):
-        'Like dict.copy() but returns a Counter instance instead of a dict.'
+        "Like dict.copy() but returns a Counter instance instead of a dict."
         return Counter(self)
 
     def __delitem__(self, elem):
         return Counter(self)
 
     def __delitem__(self, elem):
-        'Like dict.__delitem__() but does not raise KeyError for missing values.'
+        "Like dict.__delitem__() but does not raise KeyError for missing values."
         if elem in self:
             dict.__delitem__(self, elem)
 
     def __repr__(self):
         if not self:
         if elem in self:
             dict.__delitem__(self, elem)
 
     def __repr__(self):
         if not self:
-            return '%s()' % self.__class__.__name__
-        items = ', '.join(map('%r: %r'.__mod__, self.most_common()))
-        return '%s({%s})' % (self.__class__.__name__, items)
+            return "%s()" % self.__class__.__name__
+        items = ", ".join(map("%r: %r".__mod__, self.most_common()))
+        return "%s({%s})" % (self.__class__.__name__, items)
 
     # Multiset-style mathematical operations discussed in:
     #       Knuth TAOCP Volume II section 4.6.3 exercise 19
 
     # Multiset-style mathematical operations discussed in:
     #       Knuth TAOCP Volume II section 4.6.3 exercise 19
@@ -116,13 +117,13 @@ class Counter(dict):
     #       c += Counter()
 
     def __add__(self, other):
     #       c += Counter()
 
     def __add__(self, other):
-        '''Add counts from two counters.
+        """Add counts from two counters.
 
         >>> Counter('abbb') + Counter('bcc')
         Counter({'b': 4, 'c': 2, 'a': 1})
 
 
 
         >>> Counter('abbb') + Counter('bcc')
         Counter({'b': 4, 'c': 2, 'a': 1})
 
 
-        '''
+        """
         if not isinstance(other, Counter):
             return NotImplemented
         result = Counter()
         if not isinstance(other, Counter):
             return NotImplemented
         result = Counter()
@@ -133,12 +134,12 @@ class Counter(dict):
         return result
 
     def __sub__(self, other):
         return result
 
     def __sub__(self, other):
-        ''' Subtract count, but keep only results with positive counts.
+        """Subtract count, but keep only results with positive counts.
 
         >>> Counter('abbbc') - Counter('bccd')
         Counter({'b': 2, 'a': 1})
 
 
         >>> Counter('abbbc') - Counter('bccd')
         Counter({'b': 2, 'a': 1})
 
-        '''
+        """
         if not isinstance(other, Counter):
             return NotImplemented
         result = Counter()
         if not isinstance(other, Counter):
             return NotImplemented
         result = Counter()
@@ -149,12 +150,12 @@ class Counter(dict):
         return result
 
     def __or__(self, other):
         return result
 
     def __or__(self, other):
-        '''Union is the maximum of value in either of the input counters.
+        """Union is the maximum of value in either of the input counters.
 
         >>> Counter('abbb') | Counter('bcc')
         Counter({'b': 3, 'c': 2, 'a': 1})
 
 
         >>> Counter('abbb') | Counter('bcc')
         Counter({'b': 3, 'c': 2, 'a': 1})
 
-        '''
+        """
         if not isinstance(other, Counter):
             return NotImplemented
         _max = max
         if not isinstance(other, Counter):
             return NotImplemented
         _max = max
@@ -166,12 +167,12 @@ class Counter(dict):
         return result
 
     def __and__(self, other):
         return result
 
     def __and__(self, other):
-        ''' Intersection is the minimum of corresponding counts.
+        """Intersection is the minimum of corresponding counts.
 
         >>> Counter('abbb') & Counter('bcc')
         Counter({'b': 1})
 
 
         >>> Counter('abbb') & Counter('bcc')
         Counter({'b': 1})
 
-        '''
+        """
         if not isinstance(other, Counter):
             return NotImplemented
         _min = min
         if not isinstance(other, Counter):
             return NotImplemented
         _min = min
@@ -185,6 +186,7 @@ class Counter(dict):
         return result
 
 
         return result
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     import doctest
     import doctest
-    print doctest.testmod()
+
+    print(doctest.testmod())