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:
@@ -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
|
||||
|
Reference in New Issue
Block a user