prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Names with non ASCII characters deteriorate during metadata integration
  Raw data:
  https://github.com/OBOFoundry/OBOFoundry.github.io/blob/master/ontology/lepao.md?plain=1#L7
  
  Result:
  https://github.com/OBOFoundry/OBOFoundry.github.io/pull/1690/files#diff-ecec67b0e1d7e17a83587c6d27b6baaaa133f42482b07bd3685c77f34b62d883R3310
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `util/yaml2json.py`
  Content:
  ```
  1 #!/usr/bin/env python3
  2 
  3 import yaml
  4 import json
  5 
  6 from argparse import ArgumentParser
  7 
  8 __author__ = 'cjm'
  9 
  10 
  11 parser = ArgumentParser(description="Converts a YAML file to JSON, writing the result to STDOUT")
  12 parser.add_argument('yaml_file', type=str, help='YAML file to convert')
  13 args = parser.parse_args()
  14 
  15 with open(args.yaml_file, 'r') as stream:
  16   data = yaml.load(stream, Loader=yaml.SafeLoader)
  17 data['@context'] = "http://obofoundry.github.io/registry/context.jsonld"
  18 json = json.dumps(data, sort_keys=True, indent=4, separators=(',', ': '))
  19 print(json)
  20
  ```
  
  Path: `util/sort-ontologies.py`
  Content:
  ```
  1 #!/usr/bin/env python3
  2 
  3 import csv
  4 import sys
  5 import yaml
  6 
  7 from argparse import ArgumentParser
  8 
  9 
  10 def main(args):
  11   parser = ArgumentParser(description='''
  12   Takes a YAML file containing information for various ontologies and a metadata file specifying
  13   the sorting order for ontologies, and then produces a sorted version input YAML''')
  14   parser.add_argument('unsorted_yaml', type=str,
  15                       help='Unsorted YAML file containing information for ontologies')
  16   parser.add_argument('metadata_grid', type=str,
  17                       help='CSV or TSV file containing metadata information for ontologies')
  18   parser.add_argument('output_yaml', type=str,
  19                       help='Name of output YAML file that will contain sorted ontology information')
  20   args = parser.parse_args()
  21 
  22   data_file = args.unsorted_yaml
  23   grid = args.metadata_grid
  24   output = args.output_yaml
  25 
  26   sort_order = get_sort_order(grid)
  27   data = load_data(data_file)
  28   data = sort_ontologies(data, sort_order)
  29   write_data(data, output)
  30 
  31 
  32 def get_sort_order(grid):
  33   '''Given the path to the metadata grid (CSV or TSV), extract the order of
  34   ontologies from the grid. Return the list of ontology IDs in that order.'''
  35   sort_order = []
  36   if '.csv' in grid:
  37     separator = ','
  38   elif '.tsv' or '.txt' in grid:
  39     separator = '\t'
  40   else:
  41     print('%s must be tab- or comma-separated.', file=sys.stderr)
  42     sys.exit(1)
  43   with open(grid, 'r') as f:
  44     reader = csv.reader(f, delimiter=separator)
  45     # Ignore the header row:
  46     next(reader)
  47     for row in reader:
  48       # Ontology IDs are in the first column of the CSV/TSV. We simply pull them out of each line
  49       # in the file. Their ordering in the file is the sort ordering we are looking for:
  50       sort_order.append(row[0])
  51   return sort_order
  52 
  53 
  54 def load_data(data_file):
  55   '''Given a YAML file, load the data into a dictionary.'''
  56   stream = open(data_file, 'r')
  57   data = yaml.load(stream, Loader=yaml.SafeLoader)
  58   return data
  59 
  60 
  61 def sort_ontologies(data, sort_order):
  62   '''Given the ontologies data as a dictionary and the list of ontologies in
  63   proper sort order, return the sorted data.'''
  64   ontologies = []
  65   for ont_id in sort_order:
  66     # We assume that ontology ids are unique:
  67     ont = [ont for ont in data['ontologies'] if ont['id'] == ont_id].pop()
  68     ontologies.append(ont)
  69   data['ontologies'] = ontologies
  70   return data
  71 
  72 
  73 def write_data(data, output):
  74   '''Given the ontologies data as a dictionary and an output YAML file to
  75   write to, write the data to the file. '''
  76   yaml_str = yaml.dump(data)
  77   with open(output, 'w') as f:
  78     f.write(yaml_str)
  79 
  80 
  81 if __name__ == '__main__':
  82   main(sys.argv)
  83
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/util/sort-ontologies.py b/util/sort-ontologies.py
  --- a/util/sort-ontologies.py
  +++ b/util/sort-ontologies.py
  @@ -73,9 +73,8 @@
   def write_data(data, output):
     '''Given the ontologies data as a dictionary and an output YAML file to
     write to, write the data to the file. '''
  -  yaml_str = yaml.dump(data)
     with open(output, 'w') as f:
  -    f.write(yaml_str)
  +    yaml.safe_dump(data, f, allow_unicode=True)
   
   
   if __name__ == '__main__':
  diff --git a/util/yaml2json.py b/util/yaml2json.py
  --- a/util/yaml2json.py
  +++ b/util/yaml2json.py
  @@ -15,5 +15,5 @@
   with open(args.yaml_file, 'r') as stream:
     data = yaml.load(stream, Loader=yaml.SafeLoader)
   data['@context'] = "http://obofoundry.github.io/registry/context.jsonld"
  -json = json.dumps(data, sort_keys=True, indent=4, separators=(',', ': '))
  +json = json.dumps(data, sort_keys=True, indent=4, ensure_ascii=False, separators=(',', ': '))
   print(json)
  
verification_info: {"golden_diff": "diff --git a/util/sort-ontologies.py b/util/sort-ontologies.py\n--- a/util/sort-ontologies.py\n+++ b/util/sort-ontologies.py\n@@ -73,9 +73,8 @@\n def write_data(data, output):\n   '''Given the ontologies data as a dictionary and an output YAML file to\n   write to, write the data to the file. '''\n-  yaml_str = yaml.dump(data)\n   with open(output, 'w') as f:\n-    f.write(yaml_str)\n+    yaml.safe_dump(data, f, allow_unicode=True)\n \n \n if __name__ == '__main__':\ndiff --git a/util/yaml2json.py b/util/yaml2json.py\n--- a/util/yaml2json.py\n+++ b/util/yaml2json.py\n@@ -15,5 +15,5 @@\n with open(args.yaml_file, 'r') as stream:\n   data = yaml.load(stream, Loader=yaml.SafeLoader)\n data['@context'] = \"http://obofoundry.github.io/registry/context.jsonld\"\n-json = json.dumps(data, sort_keys=True, indent=4, separators=(',', ': '))\n+json = json.dumps(data, sort_keys=True, indent=4, ensure_ascii=False, separators=(',', ': '))\n print(json)\n", "issue": "Names with non ASCII characters deteriorate during metadata integration\nRaw data:\r\nhttps://github.com/OBOFoundry/OBOFoundry.github.io/blob/master/ontology/lepao.md?plain=1#L7\r\n\r\nResult:\r\nhttps://github.com/OBOFoundry/OBOFoundry.github.io/pull/1690/files#diff-ecec67b0e1d7e17a83587c6d27b6baaaa133f42482b07bd3685c77f34b62d883R3310\n", "before_files": [{"content": "#!/usr/bin/env python3\n\nimport yaml\nimport json\n\nfrom argparse import ArgumentParser\n\n__author__ = 'cjm'\n\n\nparser = ArgumentParser(description=\"Converts a YAML file to JSON, writing the result to STDOUT\")\nparser.add_argument('yaml_file', type=str, help='YAML file to convert')\nargs = parser.parse_args()\n\nwith open(args.yaml_file, 'r') as stream:\n  data = yaml.load(stream, Loader=yaml.SafeLoader)\ndata['@context'] = \"http://obofoundry.github.io/registry/context.jsonld\"\njson = json.dumps(data, sort_keys=True, indent=4, separators=(',', ': '))\nprint(json)\n", "path": "util/yaml2json.py"}, {"content": "#!/usr/bin/env python3\n\nimport csv\nimport sys\nimport yaml\n\nfrom argparse import ArgumentParser\n\n\ndef main(args):\n  parser = ArgumentParser(description='''\n  Takes a YAML file containing information for various ontologies and a metadata file specifying\n  the sorting order for ontologies, and then produces a sorted version input YAML''')\n  parser.add_argument('unsorted_yaml', type=str,\n                      help='Unsorted YAML file containing information for ontologies')\n  parser.add_argument('metadata_grid', type=str,\n                      help='CSV or TSV file containing metadata information for ontologies')\n  parser.add_argument('output_yaml', type=str,\n                      help='Name of output YAML file that will contain sorted ontology information')\n  args = parser.parse_args()\n\n  data_file = args.unsorted_yaml\n  grid = args.metadata_grid\n  output = args.output_yaml\n\n  sort_order = get_sort_order(grid)\n  data = load_data(data_file)\n  data = sort_ontologies(data, sort_order)\n  write_data(data, output)\n\n\ndef get_sort_order(grid):\n  '''Given the path to the metadata grid (CSV or TSV), extract the order of\n  ontologies from the grid. Return the list of ontology IDs in that order.'''\n  sort_order = []\n  if '.csv' in grid:\n    separator = ','\n  elif '.tsv' or '.txt' in grid:\n    separator = '\\t'\n  else:\n    print('%s must be tab- or comma-separated.', file=sys.stderr)\n    sys.exit(1)\n  with open(grid, 'r') as f:\n    reader = csv.reader(f, delimiter=separator)\n    # Ignore the header row:\n    next(reader)\n    for row in reader:\n      # Ontology IDs are in the first column of the CSV/TSV. We simply pull them out of each line\n      # in the file. Their ordering in the file is the sort ordering we are looking for:\n      sort_order.append(row[0])\n  return sort_order\n\n\ndef load_data(data_file):\n  '''Given a YAML file, load the data into a dictionary.'''\n  stream = open(data_file, 'r')\n  data = yaml.load(stream, Loader=yaml.SafeLoader)\n  return data\n\n\ndef sort_ontologies(data, sort_order):\n  '''Given the ontologies data as a dictionary and the list of ontologies in\n  proper sort order, return the sorted data.'''\n  ontologies = []\n  for ont_id in sort_order:\n    # We assume that ontology ids are unique:\n    ont = [ont for ont in data['ontologies'] if ont['id'] == ont_id].pop()\n    ontologies.append(ont)\n  data['ontologies'] = ontologies\n  return data\n\n\ndef write_data(data, output):\n  '''Given the ontologies data as a dictionary and an output YAML file to\n  write to, write the data to the file. '''\n  yaml_str = yaml.dump(data)\n  with open(output, 'w') as f:\n    f.write(yaml_str)\n\n\nif __name__ == '__main__':\n  main(sys.argv)\n", "path": "util/sort-ontologies.py"}], "after_files": [{"content": "#!/usr/bin/env python3\n\nimport yaml\nimport json\n\nfrom argparse import ArgumentParser\n\n__author__ = 'cjm'\n\n\nparser = ArgumentParser(description=\"Converts a YAML file to JSON, writing the result to STDOUT\")\nparser.add_argument('yaml_file', type=str, help='YAML file to convert')\nargs = parser.parse_args()\n\nwith open(args.yaml_file, 'r') as stream:\n  data = yaml.load(stream, Loader=yaml.SafeLoader)\ndata['@context'] = \"http://obofoundry.github.io/registry/context.jsonld\"\njson = json.dumps(data, sort_keys=True, indent=4, ensure_ascii=False, separators=(',', ': '))\nprint(json)\n", "path": "util/yaml2json.py"}, {"content": "#!/usr/bin/env python3\n\nimport csv\nimport sys\nimport yaml\n\nfrom argparse import ArgumentParser\n\n\ndef main(args):\n  parser = ArgumentParser(description='''\n  Takes a YAML file containing information for various ontologies and a metadata file specifying\n  the sorting order for ontologies, and then produces a sorted version input YAML''')\n  parser.add_argument('unsorted_yaml', type=str,\n                      help='Unsorted YAML file containing information for ontologies')\n  parser.add_argument('metadata_grid', type=str,\n                      help='CSV or TSV file containing metadata information for ontologies')\n  parser.add_argument('output_yaml', type=str,\n                      help='Name of output YAML file that will contain sorted ontology information')\n  args = parser.parse_args()\n\n  data_file = args.unsorted_yaml\n  grid = args.metadata_grid\n  output = args.output_yaml\n\n  sort_order = get_sort_order(grid)\n  data = load_data(data_file)\n  data = sort_ontologies(data, sort_order)\n  write_data(data, output)\n\n\ndef get_sort_order(grid):\n  '''Given the path to the metadata grid (CSV or TSV), extract the order of\n  ontologies from the grid. Return the list of ontology IDs in that order.'''\n  sort_order = []\n  if '.csv' in grid:\n    separator = ','\n  elif '.tsv' or '.txt' in grid:\n    separator = '\\t'\n  else:\n    print('%s must be tab- or comma-separated.', file=sys.stderr)\n    sys.exit(1)\n  with open(grid, 'r') as f:\n    reader = csv.reader(f, delimiter=separator)\n    # Ignore the header row:\n    next(reader)\n    for row in reader:\n      # Ontology IDs are in the first column of the CSV/TSV. We simply pull them out of each line\n      # in the file. Their ordering in the file is the sort ordering we are looking for:\n      sort_order.append(row[0])\n  return sort_order\n\n\ndef load_data(data_file):\n  '''Given a YAML file, load the data into a dictionary.'''\n  stream = open(data_file, 'r')\n  data = yaml.load(stream, Loader=yaml.SafeLoader)\n  return data\n\n\ndef sort_ontologies(data, sort_order):\n  '''Given the ontologies data as a dictionary and the list of ontologies in\n  proper sort order, return the sorted data.'''\n  ontologies = []\n  for ont_id in sort_order:\n    # We assume that ontology ids are unique:\n    ont = [ont for ont in data['ontologies'] if ont['id'] == ont_id].pop()\n    ontologies.append(ont)\n  data['ontologies'] = ontologies\n  return data\n\n\ndef write_data(data, output):\n  '''Given the ontologies data as a dictionary and an output YAML file to\n  write to, write the data to the file. '''\n  with open(output, 'w') as f:\n    yaml.safe_dump(data, f, allow_unicode=True)\n\n\nif __name__ == '__main__':\n  main(sys.argv)\n", "path": "util/sort-ontologies.py"}]}