| 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 from file_system import FileSystem, FileNotFoundError, StatInfo, ToUnicode | 5 from file_system import FileSystem, FileNotFoundError, StatInfo, ToUnicode |
| 6 from future import Future | 6 from future import Future |
| 7 import logging | 7 import logging |
| 8 import re | 8 import re |
| 9 import xml.dom.minidom as xml | 9 import xml.dom.minidom as xml |
| 10 from xml.parsers.expat import ExpatError | 10 from xml.parsers.expat import ExpatError |
| 11 | 11 |
| 12 # Sometimes we get bad data and end up caching it. Increment this so that | |
| 13 # CachingFileSystem (if one is attached) knows to re-fetch. | |
| 14 # | |
| 15 # WARNING: This is a VERY EXPENSIVE number to bump. ONLY do so if the data | |
| 16 # returned by these operations changes, DESPITE WHAT THE PRESUBMIT WARNING | |
| 17 # MIGHT TELL YOU! | |
| 18 _VERSION = 1 | |
| 19 | |
| 20 class _AsyncFetchFuture(object): | 12 class _AsyncFetchFuture(object): |
| 21 def __init__(self, paths, fetcher, binary): | 13 def __init__(self, paths, fetcher, binary): |
| 22 # A list of tuples of the form (path, Future). | 14 # A list of tuples of the form (path, Future). |
| 23 self._fetches = [(path, fetcher.FetchAsync(path)) for path in paths] | 15 self._fetches = [(path, fetcher.FetchAsync(path)) for path in paths] |
| 24 self._value = {} | 16 self._value = {} |
| 25 self._error = None | 17 self._error = None |
| 26 self._binary = binary | 18 self._binary = binary |
| 27 | 19 |
| 28 def _ListDir(self, directory): | 20 def _ListDir(self, directory): |
| 29 dom = xml.parseString(directory) | 21 dom = xml.parseString(directory) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 if result.status_code == 404: | 119 if result.status_code == 404: |
| 128 raise FileNotFoundError( | 120 raise FileNotFoundError( |
| 129 'Got 404 when fetching %s from %s for Stat' % (path, directory)) | 121 'Got 404 when fetching %s from %s for Stat' % (path, directory)) |
| 130 stat_info = self._CreateStatInfo(result.content) | 122 stat_info = self._CreateStatInfo(result.content) |
| 131 if not path.endswith('/'): | 123 if not path.endswith('/'): |
| 132 filename = path.rsplit('/', 1)[-1] | 124 filename = path.rsplit('/', 1)[-1] |
| 133 if filename not in stat_info.child_versions: | 125 if filename not in stat_info.child_versions: |
| 134 raise FileNotFoundError('%s was not in child versions' % filename) | 126 raise FileNotFoundError('%s was not in child versions' % filename) |
| 135 stat_info.version = stat_info.child_versions[filename] | 127 stat_info.version = stat_info.child_versions[filename] |
| 136 return stat_info | 128 return stat_info |
| 137 | |
| 138 @classmethod | |
| 139 def GetVersion(cls): | |
| 140 return _VERSION | |
| OLD | NEW |