class defaultdict(dict):

    """Poor man's implementation of defaultdict for Python 2.4
    """

    def __init__(self, default_factory=None, **kwargs):
        self.default_factory = default_factory
        super(defaultdict, self).__init__(**kwargs)

    def __getitem__(self, key):
        if self.default_factory is None:
            return super(defaultdict, self).__getitem__(key)
        else:
            try:
                return super(defaultdict, self).__getitem__(key)
            except KeyError:
                return self.default_factory()

class defaultdict(dict):

    """Poor man's implementation of defaultdict for Python 2.4
    """

    def __init__(self, default_factory=None, **kwargs):
        self.default_factory = default_factory
        super(defaultdict, self).__init__(**kwargs)

    def __getitem__(self, key):
        if self.default_factory is None:
            return super(defaultdict, self).__getitem__(key)
        else:
            try:
                return super(defaultdict, self).__getitem__(key)
            except KeyError:
                self[key] = self.default_factory()
                return self[key]

Save generated value for defaultdict
MB-6867: Save generated value for defaultdict

Instead of just returning value, keep it in dict.

Change-Id: I2a9862503b71f2234a4a450c48998b5f53a951bc
Reviewed-on: http://review.couchbase.org/21602
Tested-by: Bin Cui <ed18693fff32c00e22495f4877a3b901bed09041@gmail.com>
Reviewed-by: Pavel Paulau <dd88eded64e90046a680e3a6c0828ceb8fe8a0e7@gmail.com>

  class defaultdict(dict):
  
      """Poor man's implementation of defaultdict for Python 2.4
      """
  
      def __init__(self, default_factory=None, **kwargs):
          self.default_factory = default_factory
          super(defaultdict, self).__init__(**kwargs)
  
      def __getitem__(self, key):
          if self.default_factory is None:
              return super(defaultdict, self).__getitem__(key)
          else:
              try:
                  return super(defaultdict, self).__getitem__(key)
              except KeyError:
-                 return self.default_factory()
+                 self[key] = self.default_factory()
+                 return self[key]
  
Save generated value for defaultdict
## Code Before:
class defaultdict(dict):

    """Poor man's implementation of defaultdict for Python 2.4
    """

    def __init__(self, default_factory=None, **kwargs):
        self.default_factory = default_factory
        super(defaultdict, self).__init__(**kwargs)

    def __getitem__(self, key):
        if self.default_factory is None:
            return super(defaultdict, self).__getitem__(key)
        else:
            try:
                return super(defaultdict, self).__getitem__(key)
            except KeyError:
                return self.default_factory()

## Instruction:
Save generated value for defaultdict
## Code After:
class defaultdict(dict):

    """Poor man's implementation of defaultdict for Python 2.4
    """

    def __init__(self, default_factory=None, **kwargs):
        self.default_factory = default_factory
        super(defaultdict, self).__init__(**kwargs)

    def __getitem__(self, key):
        if self.default_factory is None:
            return super(defaultdict, self).__getitem__(key)
        else:
            try:
                return super(defaultdict, self).__getitem__(key)
            except KeyError:
                self[key] = self.default_factory()
                return self[key]
