code: def metadata_sorter(x, y):
      
      if x == y:
          return 0
      if x in METADATA_SORTER_FIRST and y in METADATA_SORTER_FIRST:
          return -1 if METADATA_SORTER_FIRST.index(x) < METADATA_SORTER_FIRST.index(y) else 1
      elif x in METADATA_SORTER_FIRST:
          return -1
      elif y in METADATA_SORTER_FIRST:
          return 1
      else:
          if x.startswith('_') and y.startswith('_'):
              return cmp(x[1:], y[1:])
          elif x.startswith('_'):
              return 1
          elif y.startswith('_'):
              return -1
          else:
              return cmp(x, y)
docs: Sort metadata keys by priority.