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 if filename.startswith('/'): |
58 if filename.startswith(i): | 58 raise UnsupportedPatchFormat( |
59 raise UnsupportedPatchFormat( | 59 filename, 'Filename can\'t start with \'/\'.') |
60 filename, 'Filename can\'t start with \'%s\'.' % i) | 60 if filename == 'CON': |
| 61 raise UnsupportedPatchFormat( |
| 62 filename, 'Filename can\'t be \'CON\'.') |
| 63 if re.match('COM\d', filename): |
| 64 raise UnsupportedPatchFormat( |
| 65 filename, 'Filename can\'t be \'%s\'.' % filename) |
61 return filename | 66 return filename |
62 | 67 |
63 def set_relpath(self, relpath): | 68 def set_relpath(self, relpath): |
64 if not relpath: | 69 if not relpath: |
65 return | 70 return |
66 relpath = relpath.replace('\\', '/') | 71 relpath = relpath.replace('\\', '/') |
67 if relpath[0] == '/': | 72 if relpath[0] == '/': |
68 self._fail('Relative path starts with %s' % relpath[0]) | 73 self._fail('Relative path starts with %s' % relpath[0]) |
69 self.filename = self._process_filename( | 74 self.filename = self._process_filename( |
70 posixpath.join(relpath, self.filename)) | 75 posixpath.join(relpath, self.filename)) |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 def __iter__(self): | 539 def __iter__(self): |
535 for patch in self.patches: | 540 for patch in self.patches: |
536 yield patch | 541 yield patch |
537 | 542 |
538 def __getitem__(self, key): | 543 def __getitem__(self, key): |
539 return self.patches[key] | 544 return self.patches[key] |
540 | 545 |
541 @property | 546 @property |
542 def filenames(self): | 547 def filenames(self): |
543 return [p.filename for p in self.patches] | 548 return [p.filename for p in self.patches] |
OLD | NEW |