prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  [beta][v20] S'inscrire/se connecter/chercher avec un emoji provoque une 500
  Serveur : Beta
  Version : v20-RC3/d3fd8af
  Système : Mac OS X
  Navigateur : 52.0.2743.116 (64-bit)
  
  ---
  1. Rendez-vous à la page d'inscription et renseigner un pseudo du type : 👚 test
  2. Remplissez les autres champs.
  3. Soumettez le formulaire.
  4. Constatez une erreur 500.
  
  Note : Vous pouvez reproduire la même erreur en tentant de vous connecter avec le même pseudo ou en faisant une recherche sur le pseudo d'un membre.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `zds/utils/misc.py`
  Content:
  ```
  1 # coding: utf-8
  2 import hashlib
  3 import re
  4 
  5 THUMB_MAX_WIDTH = 80
  6 THUMB_MAX_HEIGHT = 80
  7 
  8 MEDIUM_MAX_WIDTH = 200
  9 MEDIUM_MAX_HEIGHT = 200
  10 
  11 
  12 def compute_hash(filenames):
  13     """returns a md5 hexdigest of group of files to check if they have change"""
  14     md5_hash = hashlib.md5()
  15     for filename in filenames:
  16         if filename:
  17             file_handle = open(filename, 'rb')
  18             must_continue = True
  19             while must_continue:
  20                 read_bytes = file_handle.read(8096)
  21                 if not read_bytes:
  22                     must_continue = False
  23                 else:
  24                     md5_hash.update(read_bytes)
  25     return md5_hash.hexdigest()
  26 
  27 
  28 def content_has_changed(filenames, md5):
  29     return md5 != compute_hash(filenames)
  30 
  31 
  32 def has_changed(instance, field, manager='objects'):
  33     """Returns true if a field has changed in a model May be used in a
  34     model.save() method."""
  35     if not instance.pk:
  36         return True
  37     manager = getattr(instance.__class__, manager)
  38     old = getattr(manager.get(pk=instance.pk), field)
  39     return not getattr(instance, field) == old
  40 
  41 
  42 def convert_camel_to_underscore(camel_case):
  43     """
  44     Converts a name in camel case to underscore.
  45     """
  46     s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', camel_case)
  47     return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
  48 
  49 
  50 def contains_utf8mb4(s):
  51     """
  52     This string contains at least one character of more than 3 bytes
  53     """
  54     if not isinstance(s, unicode):
  55         s = unicode(s, 'utf-8')
  56     return not all(len(c.encode('utf-8')) <= 3 for c in s)
  57
  ```
  --- 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/zds/utils/misc.py b/zds/utils/misc.py
  --- a/zds/utils/misc.py
  +++ b/zds/utils/misc.py
  @@ -53,4 +53,5 @@
       """
       if not isinstance(s, unicode):
           s = unicode(s, 'utf-8')
  -    return not all(len(c.encode('utf-8')) <= 3 for c in s)
  +    re_pattern = re.compile(u'[^\u0000-\uD7FF\uE000-\uFFFF]', re.UNICODE)
  +    return s != re_pattern.sub(u'\uFFFD', s)
  
verification_info: {"golden_diff": "diff --git a/zds/utils/misc.py b/zds/utils/misc.py\n--- a/zds/utils/misc.py\n+++ b/zds/utils/misc.py\n@@ -53,4 +53,5 @@\n     \"\"\"\n     if not isinstance(s, unicode):\n         s = unicode(s, 'utf-8')\n-    return not all(len(c.encode('utf-8')) <= 3 for c in s)\n+    re_pattern = re.compile(u'[^\\u0000-\\uD7FF\\uE000-\\uFFFF]', re.UNICODE)\n+    return s != re_pattern.sub(u'\\uFFFD', s)\n", "issue": "[beta][v20] S'inscrire/se connecter/chercher avec un emoji provoque une 500\nServeur : Beta\nVersion : v20-RC3/d3fd8af\nSyst\u00e8me : Mac OS X\nNavigateur : 52.0.2743.116 (64-bit)\n\n---\n1. Rendez-vous \u00e0 la page d'inscription et renseigner un pseudo du type : \ud83d\udc5a test\n2. Remplissez les autres champs.\n3. Soumettez le formulaire.\n4. Constatez une erreur 500.\n\nNote : Vous pouvez reproduire la m\u00eame erreur en tentant de vous connecter avec le m\u00eame pseudo ou en faisant une recherche sur le pseudo d'un membre.\n\n", "before_files": [{"content": "# coding: utf-8\nimport hashlib\nimport re\n\nTHUMB_MAX_WIDTH = 80\nTHUMB_MAX_HEIGHT = 80\n\nMEDIUM_MAX_WIDTH = 200\nMEDIUM_MAX_HEIGHT = 200\n\n\ndef compute_hash(filenames):\n    \"\"\"returns a md5 hexdigest of group of files to check if they have change\"\"\"\n    md5_hash = hashlib.md5()\n    for filename in filenames:\n        if filename:\n            file_handle = open(filename, 'rb')\n            must_continue = True\n            while must_continue:\n                read_bytes = file_handle.read(8096)\n                if not read_bytes:\n                    must_continue = False\n                else:\n                    md5_hash.update(read_bytes)\n    return md5_hash.hexdigest()\n\n\ndef content_has_changed(filenames, md5):\n    return md5 != compute_hash(filenames)\n\n\ndef has_changed(instance, field, manager='objects'):\n    \"\"\"Returns true if a field has changed in a model May be used in a\n    model.save() method.\"\"\"\n    if not instance.pk:\n        return True\n    manager = getattr(instance.__class__, manager)\n    old = getattr(manager.get(pk=instance.pk), field)\n    return not getattr(instance, field) == old\n\n\ndef convert_camel_to_underscore(camel_case):\n    \"\"\"\n    Converts a name in camel case to underscore.\n    \"\"\"\n    s1 = re.sub('(.)([A-Z][a-z]+)', r'\\1_\\2', camel_case)\n    return re.sub('([a-z0-9])([A-Z])', r'\\1_\\2', s1).lower()\n\n\ndef contains_utf8mb4(s):\n    \"\"\"\n    This string contains at least one character of more than 3 bytes\n    \"\"\"\n    if not isinstance(s, unicode):\n        s = unicode(s, 'utf-8')\n    return not all(len(c.encode('utf-8')) <= 3 for c in s)\n", "path": "zds/utils/misc.py"}], "after_files": [{"content": "# coding: utf-8\nimport hashlib\nimport re\n\nTHUMB_MAX_WIDTH = 80\nTHUMB_MAX_HEIGHT = 80\n\nMEDIUM_MAX_WIDTH = 200\nMEDIUM_MAX_HEIGHT = 200\n\n\ndef compute_hash(filenames):\n    \"\"\"returns a md5 hexdigest of group of files to check if they have change\"\"\"\n    md5_hash = hashlib.md5()\n    for filename in filenames:\n        if filename:\n            file_handle = open(filename, 'rb')\n            must_continue = True\n            while must_continue:\n                read_bytes = file_handle.read(8096)\n                if not read_bytes:\n                    must_continue = False\n                else:\n                    md5_hash.update(read_bytes)\n    return md5_hash.hexdigest()\n\n\ndef content_has_changed(filenames, md5):\n    return md5 != compute_hash(filenames)\n\n\ndef has_changed(instance, field, manager='objects'):\n    \"\"\"Returns true if a field has changed in a model May be used in a\n    model.save() method.\"\"\"\n    if not instance.pk:\n        return True\n    manager = getattr(instance.__class__, manager)\n    old = getattr(manager.get(pk=instance.pk), field)\n    return not getattr(instance, field) == old\n\n\ndef convert_camel_to_underscore(camel_case):\n    \"\"\"\n    Converts a name in camel case to underscore.\n    \"\"\"\n    s1 = re.sub('(.)([A-Z][a-z]+)', r'\\1_\\2', camel_case)\n    return re.sub('([a-z0-9])([A-Z])', r'\\1_\\2', s1).lower()\n\n\ndef contains_utf8mb4(s):\n    \"\"\"\n    This string contains at least one character of more than 3 bytes\n    \"\"\"\n    if not isinstance(s, unicode):\n        s = unicode(s, 'utf-8')\n    re_pattern = re.compile(u'[^\\u0000-\\uD7FF\\uE000-\\uFFFF]', re.UNICODE)\n    return s != re_pattern.sub(u'\\uFFFD', s)\n", "path": "zds/utils/misc.py"}]}