old_contents: #!/usr/bin/env python
  """
  ================================================================================
  :mod:`checksum` -- Check sum
  ================================================================================
  
  .. module:: checksum
     :synopsis: Check sum
  
  .. inheritance-diagram:: checksum
  
  """
  
  # Script information for the file.
  __author__ = "Philippe T. Pinard"
  __email__ = "philippe.pinard@gmail.com"
  __version__ = "0.1"
  __copyright__ = "Copyright (c) 2013 Philippe T. Pinard"
  __license__ = "GPL v3"
  
  # Standard library modules.
  from collections import namedtuple
  import hashlib
  
  # Third party modules.
  
  # Local modules.
  
  # Globals and constants variables.
  
  CHECKSUM_ALGORITHM_SHA1 = 'SHA-1'
  CHECKSUM_ALGORITHM_SUM32 = 'SUM32'
  
  _CHECKSUM_ALGORITHMS = frozenset([CHECKSUM_ALGORITHM_SHA1, 
                                    CHECKSUM_ALGORITHM_SUM32])
  
  Checksum = namedtuple('Checksum', ['value', 'algorithm'])
  
  def calculate_checksum_sha1(buffer):
      sha1 = hashlib.sha1()
      sha1.update(buffer)
      value = sha1.hexdigest()
      return Checksum(value, CHECKSUM_ALGORITHM_SHA1)
  
  def calculate_checksum_sum32(buffer):
      sumbytes = sum(buffer)
      value = hex(sumbytes)[2:34].zfill(32)
      return Checksum(value, CHECKSUM_ALGORITHM_SUM32)
  
new_contents: #!/usr/bin/env python
  """
  ================================================================================
  :mod:`checksum` -- Check sum
  ================================================================================
  
  .. module:: checksum
     :synopsis: Check sum
  
  .. inheritance-diagram:: checksum
  
  """
  
  # Script information for the file.
  __author__ = "Philippe T. Pinard"
  __email__ = "philippe.pinard@gmail.com"
  __version__ = "0.1"
  __copyright__ = "Copyright (c) 2013 Philippe T. Pinard"
  __license__ = "GPL v3"
  
  # Standard library modules.
  from collections import namedtuple
  import hashlib
  
  # Third party modules.
  
  # Local modules.
  
  # Globals and constants variables.
  
  CHECKSUM_ALGORITHM_SHA1 = 'SHA-1'
  CHECKSUM_ALGORITHM_SUM32 = 'SUM32'
  
  Checksum = namedtuple('Checksum', ['value', 'algorithm'])
  
  def calculate_checksum_sha1(buffer):
      sha1 = hashlib.sha1()
      sha1.update(buffer)
      value = sha1.hexdigest()
      return Checksum(value, CHECKSUM_ALGORITHM_SHA1)
  
  def calculate_checksum_sum32(buffer):
      sumbytes = sum(buffer)
      value = hex(sumbytes)[2:34].zfill(32)
      return Checksum(value, CHECKSUM_ALGORITHM_SUM32)
  
  _CHECKSUM_ALGORITHMS = {CHECKSUM_ALGORITHM_SHA1: calculate_checksum_sha1,
                          CHECKSUM_ALGORITHM_SUM32: calculate_checksum_sum32}
  
  def calculate_checksum(algorithm, buffer):
      try:
          method = _CHECKSUM_ALGORITHMS[algorithm.upper()]
      except KeyError:
          raise ValueError('Unknown checksum algorithm: %s' % algorithm)
      else:
          return method(buffer)
  
subject: Add generic function to calculate checksum.