Make filename processing a static method.

This is in preparation to support file rename, as a source_filename needs to be
added and processed.

R=dpranke@chromium.org
BUG=
TEST=

Review URL: http://codereview.chromium.org/7809001

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@99185 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
maruel@chromium.org 14 years ago
parent 031524151a
commit be113f1365

@ -32,18 +32,21 @@ class FilePatchBase(object):
is_new = False
def __init__(self, filename):
self.filename = None
self._set_filename(filename)
self.filename = self._process_filename(filename)
def _set_filename(self, filename):
self.filename = filename.replace('\\', '/')
@staticmethod
def _process_filename(filename):
filename = filename.replace('\\', '/')
# Blacklist a few characters for simplicity.
for i in ('%', '$', '..', '\'', '"'):
if i in self.filename:
self._fail('Can\'t use \'%s\' in filename.' % i)
if i in filename:
raise UnsupportedPatchFormat(
filename, 'Can\'t use \'%s\' in filename.' % i)
for i in ('/', 'CON', 'COM'):
if self.filename.startswith(i):
self._fail('Filename can\'t start with \'%s\'.' % i)
if filename.startswith(i):
raise UnsupportedPatchFormat(
filename, 'Filename can\'t start with \'%s\'.' % i)
return filename
def get(self): # pragma: no coverage
raise NotImplementedError('Nothing to grab')
@ -54,9 +57,11 @@ class FilePatchBase(object):
relpath = relpath.replace('\\', '/')
if relpath[0] == '/':
self._fail('Relative path starts with %s' % relpath[0])
self._set_filename(posixpath.join(relpath, self.filename))
self.filename = self._process_filename(
posixpath.join(relpath, self.filename))
def _fail(self, msg):
"""Shortcut function to raise UnsupportedPatchFormat."""
raise UnsupportedPatchFormat(self.filename, msg)

Loading…
Cancel
Save