OLD | NEW |
---|---|
1 # coding=utf8 | 1 # coding=utf8 |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 """Utility functions to handle patches.""" | 5 """Utility functions to handle patches.""" |
6 | 6 |
7 import posixpath | 7 import posixpath |
8 import os | 8 import os |
9 import re | 9 import re |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 return self.source_filename.encode('utf-8') | 47 return self.source_filename.encode('utf-8') |
48 | 48 |
49 @staticmethod | 49 @staticmethod |
50 def _process_filename(filename): | 50 def _process_filename(filename): |
51 filename = filename.replace('\\', '/') | 51 filename = filename.replace('\\', '/') |
52 # Blacklist a few characters for simplicity. | 52 # Blacklist a few characters for simplicity. |
53 for i in ('$', '..', '\'', '"', '<', '>', ':', '|', '?', '*'): | 53 for i in ('$', '..', '\'', '"', '<', '>', ':', '|', '?', '*'): |
54 if i in filename: | 54 if i in filename: |
55 raise UnsupportedPatchFormat( | 55 raise UnsupportedPatchFormat( |
56 filename, 'Can\'t use \'%s\' in filename.' % i) | 56 filename, 'Can\'t use \'%s\' in filename.' % i) |
57 for i in ('/', 'CON', 'COM'): | 57 for i in ('/'): |
M-A Ruel
2015/05/27 18:09:17
Remove the for loop here
sullivan
2015/05/27 18:20:11
Done.
| |
58 if filename.startswith(i): | 58 if filename.startswith(i): |
59 raise UnsupportedPatchFormat( | 59 raise UnsupportedPatchFormat( |
60 filename, 'Filename can\'t start with \'%s\'.' % i) | 60 filename, 'Filename can\'t start with \'%s\'.' % i) |
61 for i in ('CON', 'COM'): | |
M-A Ruel
2015/05/27 18:09:17
In the COM case, it would be the equivalent of re.
sullivan
2015/05/27 18:20:11
Done.
| |
62 if filename == i: | |
63 raise UnsupportedPatchFormat( | |
64 filename, 'Filename can\'t be \'%s\'.' % i) | |
61 return filename | 65 return filename |
62 | 66 |
63 def set_relpath(self, relpath): | 67 def set_relpath(self, relpath): |
64 if not relpath: | 68 if not relpath: |
65 return | 69 return |
66 relpath = relpath.replace('\\', '/') | 70 relpath = relpath.replace('\\', '/') |
67 if relpath[0] == '/': | 71 if relpath[0] == '/': |
68 self._fail('Relative path starts with %s' % relpath[0]) | 72 self._fail('Relative path starts with %s' % relpath[0]) |
69 self.filename = self._process_filename( | 73 self.filename = self._process_filename( |
70 posixpath.join(relpath, self.filename)) | 74 posixpath.join(relpath, self.filename)) |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
534 def __iter__(self): | 538 def __iter__(self): |
535 for patch in self.patches: | 539 for patch in self.patches: |
536 yield patch | 540 yield patch |
537 | 541 |
538 def __getitem__(self, key): | 542 def __getitem__(self, key): |
539 return self.patches[key] | 543 return self.patches[key] |
540 | 544 |
541 @property | 545 @property |
542 def filenames(self): | 546 def filenames(self): |
543 return [p.filename for p in self.patches] | 547 return [p.filename for p in self.patches] |
OLD | NEW |