Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Specified when open should use binary mode.

Thanks Vinaj Sajip for the help of his django3 branch.
  • Loading branch information...
commit edfa95c22ffe8f58060bb985ad1b6fbca9506f5e 1 parent e73838b
@claudep claudep authored
View
14 django/contrib/formtools/tests/wizard/namedwizardtests/tests.py
@@ -120,7 +120,7 @@ def test_form_finish(self):
self.assertEqual(response.context['wizard']['steps'].current, 'form2')
post_data = self.wizard_step_data[1]
- post_data['form2-file1'] = open(__file__)
+ post_data['form2-file1'] = open(__file__, 'rb')
response = self.client.post(
reverse(self.wizard_urlname,
kwargs={'step': response.context['wizard']['steps'].current}),
@@ -147,7 +147,7 @@ def test_form_finish(self):
self.assertEqual(response.status_code, 200)
all_data = response.context['form_list']
- self.assertEqual(all_data[1]['file1'].read(), open(__file__).read())
+ self.assertEqual(all_data[1]['file1'].read(), open(__file__, 'rb').read())
del all_data[1]['file1']
self.assertEqual(all_data, [
{'name': u'Pony', 'thirsty': True, 'user': self.testuser},
@@ -168,7 +168,7 @@ def test_cleaned_data(self):
self.assertEqual(response.status_code, 200)
post_data = self.wizard_step_data[1]
- post_data['form2-file1'] = open(__file__)
+ post_data['form2-file1'] = open(__file__, 'rb')
response = self.client.post(
reverse(self.wizard_urlname,
kwargs={'step': response.context['wizard']['steps'].current}),
@@ -180,7 +180,9 @@ def test_cleaned_data(self):
response = self.client.get(step2_url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['wizard']['steps'].current, 'form2')
- self.assertEqual(response.context['wizard']['form'].files['form2-file1'].read(), open(__file__).read())
+ self.assertEqual(
+ response.context['wizard']['form'].files['form2-file1'].read(),
+ open(__file__, 'rb').read())
response = self.client.post(
reverse(self.wizard_urlname,
@@ -197,7 +199,7 @@ def test_cleaned_data(self):
self.assertEqual(response.status_code, 200)
all_data = response.context['all_cleaned_data']
- self.assertEqual(all_data['file1'].read(), open(__file__).read())
+ self.assertEqual(all_data['file1'].read(), open(__file__, 'rb').read())
del all_data['file1']
self.assertEqual(
all_data,
@@ -221,7 +223,7 @@ def test_manipulated_data(self):
self.assertEqual(response.status_code, 200)
post_data = self.wizard_step_data[1]
- post_data['form2-file1'] = open(__file__)
+ post_data['form2-file1'] = open(__file__, 'rb')
response = self.client.post(
reverse(self.wizard_urlname,
kwargs={'step': response.context['wizard']['steps'].current}),
View
12 django/contrib/formtools/tests/wizard/wizardtests/tests.py
@@ -80,7 +80,7 @@ def test_form_finish(self):
self.assertEqual(response.context['wizard']['steps'].current, 'form2')
post_data = self.wizard_step_data[1]
- post_data['form2-file1'] = open(__file__)
+ post_data['form2-file1'] = open(__file__, 'rb')
response = self.client.post(self.wizard_url, post_data)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['wizard']['steps'].current, 'form3')
@@ -93,7 +93,7 @@ def test_form_finish(self):
self.assertEqual(response.status_code, 200)
all_data = response.context['form_list']
- self.assertEqual(all_data[1]['file1'].read(), open(__file__).read())
+ self.assertEqual(all_data[1]['file1'].read(), open(__file__, 'rb').read())
del all_data[1]['file1']
self.assertEqual(all_data, [
{'name': u'Pony', 'thirsty': True, 'user': self.testuser},
@@ -110,7 +110,7 @@ def test_cleaned_data(self):
self.assertEqual(response.status_code, 200)
post_data = self.wizard_step_data[1]
- post_data['form2-file1'] = open(__file__)
+ post_data['form2-file1'] = open(__file__, 'rb')
response = self.client.post(self.wizard_url, post_data)
self.assertEqual(response.status_code, 200)
@@ -121,7 +121,7 @@ def test_cleaned_data(self):
self.assertEqual(response.status_code, 200)
all_data = response.context['all_cleaned_data']
- self.assertEqual(all_data['file1'].read(), open(__file__).read())
+ self.assertEqual(all_data['file1'].read(), open(__file__, 'rb').read())
del all_data['file1']
self.assertEqual(all_data, {
'name': u'Pony', 'thirsty': True, 'user': self.testuser,
@@ -138,7 +138,7 @@ def test_manipulated_data(self):
self.assertEqual(response.status_code, 200)
post_data = self.wizard_step_data[1]
- post_data['form2-file1'] = open(__file__)
+ post_data['form2-file1'] = open(__file__, 'rb')
response = self.client.post(self.wizard_url, post_data)
self.assertEqual(response.status_code, 200)
@@ -165,7 +165,7 @@ def test_form_refresh(self):
self.assertEqual(response.context['wizard']['steps'].current, 'form2')
post_data = self.wizard_step_data[1]
- post_data['form2-file1'] = open(__file__)
+ post_data['form2-file1'] = open(__file__, 'rb')
response = self.client.post(self.wizard_url, post_data)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['wizard']['steps'].current, 'form3')
View
2  django/core/management/commands/compilemessages.py
@@ -5,7 +5,7 @@
from django.core.management.base import BaseCommand, CommandError
def has_bom(fn):
- with open(fn, 'r') as f:
+ with open(fn, 'rb') as f:
sample = f.read(4)
return sample[:3] == '\xef\xbb\xbf' or \
sample.startswith(codecs.BOM_UTF16_LE) or \
View
2  django/template/loaders/app_directories.py
@@ -52,7 +52,7 @@ def get_template_sources(self, template_name, template_dirs=None):
def load_template_source(self, template_name, template_dirs=None):
for filepath in self.get_template_sources(template_name, template_dirs):
try:
- with open(filepath) as fp:
+ with open(filepath, 'rb') as fp:
return (fp.read().decode(settings.FILE_CHARSET), filepath)
except IOError:
pass
View
2  django/template/loaders/filesystem.py
@@ -34,7 +34,7 @@ def load_template_source(self, template_name, template_dirs=None):
tried = []
for filepath in self.get_template_sources(template_name, template_dirs):
try:
- with open(filepath) as fp:
+ with open(filepath, 'rb') as fp:
return (fp.read().decode(settings.FILE_CHARSET), filepath)
except IOError:
tried.append(filepath)
View
10 tests/regressiontests/views/tests/static.py
@@ -29,7 +29,7 @@ def test_serve(self):
for filename in media_files:
response = self.client.get('/views/%s/%s' % (self.prefix, filename))
file_path = path.join(media_dir, filename)
- with open(file_path) as fp:
+ with open(file_path, 'rb') as fp:
self.assertEqual(fp.read(), response.content)
self.assertEqual(len(response.content), int(response['Content-Length']))
self.assertEqual(mimetypes.guess_type(file_path)[1], response.get('Content-Encoding', None))
@@ -41,14 +41,14 @@ def test_unknown_mime_type(self):
def test_copes_with_empty_path_component(self):
file_name = 'file.txt'
response = self.client.get('/views/%s//%s' % (self.prefix, file_name))
- with open(path.join(media_dir, file_name)) as fp:
+ with open(path.join(media_dir, file_name), 'rb') as fp:
self.assertEqual(fp.read(), response.content)
def test_is_modified_since(self):
file_name = 'file.txt'
response = self.client.get('/views/%s/%s' % (self.prefix, file_name),
HTTP_IF_MODIFIED_SINCE='Thu, 1 Jan 1970 00:00:00 GMT')
- with open(path.join(media_dir, file_name)) as fp:
+ with open(path.join(media_dir, file_name), 'rb') as fp:
self.assertEqual(fp.read(), response.content)
def test_not_modified_since(self):
@@ -71,7 +71,7 @@ def test_invalid_if_modified_since(self):
invalid_date = 'Mon, 28 May 999999999999 28:25:26 GMT'
response = self.client.get('/views/%s/%s' % (self.prefix, file_name),
HTTP_IF_MODIFIED_SINCE=invalid_date)
- with open(path.join(media_dir, file_name)) as fp:
+ with open(path.join(media_dir, file_name), 'rb') as fp:
self.assertEqual(fp.read(), response.content)
self.assertEqual(len(response.content),
int(response['Content-Length']))
@@ -86,7 +86,7 @@ def test_invalid_if_modified_since2(self):
invalid_date = ': 1291108438, Wed, 20 Oct 2010 14:05:00 GMT'
response = self.client.get('/views/%s/%s' % (self.prefix, file_name),
HTTP_IF_MODIFIED_SINCE=invalid_date)
- with open(path.join(media_dir, file_name)) as fp:
+ with open(path.join(media_dir, file_name), 'rb') as fp:
self.assertEqual(fp.read(), response.content)
self.assertEqual(len(response.content),
int(response['Content-Length']))
Please sign in to comment.
Something went wrong with that request. Please try again.