1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-16 07:08:55 +00:00

wrap tempfile.mkstemp to work on windows

The path returned by tempfile.mkstemp is encoded in system locale,
since we need to pass it through rpc, we need it to be encoded in UTF-8
This commit is contained in:
lins05
2013-04-25 13:43:09 +08:00
parent 11ec7ed43f
commit aa0dc23b0f
2 changed files with 14 additions and 3 deletions

View File

@@ -7,6 +7,8 @@ import urllib2
import uuid
import logging
import json
import tempfile
import locale
from django.contrib.sites.models import RequestSite
from django.db import IntegrityError
@@ -855,5 +857,15 @@ def redirect_to_login(request):
tup = login_url, redirect_field_name, path
return HttpResponseRedirect('%s?%s=%s' % tup)
def mkstemp():
'''Returns (fd, filepath), the same as tempfile.mkstemp, except the
filepath is encoded in UTF-8
'''
fd, path = tempfile.mkstemp()
system_encoding = locale.getdefaultlocale()[1]
path_utf8 = path.decode(system_encoding).encode('UTF-8')
return fd, path_utf8
# Move to here to avoid circular import.
from base.models import FileContributors, UserStarredFiles, DirFilesLastModifiedInfo, FileLastModifiedInfo