Commits

Martin von Löwis committed b61b990

Issue #16926: Universal mode cannot be combined with binary in Python 3.

Comments (0)

Files changed (1)

django/core/management/sql.py

+import sys
 import os
 import re
 
                  os.path.join(app_dir, "%s.sql" % opts.object_name.lower())]
     for sql_file in sql_files:
         if os.path.exists(sql_file):
-            fp = open(sql_file, 'rbU')
-            for statement in statements.split(fp.read().decode(settings.FILE_CHARSET)):
+            if sys.version_info < (3,):
+                sql_data = open(sql_file, 'U').read().decode(settings.FILE_CHARSET)
+            else:
+                sql_data = open(sql_file, 'r', encoding=settings.FILE_CHARSET).read()
+            for statement in statements.split(sql_data):
                 # Remove any comments from the file
                 statement = re.sub(ur"--.*([\n\Z]|$)", "", statement)
                 if statement.strip():