Commit c7952b53 authored by Aurel's avatar Aurel

encode object title and path with url encoding


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4450 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c5ff2224
...@@ -65,6 +65,7 @@ from gzip import GzipFile ...@@ -65,6 +65,7 @@ from gzip import GzipFile
from xml.dom.minidom import parse from xml.dom.minidom import parse
from Products.CMFCore.Expression import Expression from Products.CMFCore.Expression import Expression
import tarfile import tarfile
from urllib import pathname2url, url2pathname
catalog_method_list = ('_is_catalog_method_archive', '_is_catalog_list_method_archive', catalog_method_list = ('_is_catalog_method_archive', '_is_catalog_list_method_archive',
...@@ -130,6 +131,7 @@ class BusinessTemplateFolder(BusinessTemplateArchive): ...@@ -130,6 +131,7 @@ class BusinessTemplateFolder(BusinessTemplateArchive):
os.makedirs(self.path) os.makedirs(self.path)
def addFolder(self, name=''): def addFolder(self, name=''):
name = pathname2url(name)
if name !='': if name !='':
path = os.path.join(self.path, name) path = os.path.join(self.path, name)
if not os.path.exists(path): if not os.path.exists(path):
...@@ -137,9 +139,12 @@ class BusinessTemplateFolder(BusinessTemplateArchive): ...@@ -137,9 +139,12 @@ class BusinessTemplateFolder(BusinessTemplateArchive):
return path return path
def addObject(self, object, name, path=None, ext='.xml'): def addObject(self, object, name, path=None, ext='.xml'):
name = pathname2url(name)
if path is None: if path is None:
object_path = os.path.join(self.path, name) object_path = os.path.join(self.path, name)
else: else:
if '%' not in path:
path = pathname2url(path)
object_path = os.path.join(path, name) object_path = os.path.join(path, name)
f = open(object_path+ext, 'wt') f = open(object_path+ext, 'wt')
f.write(str(object)) f.write(str(object))
...@@ -162,6 +167,8 @@ class BusinessTemplateFolder(BusinessTemplateArchive): ...@@ -162,6 +167,8 @@ class BusinessTemplateFolder(BusinessTemplateArchive):
# get object id # get object id
folders = file_path.split(os.sep) folders = file_path.split(os.sep)
file_name = string.join(folders[self.root_path_len:], os.sep) file_name = string.join(folders[self.root_path_len:], os.sep)
if '%' in file_name:
file_name = url2pathname(file_name)
klass._importFile(file_name, file) klass._importFile(file_name, file)
# close file # close file
file.close() file.close()
...@@ -185,13 +192,17 @@ class BusinessTemplateTarball(BusinessTemplateArchive): ...@@ -185,13 +192,17 @@ class BusinessTemplateTarball(BusinessTemplateArchive):
self.tar = tarfile.open('', 'w:gz', self.fobj) self.tar = tarfile.open('', 'w:gz', self.fobj)
def addFolder(self, name=''): def addFolder(self, name=''):
name = pathname2url(name)
if not os.path.exists(name): if not os.path.exists(name):
os.makedirs(name) os.makedirs(name)
def addObject(self, object, name, path=None, ext='.xml'): def addObject(self, object, name, path=None, ext='.xml'):
name = pathname2url(name)
if path is None: if path is None:
object_path = os.path.join(self.path, name) object_path = os.path.join(self.path, name)
else: else:
if '%' not in path:
path = pathname2url(path)
object_path = os.path.join(path, name) object_path = os.path.join(path, name)
f = open(object_path+ext, 'wt') f = open(object_path+ext, 'wt')
f.write(str(object)) f.write(str(object))
...@@ -220,7 +231,10 @@ class BusinessTemplateTarball(BusinessTemplateArchive): ...@@ -220,7 +231,10 @@ class BusinessTemplateTarball(BusinessTemplateArchive):
if info.isreg(): if info.isreg():
file = tar.extractfile(info) file = tar.extractfile(info)
folders = string.split(info.name, os.sep) folders = string.split(info.name, os.sep)
klass._importFile((os.sep).join(folders[2:]), file) file_name = (os.sep).join(folders[2:])
if '%' in file_name:
file_name = url2pathname(file_name)
klass._importFile(file_name, file)
file.close() file.close()
tar.close() tar.close()
io.close() io.close()
......
...@@ -44,6 +44,7 @@ from OFS.Traversable import NotFound ...@@ -44,6 +44,7 @@ from OFS.Traversable import NotFound
from difflib import unified_diff from difflib import unified_diff
from cStringIO import StringIO from cStringIO import StringIO
from zLOG import LOG from zLOG import LOG
from urllib import pathname2url
class LocalConfiguration(Implicit): class LocalConfiguration(Implicit):
""" """
...@@ -139,6 +140,7 @@ class TemplateTool (BaseTool): ...@@ -139,6 +140,7 @@ class TemplateTool (BaseTool):
Export BT in tarball format Export BT in tarball format
""" """
path = business_template.getTitle() path = business_template.getTitle()
path = pathname2url(path)
tmpfile_path = os.tmpnam() tmpfile_path = os.tmpnam()
tmpdir_path = os.path.dirname(tmpfile_path) tmpdir_path = os.path.dirname(tmpfile_path)
current_directory = os.getcwd() current_directory = os.getcwd()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment