summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcduvall@chromium.org <cduvall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-30 18:26:12 +0000
committercduvall@chromium.org <cduvall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-30 18:26:12 +0000
commit64ff751b66361db477a21925d04f8fc1edc88bda (patch)
tree210a1928d927ae3d0d51de0a7daa1314a1b05d63
parent274bb5fbb04a5346897dc15caae48decd2af6397 (diff)
downloadchromium_src-64ff751b66361db477a21925d04f8fc1edc88bda.zip
chromium_src-64ff751b66361db477a21925d04f8fc1edc88bda.tar.gz
chromium_src-64ff751b66361db477a21925d04f8fc1edc88bda.tar.bz2
Extensions Docs Server: Fix zipper
The ExampleZipper was getting caught on unicode characters. I added a parameter to Read in FileSystem that will return the files without converting to unicode. BUG=131095 Review URL: https://chromiumcodereview.appspot.com/10826037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148980 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/common/extensions/docs/server2/example_zipper.py5
-rw-r--r--chrome/common/extensions/docs/server2/file_system.py6
-rw-r--r--chrome/common/extensions/docs/server2/local_file_system.py11
-rw-r--r--chrome/common/extensions/docs/server2/memcache_file_system.py4
-rw-r--r--chrome/common/extensions/docs/server2/subversion_file_system.py11
5 files changed, 24 insertions, 13 deletions
diff --git a/chrome/common/extensions/docs/server2/example_zipper.py b/chrome/common/extensions/docs/server2/example_zipper.py
index a21867c..26dbe15 100644
--- a/chrome/common/extensions/docs/server2/example_zipper.py
+++ b/chrome/common/extensions/docs/server2/example_zipper.py
@@ -24,8 +24,9 @@ class ExampleZipper(object):
zip_bytes = BytesIO()
zip_file = ZipFile(zip_bytes, mode='w')
try:
- for filename, contents in self._file_system.Read(files).Get().iteritems():
- zip_file.writestr(filename[len(prefix):].strip('/'), contents)
+ for name, file_contents in (
+ self._file_system.Read(files, binary=True).Get().iteritems()):
+ zip_file.writestr(name[len(prefix):].strip('/'), file_contents)
finally:
zip_file.close()
return zip_bytes.getvalue()
diff --git a/chrome/common/extensions/docs/server2/file_system.py b/chrome/common/extensions/docs/server2/file_system.py
index 617d43a..873cdbf 100644
--- a/chrome/common/extensions/docs/server2/file_system.py
+++ b/chrome/common/extensions/docs/server2/file_system.py
@@ -21,10 +21,14 @@ class FileSystem(object):
def __init__(self, version):
self.version = version
- def Read(self, paths):
+ def Read(self, paths, binary=False):
"""Reads each file in paths and returns a dictionary mapping the path to the
contents. If a path in paths ends with a '/', it is assumed to be a
directory, and a list of files in the directory is mapped to the path.
+
+ If binary=False, the contents of each file will be unicode parsed as utf-8,
+ and failing that as latin-1 (some extension docs use latin-1). If
+ binary=True then the contents will be a str.
"""
raise NotImplementedError()
diff --git a/chrome/common/extensions/docs/server2/local_file_system.py b/chrome/common/extensions/docs/server2/local_file_system.py
index 44efcc0..7360e2a 100644
--- a/chrome/common/extensions/docs/server2/local_file_system.py
+++ b/chrome/common/extensions/docs/server2/local_file_system.py
@@ -17,9 +17,12 @@ class LocalFileSystem(file_system.FileSystem):
def _ConvertToFilepath(self, path):
return path.replace('/', os.sep)
- def _ReadFile(self, filename):
+ def _ReadFile(self, filename, binary):
with open(os.path.join(self._base_path, filename), 'r') as f:
- return file_system._ProcessFileData(f.read(), filename)
+ contents = f.read()
+ if binary:
+ return contents
+ return file_system._ProcessFileData(contents, filename)
def _ListDir(self, dir_name):
all_files = []
@@ -33,13 +36,13 @@ class LocalFileSystem(file_system.FileSystem):
all_files.append(path)
return all_files
- def Read(self, paths):
+ def Read(self, paths, binary=False):
result = {}
for path in paths:
if path.endswith('/'):
result[path] = self._ListDir(self._ConvertToFilepath(path))
else:
- result[path] = self._ReadFile(self._ConvertToFilepath(path))
+ result[path] = self._ReadFile(self._ConvertToFilepath(path), binary)
return Future(value=result)
def Stat(self, path):
diff --git a/chrome/common/extensions/docs/server2/memcache_file_system.py b/chrome/common/extensions/docs/server2/memcache_file_system.py
index 10ba7ee..5ac4072 100644
--- a/chrome/common/extensions/docs/server2/memcache_file_system.py
+++ b/chrome/common/extensions/docs/server2/memcache_file_system.py
@@ -27,7 +27,7 @@ class MemcacheFileSystem(FileSystem):
stat_info = self.StatInfo(version)
return stat_info
- def Read(self, paths):
+ def Read(self, paths, binary=False):
"""Reads a list of files. If a file is in memcache and it is not out of
date, it is returned. Otherwise, the file is retrieved from the file system.
"""
@@ -45,7 +45,7 @@ class MemcacheFileSystem(FileSystem):
uncached.append(path)
continue
result[path] = data
- new_items = self._file_system.Read(uncached).Get()
+ new_items = self._file_system.Read(uncached, binary=binary).Get()
for item in new_items:
version = self.Stat(item).version
value = new_items[item]
diff --git a/chrome/common/extensions/docs/server2/subversion_file_system.py b/chrome/common/extensions/docs/server2/subversion_file_system.py
index 5b10f88..b5d2642 100644
--- a/chrome/common/extensions/docs/server2/subversion_file_system.py
+++ b/chrome/common/extensions/docs/server2/subversion_file_system.py
@@ -14,8 +14,8 @@ class SubversionFileSystem(file_system.FileSystem):
def __init__(self, fetcher):
self._fetcher = fetcher
- def Read(self, paths):
- return Future(delegate=_AsyncFetchFuture(paths, self._fetcher))
+ def Read(self, paths, binary=False):
+ return Future(delegate=_AsyncFetchFuture(paths, self._fetcher, binary))
def Stat(self, path):
directory = path.rsplit('/', 1)[0]
@@ -23,12 +23,13 @@ class SubversionFileSystem(file_system.FileSystem):
return self.StatInfo(int(re.search('([0-9]+)', dir_html).group(0)))
class _AsyncFetchFuture(object):
- def __init__(self, paths, fetcher):
+ def __init__(self, paths, fetcher, binary):
# A list of tuples of the form (path, Future).
self._fetches = []
self._value = {}
self._error = None
self._fetches = [(path, fetcher.FetchAsync(path)) for path in paths]
+ self._binary = binary
def _ListDir(self, directory):
dom = xml.parseString(directory)
@@ -44,8 +45,10 @@ class _AsyncFetchFuture(object):
self._value[path] = None
elif path.endswith('/'):
self._value[path] = self._ListDir(result.content)
- else:
+ elif not self._binary:
self._value[path] = file_system._ProcessFileData(result.content, path)
+ else:
+ self._value[path] = result.content
if self._error is not None:
raise self._error
return self._value