mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-17 15:53:28 +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 uuid
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
|
import tempfile
|
||||||
|
import locale
|
||||||
|
|
||||||
from django.contrib.sites.models import RequestSite
|
from django.contrib.sites.models import RequestSite
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
@@ -855,5 +857,15 @@ def redirect_to_login(request):
|
|||||||
tup = login_url, redirect_field_name, path
|
tup = login_url, redirect_field_name, path
|
||||||
return HttpResponseRedirect('%s?%s=%s' % tup)
|
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.
|
# Move to here to avoid circular import.
|
||||||
from base.models import FileContributors, UserStarredFiles, DirFilesLastModifiedInfo, FileLastModifiedInfo
|
from base.models import FileContributors, UserStarredFiles, DirFilesLastModifiedInfo, FileLastModifiedInfo
|
||||||
|
@@ -7,7 +7,6 @@ view_trash_file, view_snapshot_file
|
|||||||
import os
|
import os
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import stat
|
import stat
|
||||||
import tempfile
|
|
||||||
import urllib
|
import urllib
|
||||||
import urllib2
|
import urllib2
|
||||||
import chardet
|
import chardet
|
||||||
@@ -38,7 +37,7 @@ from seahub.wiki.models import WikiDoesNotExist, WikiPageMissing
|
|||||||
from seahub.utils import get_httpserver_root, show_delete_days, render_error, \
|
from seahub.utils import get_httpserver_root, show_delete_days, render_error, \
|
||||||
get_file_type_and_ext, gen_file_get_url, gen_shared_link, is_file_starred, \
|
get_file_type_and_ext, gen_file_get_url, gen_shared_link, is_file_starred, \
|
||||||
get_file_contributors, get_ccnetapplet_root, render_permission_error, \
|
get_file_contributors, get_ccnetapplet_root, render_permission_error, \
|
||||||
is_textual_file, show_delete_days
|
is_textual_file, show_delete_days, mkstemp
|
||||||
from seahub.utils.file_types import (IMAGE, PDF, IMAGE, DOCUMENT, MARKDOWN, \
|
from seahub.utils.file_types import (IMAGE, PDF, IMAGE, DOCUMENT, MARKDOWN, \
|
||||||
TEXT, SF)
|
TEXT, SF)
|
||||||
from seahub.settings import FILE_ENCODING_LIST, FILE_PREVIEW_MAX_SIZE, \
|
from seahub.settings import FILE_ENCODING_LIST, FILE_PREVIEW_MAX_SIZE, \
|
||||||
@@ -570,7 +569,7 @@ def file_edit_submit(request, repo_id):
|
|||||||
content = content.encode(encoding)
|
content = content.encode(encoding)
|
||||||
|
|
||||||
# first dump the file content to a tmp file, then update the file
|
# first dump the file content to a tmp file, then update the file
|
||||||
fd, tmpfile = tempfile.mkstemp()
|
fd, tmpfile = mkstemp()
|
||||||
def remove_tmp_file():
|
def remove_tmp_file():
|
||||||
try:
|
try:
|
||||||
os.remove(tmpfile)
|
os.remove(tmpfile)
|
||||||
|
Reference in New Issue
Block a user