From dc8786ce9413f5d8553997a6b957886694205fa2 Mon Sep 17 00:00:00 2001
From: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Sat, 29 Aug 2015 13:05:22 +0200
Subject: [PATCH] [1.8.x] Ensured gen_filenames() yields native strings.

This also fixes a test failure on Python 2 when Django is installed in a
non-ASCII path. This problem cannot happen on Python 3.

Backport of c2fcba2ac7 from master
---
 django/utils/autoreload.py           | 3 ++-
 tests/utils_tests/test_autoreload.py | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py
index 807a1f76ba..869020359a 100644
--- a/django/utils/autoreload.py
+++ b/django/utils/autoreload.py
@@ -40,6 +40,7 @@ import traceback
 from django.apps import apps
 from django.conf import settings
 from django.core.signals import request_finished
+from django.utils._os import npath
 from django.utils.six.moves import _thread as thread
 
 # This import does nothing, but it's necessary to avoid some race conditions
@@ -109,7 +110,7 @@ def gen_filenames(only_new=False):
                                  'conf', 'locale'),
                     'locale']
         for app_config in reversed(list(apps.get_app_configs())):
-            basedirs.append(os.path.join(app_config.path, 'locale'))
+            basedirs.append(os.path.join(npath(app_config.path), 'locale'))
         basedirs.extend(settings.LOCALE_PATHS)
         basedirs = [os.path.abspath(basedir) for basedir in basedirs
                     if os.path.isdir(basedir)]
diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py
index 079b89d830..181ee02b96 100644
--- a/tests/utils_tests/test_autoreload.py
+++ b/tests/utils_tests/test_autoreload.py
@@ -90,6 +90,10 @@ class TestFilenameGenerator(TestCase):
         django_mo = os.path.join(django_dir, 'nl', 'LC_MESSAGES', 'django.mo')
         self.assertFileNotFound(django_mo)
 
+    def test_paths_are_native_strings(self):
+        for filename in autoreload.gen_filenames():
+            self.assertIsInstance(filename, str)
+
     def test_only_new_files(self):
         """
         When calling a second time gen_filenames with only_new = True, only