code: def compare_versions(version_a, version_b):
      logger.debug('compare_versions(%s, %s)', version_a, version_b)
      if version_a == version_b:
          return a_eq_b
      try:
          chars_a, chars_b = list(version_a), list(version_b)
      except TypeError:
          raise RpmError('Could not compare {0} to '
                         '{1}'.format(version_a, version_b))
      while len(chars_a) != 0 and len(chars_b) != 0:
          logger.debug('starting loop comparing %s '
                       'to %s', chars_a, chars_b)
          _check_leading(chars_a, chars_b)
          if chars_a[0] == '~' and chars_b[0] == '~':
              map(lambda x: x.pop(0), (chars_a, chars_b))
          elif chars_a[0] == '~':
              return b_newer
          elif chars_b[0] == '~':
              return a_newer
          if len(chars_a) == 0 or len(chars_b) == 0:
              break
          block_res = _get_block_result(chars_a, chars_b)
          if block_res != a_eq_b:
              return block_res
      if len(chars_a) == len(chars_b):
          logger.debug('versions are equal')
          return a_eq_b
      else:
          logger.debug('versions not equal')
          return a_newer if len(chars_a) > len(chars_b) else b_newer