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

Unified Diff: patch.py

Issue 7809001: Make filename processing a static method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: patch.py
diff --git a/patch.py b/patch.py
index 77bb15991065f4fefd363335e26e59cad19dffa6..8bdeddb1e67e56c89dffed7f0aa0a7e106d546d4 100644
--- a/patch.py
+++ b/patch.py
@@ -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)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698