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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import posixpath
6
7
8 # TODO(kalman): Write a Path class and use that everywhere rather than a
9 # utility class.
10
11
12 def IsDirectory(path):
13 '''Returns whether |path| should be considered a directory.
14 '''
15 # This assertion is sprinkled throughout the code base.
16 assert not path.startswith('/'), path
17 return path == '' or path.endswith('/')
18
19
20 def SplitParent(path):
21 '''Returns the parent directory and base name of |path| in a tuple.
22 Any trailing slash of |path| is preserved, such that the parent of
23 '/hello/world/' is '/hello' and the base is 'world/'.
24 '''
25 parent, base = posixpath.split(path.rstrip('/'))
26 if path.endswith('/'):
27 base += '/'
28 return parent, base
29
30
31 def ToDirectory(path):
32 '''Returns a string representing |path| as a directory, that is,
33 IsDirectory(result) is True (and does not fail assertions). If |path| is
34 already a directory then this is a no-op.
35 '''
36 return path if IsDirectory(path) else (path + '/')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698