Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Claude Paroz authored May 25, 2012
14  django/contrib/formtools/tests/wizard/namedwizardtests/tests.py
@@ -120,7 +120,7 @@ def test_form_finish(self):
120 120
         self.assertEqual(response.context['wizard']['steps'].current, 'form2')
121 121
 
122 122
         post_data = self.wizard_step_data[1]
123  
-        post_data['form2-file1'] = open(__file__)
  123
+        post_data['form2-file1'] = open(__file__, 'rb')
124 124
         response = self.client.post(
125 125
             reverse(self.wizard_urlname,
126 126
                     kwargs={'step': response.context['wizard']['steps'].current}),
@@ -147,7 +147,7 @@ def test_form_finish(self):
147 147
         self.assertEqual(response.status_code, 200)
148 148
 
149 149
         all_data = response.context['form_list']
150  
-        self.assertEqual(all_data[1]['file1'].read(), open(__file__).read())
  150
+        self.assertEqual(all_data[1]['file1'].read(), open(__file__, 'rb').read())
151 151
         del all_data[1]['file1']
152 152
         self.assertEqual(all_data, [
153 153
             {'name': u'Pony', 'thirsty': True, 'user': self.testuser},
@@ -168,7 +168,7 @@ def test_cleaned_data(self):
168 168
         self.assertEqual(response.status_code, 200)
169 169
 
170 170
         post_data = self.wizard_step_data[1]
171  
-        post_data['form2-file1'] = open(__file__)
  171
+        post_data['form2-file1'] = open(__file__, 'rb')
172 172
         response = self.client.post(
173 173
             reverse(self.wizard_urlname,
174 174
                     kwargs={'step': response.context['wizard']['steps'].current}),
@@ -180,7 +180,9 @@ def test_cleaned_data(self):
180 180
         response = self.client.get(step2_url)
181 181
         self.assertEqual(response.status_code, 200)
182 182
         self.assertEqual(response.context['wizard']['steps'].current, 'form2')
183  
-        self.assertEqual(response.context['wizard']['form'].files['form2-file1'].read(), open(__file__).read())
  183
+        self.assertEqual(
  184
+            response.context['wizard']['form'].files['form2-file1'].read(),
  185
+            open(__file__, 'rb').read())
184 186
 
185 187
         response = self.client.post(
186 188
             reverse(self.wizard_urlname,
@@ -197,7 +199,7 @@ def test_cleaned_data(self):
197 199
         self.assertEqual(response.status_code, 200)
198 200
 
199 201
         all_data = response.context['all_cleaned_data']
200  
-        self.assertEqual(all_data['file1'].read(), open(__file__).read())
  202
+        self.assertEqual(all_data['file1'].read(), open(__file__, 'rb').read())
201 203
         del all_data['file1']
202 204
         self.assertEqual(
203 205
             all_data,
@@ -221,7 +223,7 @@ def test_manipulated_data(self):
221 223
         self.assertEqual(response.status_code, 200)
222 224
 
223 225
         post_data = self.wizard_step_data[1]
224  
-        post_data['form2-file1'] = open(__file__)
  226
+        post_data['form2-file1'] = open(__file__, 'rb')
225 227
         response = self.client.post(
226 228
             reverse(self.wizard_urlname,
227 229
                     kwargs={'step': response.context['wizard']['steps'].current}),
12  django/contrib/formtools/tests/wizard/wizardtests/tests.py
@@ -80,7 +80,7 @@ def test_form_finish(self):
80 80
         self.assertEqual(response.context['wizard']['steps'].current, 'form2')
81 81
 
82 82
         post_data = self.wizard_step_data[1]
83  
-        post_data['form2-file1'] = open(__file__)
  83
+        post_data['form2-file1'] = open(__file__, 'rb')
84 84
         response = self.client.post(self.wizard_url, post_data)
85 85
         self.assertEqual(response.status_code, 200)
86 86
         self.assertEqual(response.context['wizard']['steps'].current, 'form3')
@@ -93,7 +93,7 @@ def test_form_finish(self):
93 93
         self.assertEqual(response.status_code, 200)
94 94
 
95 95
         all_data = response.context['form_list']
96  
-        self.assertEqual(all_data[1]['file1'].read(), open(__file__).read())
  96
+        self.assertEqual(all_data[1]['file1'].read(), open(__file__, 'rb').read())
97 97
         del all_data[1]['file1']
98 98
         self.assertEqual(all_data, [
99 99
             {'name': u'Pony', 'thirsty': True, 'user': self.testuser},
@@ -110,7 +110,7 @@ def test_cleaned_data(self):
110 110
         self.assertEqual(response.status_code, 200)
111 111
 
112 112
         post_data = self.wizard_step_data[1]
113  
-        post_data['form2-file1'] = open(__file__)
  113
+        post_data['form2-file1'] = open(__file__, 'rb')
114 114
         response = self.client.post(self.wizard_url, post_data)
115 115
         self.assertEqual(response.status_code, 200)
116 116
 
@@ -121,7 +121,7 @@ def test_cleaned_data(self):
121 121
         self.assertEqual(response.status_code, 200)
122 122
 
123 123
         all_data = response.context['all_cleaned_data']
124  
-        self.assertEqual(all_data['file1'].read(), open(__file__).read())
  124
+        self.assertEqual(all_data['file1'].read(), open(__file__, 'rb').read())
125 125
         del all_data['file1']
126 126
         self.assertEqual(all_data, {
127 127
             'name': u'Pony', 'thirsty': True, 'user': self.testuser,
@@ -138,7 +138,7 @@ def test_manipulated_data(self):
138 138
         self.assertEqual(response.status_code, 200)
139 139
 
140 140
         post_data = self.wizard_step_data[1]
141  
-        post_data['form2-file1'] = open(__file__)
  141
+        post_data['form2-file1'] = open(__file__, 'rb')
142 142
         response = self.client.post(self.wizard_url, post_data)
143 143
         self.assertEqual(response.status_code, 200)
144 144
 
@@ -165,7 +165,7 @@ def test_form_refresh(self):
165 165
         self.assertEqual(response.context['wizard']['steps'].current, 'form2')
166 166
 
167 167
         post_data = self.wizard_step_data[1]
168  
-        post_data['form2-file1'] = open(__file__)
  168
+        post_data['form2-file1'] = open(__file__, 'rb')
169 169
         response = self.client.post(self.wizard_url, post_data)
170 170
         self.assertEqual(response.status_code, 200)
171 171
         self.assertEqual(response.context['wizard']['steps'].current, 'form3')
2  django/core/management/commands/compilemessages.py
@@ -5,7 +5,7 @@
5 5
 from django.core.management.base import BaseCommand, CommandError
6 6
 
7 7
 def has_bom(fn):
8  
-    with open(fn, 'r') as f:
  8
+    with open(fn, 'rb') as f:
9 9
         sample = f.read(4)
10 10
     return sample[:3] == '\xef\xbb\xbf' or \
11 11
             sample.startswith(codecs.BOM_UTF16_LE) or \
2  django/template/loaders/app_directories.py
@@ -52,7 +52,7 @@ def get_template_sources(self, template_name, template_dirs=None):
52 52
     def load_template_source(self, template_name, template_dirs=None):
53 53
         for filepath in self.get_template_sources(template_name, template_dirs):
54 54
             try:
55  
-                with open(filepath) as fp:
  55
+                with open(filepath, 'rb') as fp:
56 56
                     return (fp.read().decode(settings.FILE_CHARSET), filepath)
57 57
             except IOError:
58 58
                 pass
2  django/template/loaders/filesystem.py
@@ -34,7 +34,7 @@ def load_template_source(self, template_name, template_dirs=None):
34 34
         tried = []
35 35
         for filepath in self.get_template_sources(template_name, template_dirs):
36 36
             try:
37  
-                with open(filepath) as fp:
  37
+                with open(filepath, 'rb') as fp:
38 38
                     return (fp.read().decode(settings.FILE_CHARSET), filepath)
39 39
             except IOError:
40 40
                 tried.append(filepath)
10  tests/regressiontests/views/tests/static.py
@@ -29,7 +29,7 @@ def test_serve(self):
29 29
         for filename in media_files:
30 30
             response = self.client.get('/views/%s/%s' % (self.prefix, filename))
31 31
             file_path = path.join(media_dir, filename)
32  
-            with open(file_path) as fp:
  32
+            with open(file_path, 'rb') as fp:
33 33
                 self.assertEqual(fp.read(), response.content)
34 34
             self.assertEqual(len(response.content), int(response['Content-Length']))
35 35
             self.assertEqual(mimetypes.guess_type(file_path)[1], response.get('Content-Encoding', None))
@@ -41,14 +41,14 @@ def test_unknown_mime_type(self):
41 41
     def test_copes_with_empty_path_component(self):
42 42
         file_name = 'file.txt'
43 43
         response = self.client.get('/views/%s//%s' % (self.prefix, file_name))
44  
-        with open(path.join(media_dir, file_name)) as fp:
  44
+        with open(path.join(media_dir, file_name), 'rb') as fp:
45 45
             self.assertEqual(fp.read(), response.content)
46 46
 
47 47
     def test_is_modified_since(self):
48 48
         file_name = 'file.txt'
49 49
         response = self.client.get('/views/%s/%s' % (self.prefix, file_name),
50 50
             HTTP_IF_MODIFIED_SINCE='Thu, 1 Jan 1970 00:00:00 GMT')
51  
-        with open(path.join(media_dir, file_name)) as fp:
  51
+        with open(path.join(media_dir, file_name), 'rb') as fp:
52 52
             self.assertEqual(fp.read(), response.content)
53 53
 
54 54
     def test_not_modified_since(self):
@@ -71,7 +71,7 @@ def test_invalid_if_modified_since(self):
71 71
         invalid_date = 'Mon, 28 May 999999999999 28:25:26 GMT'
72 72
         response = self.client.get('/views/%s/%s' % (self.prefix, file_name),
73 73
                                    HTTP_IF_MODIFIED_SINCE=invalid_date)
74  
-        with open(path.join(media_dir, file_name)) as fp:
  74
+        with open(path.join(media_dir, file_name), 'rb') as fp:
75 75
             self.assertEqual(fp.read(), response.content)
76 76
         self.assertEqual(len(response.content),
77 77
                           int(response['Content-Length']))
@@ -86,7 +86,7 @@ def test_invalid_if_modified_since2(self):
86 86
         invalid_date = ': 1291108438, Wed, 20 Oct 2010 14:05:00 GMT'
87 87
         response = self.client.get('/views/%s/%s' % (self.prefix, file_name),
88 88
                                    HTTP_IF_MODIFIED_SINCE=invalid_date)
89  
-        with open(path.join(media_dir, file_name)) as fp:
  89
+        with open(path.join(media_dir, file_name), 'rb') as fp:
90 90
             self.assertEqual(fp.read(), response.content)
91 91
         self.assertEqual(len(response.content),
92 92
                           int(response['Content-Length']))

0 notes on commit edfa95c

Please sign in to comment.
Something went wrong with that request. Please try again.