fix error spotted by @andrewsg

This commit is contained in:
benoitc 2012-10-28 06:56:00 +01:00
parent f7b9a08c9c
commit e4fbc805b6
3 changed files with 10 additions and 4 deletions

View File

@ -1,6 +1,7 @@
# Create your views here.
import csv
import io
import os
from django import forms
from django.http import HttpResponse
@ -28,10 +29,15 @@ def home(request):
subject = form.cleaned_data['subject']
message = form.cleaned_data['message']
f = request.FILES['f']
if not hasattr(f, "fileno"):
size = len(f.read())
else:
size = int(os.fstat(f.fileno())[6])
try:
size = int(os.fstat(f.fileno())[6])
except io.UnsupportedOperation:
size = len(f.read())
else:
form = MsgForm()

View File

@ -275,7 +275,7 @@ class Response(object):
self.send_headers()
if isinstance(arg, text_type):
arg = arg.decode('utf-8')
arg = arg.encode('utf-8')
assert isinstance(arg, binary_type), "%r is not a byte." % arg

View File

@ -225,9 +225,9 @@ except ImportError:
def write_chunk(sock, data):
if isinstance(data, text_type):
data = data.decode('utf-8')
data = data.encode('utf-8')
chunk_size = "%X\r\n" % len(data)
chunk = b"".join([chunk_size.decode('utf-8'), data, b"\r\n"])
chunk = b"".join([chunk_size.encode('utf-8'), data, b"\r\n"])
sock.sendall(chunk)
def write(sock, data, chunked=False):