Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 import re | 6 import re |
| 7 import urlparse | 7 import urlparse |
| 8 | 8 |
| 9 | 9 |
| 10 class Page(object): | 10 class Page(object): |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 if not self._scheme: | 26 if not self._scheme: |
| 27 raise ValueError('Must prepend the URL with scheme (e.g. file://)') | 27 raise ValueError('Must prepend the URL with scheme (e.g. file://)') |
| 28 | 28 |
| 29 def __getattr__(self, name): | 29 def __getattr__(self, name): |
| 30 # Inherit attributes from the page set. | 30 # Inherit attributes from the page set. |
| 31 if self.page_set and hasattr(self.page_set, name): | 31 if self.page_set and hasattr(self.page_set, name): |
| 32 return getattr(self.page_set, name) | 32 return getattr(self.page_set, name) |
| 33 raise AttributeError( | 33 raise AttributeError( |
| 34 '%r object has no attribute %r' % (self.__class__, name)) | 34 '%r object has no attribute %r' % (self.__class__, name)) |
| 35 | 35 |
| 36 def __lt__(self, other): | |
| 37 return self.url < other.url | |
|
dtu
2013/10/31 23:24:30
Compare on page.name, then page.url.
| |
| 38 | |
| 39 def __cmp__(self, other): | |
| 40 return cmp(self.url, other.url) | |
| 41 | |
| 36 def __str__(self): | 42 def __str__(self): |
| 37 return self.url | 43 return self.url |
| 38 | 44 |
| 39 @property | 45 @property |
| 40 def _scheme(self): | 46 def _scheme(self): |
| 41 return urlparse.urlparse(self.url).scheme | 47 return urlparse.urlparse(self.url).scheme |
| 42 | 48 |
| 43 @property | 49 @property |
| 44 def is_file(self): | 50 def is_file(self): |
| 45 """Returns True iff this URL points to a file.""" | 51 """Returns True iff this URL points to a file.""" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 return self.name | 97 return self.name |
| 92 if not self.is_file: | 98 if not self.is_file: |
| 93 return self.url | 99 return self.url |
| 94 all_urls = [p.url.rstrip('/') for p in self.page_set if p.is_file] | 100 all_urls = [p.url.rstrip('/') for p in self.page_set if p.is_file] |
| 95 common_prefix = os.path.dirname(os.path.commonprefix(all_urls)) | 101 common_prefix = os.path.dirname(os.path.commonprefix(all_urls)) |
| 96 return self.url[len(common_prefix):].strip('/') | 102 return self.url[len(common_prefix):].strip('/') |
| 97 | 103 |
| 98 @property | 104 @property |
| 99 def archive_path(self): | 105 def archive_path(self): |
| 100 return self.page_set.WprFilePathForPage(self) | 106 return self.page_set.WprFilePathForPage(self) |
| OLD | NEW |