prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Corriger et refactoriser remove_url_scheme et ses tests
  On a une fonction utilitaire qui s'appelle [remove_url_scheme](https://github.com/zestedesavoir/zds-site/blob/03c8f316c46e51d42afb8b8d2d9553cdd8fb0f08/zds/utils/templatetags/remove_url_scheme.py#L9), qui permet d'enlever le schéma des urls (http ou https) et le nom du domaine, afin de toujours servir les ressources locales au site avec le bon protocole (http ou https).
  
  **Description du problème**
  
  Le problème actuellement, c'est qu'elle gère mal le nom du domaine spécifié dans l'environnement de dev, à savoir `ZDS_APP['site']['dns'] = 127.0.0.1:8000`, ce qui a pour effet de faire rater un des tests (zds.utils.tests.test_misc.Misc.test_remove_url_scheme), mais en **local seulement**, pas sur Travis. Il s'agit donc d'un faux positif sur l'environnement de dev, ce qui est pénible.
  
  **Comportement attendu**
  
  On devrait avoir le bon fonctionnement sur l'environnement de dev en gérant correctement le numéro de port à la fin de l'url. Au passage, on devrait aussi :
  
  * utiliser `urllib.parse` au lieu du module de `six` ;
  * réunir tous les tests de `remove_url_scheme` dans le bon fichier (actuellement c'est réparti dans `test_misc` et un fichier `test_remove_url_scheme`).
  
  
  --- 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/templatetags/remove_url_scheme.py`
  Content:
  ```
  1 from django import template
  2 from django.conf import settings
  3 from six.moves import urllib_parse as urlparse
  4 
  5 register = template.Library()
  6 
  7 
  8 @register.filter('remove_url_scheme')
  9 def remove_url_scheme(input_url):
  10     """
  11     make every image url pointing to this website protocol independant so that if we use https, we are sure
  12     that all our media are served with this protocol.
  13 
  14     .. notice::
  15 
  16         this also removes the ``settings.ZDS_APP['site']['dns']`` from the url.
  17 
  18     :return: the url without its scheme, e.g. ``http://zestedesavoir.com/media/gallery/1/1.png`` becomes
  19     ``/media/gallery/1/1.png``
  20 
  21     """
  22 
  23     schemeless_url = input_url[len(urlparse.urlparse(input_url).scheme):]
  24     schemeless_url = schemeless_url[len('://'):] if schemeless_url.startswith('://') else schemeless_url
  25     if schemeless_url.startswith(settings.ZDS_APP['site']['dns']):
  26         return schemeless_url[len(settings.ZDS_APP['site']['dns']):]
  27     return input_url
  28
  ```
  --- 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/templatetags/remove_url_scheme.py b/zds/utils/templatetags/remove_url_scheme.py
  --- a/zds/utils/templatetags/remove_url_scheme.py
  +++ b/zds/utils/templatetags/remove_url_scheme.py
  @@ -1,27 +1,37 @@
  +import urllib.parse
  +
   from django import template
   from django.conf import settings
  -from six.moves import urllib_parse as urlparse
   
   register = template.Library()
   
   
   @register.filter('remove_url_scheme')
  -def remove_url_scheme(input_url):
  +def remove_url_scheme(url):
       """
  -    make every image url pointing to this website protocol independant so that if we use https, we are sure
  -    that all our media are served with this protocol.
  -
  -    .. notice::
  +    Remove the scheme and hostname from a URL if it is internal, but leave it unchanged otherwise.
   
  -        this also removes the ``settings.ZDS_APP['site']['dns']`` from the url.
  +    The internal hostname is determined using the value of ``ZDS_APP['site']['dns']``.
  +    URLs with no scheme are accepted. URLs with no hostname are treated as internal.
   
  -    :return: the url without its scheme, e.g. ``http://zestedesavoir.com/media/gallery/1/1.png`` becomes
  -    ``/media/gallery/1/1.png``
  +    For example, ``http://zestedesavoir.com/media/gallery/1/1.png`` becomes ``/media/gallery/1/1.png``,
  +    whereas ``/media/gallery/1/1.png`` and ``example.com/media/gallery/1/1.png`` stay the same.
   
  +    :return: the url without its scheme and hostname.
       """
   
  -    schemeless_url = input_url[len(urlparse.urlparse(input_url).scheme):]
  -    schemeless_url = schemeless_url[len('://'):] if schemeless_url.startswith('://') else schemeless_url
  -    if schemeless_url.startswith(settings.ZDS_APP['site']['dns']):
  -        return schemeless_url[len(settings.ZDS_APP['site']['dns']):]
  -    return input_url
  +    # Parse URLs after adding a prefix if necessary (e.g 'zestedesavoir.com' becomes '//zestedesavoir.com')
  +    url_normalized = url
  +    if '//' not in url:
  +        url_normalized = '//' + url
  +    url_parsed = urllib.parse.urlsplit(url_normalized)
  +
  +    # Return external URLs unchanged
  +    if url_parsed.netloc != settings.ZDS_APP['site']['dns']:
  +        return url
  +
  +    # Clean internal URLs
  +    url_noscheme = urllib.parse.urlunsplit(['', '', url_parsed.path, url_parsed.query, url_parsed.fragment])
  +    url_cleaned = url_noscheme[0:]  # remove first "/"
  +
  +    return url_cleaned
  
verification_info: {"golden_diff": "diff --git a/zds/utils/templatetags/remove_url_scheme.py b/zds/utils/templatetags/remove_url_scheme.py\n--- a/zds/utils/templatetags/remove_url_scheme.py\n+++ b/zds/utils/templatetags/remove_url_scheme.py\n@@ -1,27 +1,37 @@\n+import urllib.parse\n+\n from django import template\n from django.conf import settings\n-from six.moves import urllib_parse as urlparse\n \n register = template.Library()\n \n \n @register.filter('remove_url_scheme')\n-def remove_url_scheme(input_url):\n+def remove_url_scheme(url):\n     \"\"\"\n-    make every image url pointing to this website protocol independant so that if we use https, we are sure\n-    that all our media are served with this protocol.\n-\n-    .. notice::\n+    Remove the scheme and hostname from a URL if it is internal, but leave it unchanged otherwise.\n \n-        this also removes the ``settings.ZDS_APP['site']['dns']`` from the url.\n+    The internal hostname is determined using the value of ``ZDS_APP['site']['dns']``.\n+    URLs with no scheme are accepted. URLs with no hostname are treated as internal.\n \n-    :return: the url without its scheme, e.g. ``http://zestedesavoir.com/media/gallery/1/1.png`` becomes\n-    ``/media/gallery/1/1.png``\n+    For example, ``http://zestedesavoir.com/media/gallery/1/1.png`` becomes ``/media/gallery/1/1.png``,\n+    whereas ``/media/gallery/1/1.png`` and ``example.com/media/gallery/1/1.png`` stay the same.\n \n+    :return: the url without its scheme and hostname.\n     \"\"\"\n \n-    schemeless_url = input_url[len(urlparse.urlparse(input_url).scheme):]\n-    schemeless_url = schemeless_url[len('://'):] if schemeless_url.startswith('://') else schemeless_url\n-    if schemeless_url.startswith(settings.ZDS_APP['site']['dns']):\n-        return schemeless_url[len(settings.ZDS_APP['site']['dns']):]\n-    return input_url\n+    # Parse URLs after adding a prefix if necessary (e.g 'zestedesavoir.com' becomes '//zestedesavoir.com')\n+    url_normalized = url\n+    if '//' not in url:\n+        url_normalized = '//' + url\n+    url_parsed = urllib.parse.urlsplit(url_normalized)\n+\n+    # Return external URLs unchanged\n+    if url_parsed.netloc != settings.ZDS_APP['site']['dns']:\n+        return url\n+\n+    # Clean internal URLs\n+    url_noscheme = urllib.parse.urlunsplit(['', '', url_parsed.path, url_parsed.query, url_parsed.fragment])\n+    url_cleaned = url_noscheme[0:]  # remove first \"/\"\n+\n+    return url_cleaned\n", "issue": "Corriger et refactoriser remove_url_scheme et ses tests\nOn a une fonction utilitaire qui s'appelle [remove_url_scheme](https://github.com/zestedesavoir/zds-site/blob/03c8f316c46e51d42afb8b8d2d9553cdd8fb0f08/zds/utils/templatetags/remove_url_scheme.py#L9), qui permet d'enlever le sch\u00e9ma des urls (http ou https) et le nom du domaine, afin de toujours servir les ressources locales au site avec le bon protocole (http ou https).\r\n\r\n**Description du probl\u00e8me**\r\n\r\nLe probl\u00e8me actuellement, c'est qu'elle g\u00e8re mal le nom du domaine sp\u00e9cifi\u00e9 dans l'environnement de dev, \u00e0 savoir `ZDS_APP['site']['dns'] = 127.0.0.1:8000`, ce qui a pour effet de faire rater un des tests (zds.utils.tests.test_misc.Misc.test_remove_url_scheme), mais en **local seulement**, pas sur Travis. Il s'agit donc d'un faux positif sur l'environnement de dev, ce qui est p\u00e9nible.\r\n\r\n**Comportement attendu**\r\n\r\nOn devrait avoir le bon fonctionnement sur l'environnement de dev en g\u00e9rant correctement le num\u00e9ro de port \u00e0 la fin de l'url. Au passage, on devrait aussi :\r\n\r\n* utiliser `urllib.parse` au lieu du module de `six` ;\r\n* r\u00e9unir tous les tests de `remove_url_scheme` dans le bon fichier (actuellement c'est r\u00e9parti dans `test_misc` et un fichier `test_remove_url_scheme`).\r\n\n", "before_files": [{"content": "from django import template\nfrom django.conf import settings\nfrom six.moves import urllib_parse as urlparse\n\nregister = template.Library()\n\n\n@register.filter('remove_url_scheme')\ndef remove_url_scheme(input_url):\n    \"\"\"\n    make every image url pointing to this website protocol independant so that if we use https, we are sure\n    that all our media are served with this protocol.\n\n    .. notice::\n\n        this also removes the ``settings.ZDS_APP['site']['dns']`` from the url.\n\n    :return: the url without its scheme, e.g. ``http://zestedesavoir.com/media/gallery/1/1.png`` becomes\n    ``/media/gallery/1/1.png``\n\n    \"\"\"\n\n    schemeless_url = input_url[len(urlparse.urlparse(input_url).scheme):]\n    schemeless_url = schemeless_url[len('://'):] if schemeless_url.startswith('://') else schemeless_url\n    if schemeless_url.startswith(settings.ZDS_APP['site']['dns']):\n        return schemeless_url[len(settings.ZDS_APP['site']['dns']):]\n    return input_url\n", "path": "zds/utils/templatetags/remove_url_scheme.py"}], "after_files": [{"content": "import urllib.parse\n\nfrom django import template\nfrom django.conf import settings\n\nregister = template.Library()\n\n\n@register.filter('remove_url_scheme')\ndef remove_url_scheme(url):\n    \"\"\"\n    Remove the scheme and hostname from a URL if it is internal, but leave it unchanged otherwise.\n\n    The internal hostname is determined using the value of ``ZDS_APP['site']['dns']``.\n    URLs with no scheme are accepted. URLs with no hostname are treated as internal.\n\n    For example, ``http://zestedesavoir.com/media/gallery/1/1.png`` becomes ``/media/gallery/1/1.png``,\n    whereas ``/media/gallery/1/1.png`` and ``example.com/media/gallery/1/1.png`` stay the same.\n\n    :return: the url without its scheme and hostname.\n    \"\"\"\n\n    # Parse URLs after adding a prefix if necessary (e.g 'zestedesavoir.com' becomes '//zestedesavoir.com')\n    url_normalized = url\n    if '//' not in url:\n        url_normalized = '//' + url\n    url_parsed = urllib.parse.urlsplit(url_normalized)\n\n    # Return external URLs unchanged\n    if url_parsed.netloc != settings.ZDS_APP['site']['dns']:\n        return url\n\n    # Clean internal URLs\n    url_noscheme = urllib.parse.urlunsplit(['', '', url_parsed.path, url_parsed.query, url_parsed.fragment])\n    url_cleaned = url_noscheme[0:]  # remove first \"/\"\n\n    return url_cleaned\n", "path": "zds/utils/templatetags/remove_url_scheme.py"}]}