old_contents: import re
  import six
  import unicodedata
  
  
  def smart_text(s, encoding='utf-8', errors='strict'):
      if isinstance(s, six.text_type):
          return s
  
      if not isinstance(s, six.string_types):
          if six.PY3:
              if isinstance(s, bytes):
                  s = six.text_type(s, encoding, errors)
              else:
                  s = six.text_type(s)
          elif hasattr(s, '__unicode__'):
              s = six.text_type(s)
          else:
              s = six.text_type(bytes(s), encoding, errors)
      else:
          s = six.text_type(s)
      return s
  
  
  # Extra characters outside of alphanumerics that we'll allow.
  SLUG_OK = '-_~'
  
  
  def slugify(s, ok=SLUG_OK, lower=True, spaces=False, unicode_pairs=None):
      # L and N signify letter/number.
      # http://www.unicode.org/reports/tr44/tr44-4.html#GC_Values_Table
      rv = []
      for c in unicodedata.normalize('NFKC', smart_text(s)):
          cat = unicodedata.category(c)[0]
          if cat in 'LN' or c in ok:
              rv.append(c)
          if cat == 'Z':  # space
              rv.append(' ')
      new = ''.join(rv).strip()
      if not spaces:
          new = re.sub('[-\s]+', '-', new)
  
      if unicode_pairs and isinstance(unicode_pairs, dict):
          for char in unicode_pairs:
              new = new.replace(char, unicode_pairs[char])
  
      return new.lower() if lower else new
  
new_contents: import re
  import six
  import unicodedata
  
  
  def smart_text(s, encoding='utf-8', errors='strict'):
      if isinstance(s, six.text_type):
          return s
  
      if not isinstance(s, six.string_types):
          if six.PY3:
              if isinstance(s, bytes):
                  s = six.text_type(s, encoding, errors)
              else:
                  s = six.text_type(s)
          elif hasattr(s, '__unicode__'):
              s = six.text_type(s)
          else:
              s = six.text_type(bytes(s), encoding, errors)
      else:
          s = six.text_type(s)
      return s
  
  
  # Extra characters outside of alphanumerics that we'll allow.
  SLUG_OK = '-_~'
  
  
  def slugify(s, ok=SLUG_OK, lower=True, spaces=False, unicode_pairs=None):
      # L and N signify letter/number.
      # http://www.unicode.org/reports/tr44/tr44-4.html#GC_Values_Table
      rv = []
      for c in unicodedata.normalize('NFKC', smart_text(s)):
          cat = unicodedata.category(c)[0]
          if cat in 'LN' or c in ok:
              rv.append(c)
          if cat == 'Z':  # space
              rv.append(' ')
      new = ''.join(rv).strip()
      if not spaces:
          new = re.sub('[-\s]+', '-', new)
  
      new = new.lower() if lower else new
  
      if unicode_pairs and isinstance(unicode_pairs, dict):
          for char in unicode_pairs:
              new = new.replace(char, unicode_pairs[char])
  
      return new
  
subject: Change logic order.