Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5279)

Unified Diff: chrome/common/extensions/docs/server2/path_util.py

Issue 149513014: Docserver: Add FileSystem.Exists method and start sanity checking path format (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/path_util.py
diff --git a/chrome/common/extensions/docs/server2/path_util.py b/chrome/common/extensions/docs/server2/path_util.py
new file mode 100644
index 0000000000000000000000000000000000000000..78ed8333fe2988aeb8a7271f54c745f45ad0f5a0
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/path_util.py
@@ -0,0 +1,36 @@
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import posixpath
+
+
+# TODO(kalman): Write a Path class and use that everywhere rather than a
+# utility class.
+
+
+def IsDirectory(path):
+ '''Returns whether |path| should be considered a directory.
+ '''
+ # This assertion is sprinkled throughout the code base.
+ assert not path.startswith('/'), path
+ return path == '' or path.endswith('/')
+
+
+def SplitParent(path):
+ '''Returns the parent directory and base name of |path| in a tuple.
+ Any trailing slash of |path| is preserved, such that the parent of
+ '/hello/world/' is '/hello' and the base is 'world/'.
+ '''
+ parent, base = posixpath.split(path.rstrip('/'))
+ if path.endswith('/'):
+ base += '/'
+ return parent, base
+
+
+def ToDirectory(path):
+ '''Returns a string representing |path| as a directory, that is,
+ IsDirectory(result) is True (and does not fail assertions). If |path| is
+ already a directory then this is a no-op.
+ '''
+ return path if IsDirectory(path) else (path + '/')
« no previous file with comments | « chrome/common/extensions/docs/server2/file_system_test.py ('k') | chrome/common/extensions/docs/server2/path_util_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698