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 # These are fake fetchers that are used for testing and the preview server. | 5 # These are fake fetchers that are used for testing and the preview server. |
6 # They return canned responses for URLs. appengine_wrappers.py uses the fake | 6 # They return canned responses for URLs. appengine_wrappers.py uses the fake |
7 # fetchers if the App Engine imports fail. | 7 # fetchers if the App Engine imports fail. |
8 | 8 |
9 import base64 | 9 import base64 |
10 import json | 10 import json |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 return None | 73 return None |
74 try: | 74 try: |
75 return ReadFile(path) | 75 return ReadFile(path) |
76 except IOError: | 76 except IOError: |
77 return None | 77 return None |
78 | 78 |
79 | 79 |
80 _GITILES_BASE_RE = re.escape(url_constants.GITILES_BASE) | 80 _GITILES_BASE_RE = re.escape(url_constants.GITILES_BASE) |
81 _GITILES_BRANCH_BASE_RE = re.escape(url_constants.GITILES_BRANCH_BASE) | 81 _GITILES_BRANCH_BASE_RE = re.escape(url_constants.GITILES_BRANCH_BASE) |
82 _GITILES_URL_TO_PATH_PATTERN = re.compile( | 82 _GITILES_URL_TO_PATH_PATTERN = re.compile( |
83 r'(' + _GITILES_BASE_RE + r'|' + _GITILES_BRANCH_BASE_RE + r').+?/(.*)') | 83 r'(' + _GITILES_BRANCH_BASE_RE + r'|' + _GITILES_BASE_RE + r').+?/(.*)') |
84 def _ExtractPathFromGitilesUrl(url): | 84 def _ExtractPathFromGitilesUrl(url): |
85 return _GITILES_URL_TO_PATH_PATTERN.match(url).group(2) | 85 return _GITILES_URL_TO_PATH_PATTERN.match(url).group(2) |
86 | 86 |
87 | 87 |
88 class _FakeGitilesServer(_FakeFetcher): | 88 class _FakeGitilesServer(_FakeFetcher): |
89 def fetch(self, url): | 89 def fetch(self, url): |
| 90 if _GITILES_URL_TO_PATH_PATTERN.match(url) is None: |
| 91 return json.dumps({ |
| 92 'commit': '1' * 40, |
| 93 'parents': ['0' * 40] |
| 94 }) |
90 path = _ExtractPathFromGitilesUrl(url) | 95 path = _ExtractPathFromGitilesUrl(url) |
91 chromium_path = ChromiumPath(path) | 96 chromium_path = ChromiumPath(path) |
92 if self._IsDir(chromium_path): | 97 if self._IsDir(chromium_path): |
93 jsn = {} | 98 jsn = {} |
94 dir_stat = self._Stat(chromium_path) | 99 dir_stat = self._Stat(chromium_path) |
95 jsn['id'] = dir_stat | 100 jsn['id'] = dir_stat |
96 jsn['entries'] = [] | 101 jsn['entries'] = [] |
97 for f in self._ListDir(chromium_path): | 102 for f in self._ListDir(chromium_path): |
98 if f.startswith('.'): | 103 if f.startswith('.'): |
99 continue | 104 continue |
| 105 f_path = os.path.join(chromium_path, f) |
100 jsn['entries'].append({ | 106 jsn['entries'].append({ |
101 'id': self._Stat(os.path.join(chromium_path, f)), | 107 'id': self._Stat(f_path), |
102 'name': f | 108 'name': f, |
| 109 'type': 'tree' if self._IsDir(f_path) else 'blob' |
103 }) | 110 }) |
104 return json.dumps(jsn) | 111 return json.dumps(jsn) |
105 try: | 112 try: |
106 return base64.b64encode(ReadFile(path)) | 113 return base64.b64encode(ReadFile(path)) |
107 except IOError: | 114 except IOError: |
108 return None | 115 return None |
109 | 116 |
110 | 117 |
111 class _FakeViewvcServer(_FakeFetcher): | 118 class _FakeViewvcServer(_FakeFetcher): |
112 def fetch(self, url): | 119 def fetch(self, url): |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 url_constants.OMAHA_PROXY_URL: _FakeOmahaProxy(), | 182 url_constants.OMAHA_PROXY_URL: _FakeOmahaProxy(), |
176 '%s/.*' % url_constants.SVN_URL: _FakeSubversionServer(), | 183 '%s/.*' % url_constants.SVN_URL: _FakeSubversionServer(), |
177 '%s/.*' % url_constants.VIEWVC_URL: _FakeViewvcServer(), | 184 '%s/.*' % url_constants.VIEWVC_URL: _FakeViewvcServer(), |
178 '%s/.*/commits/.*' % url_constants.GITHUB_REPOS: _FakeGithubStat(), | 185 '%s/.*/commits/.*' % url_constants.GITHUB_REPOS: _FakeGithubStat(), |
179 '%s/.*/zipball' % url_constants.GITHUB_REPOS: _FakeGithubZip(), | 186 '%s/.*/zipball' % url_constants.GITHUB_REPOS: _FakeGithubZip(), |
180 '%s/api/.*' % url_constants.CODEREVIEW_SERVER: _FakeRietveldAPI(), | 187 '%s/api/.*' % url_constants.CODEREVIEW_SERVER: _FakeRietveldAPI(), |
181 '%s/tarball/.*' % url_constants.CODEREVIEW_SERVER: _FakeRietveldTarball(), | 188 '%s/tarball/.*' % url_constants.CODEREVIEW_SERVER: _FakeRietveldTarball(), |
182 '%s/.*' % _GITILES_BASE_RE: _FakeGitilesServer(), | 189 '%s/.*' % _GITILES_BASE_RE: _FakeGitilesServer(), |
183 '%s/.*' % _GITILES_BRANCH_BASE_RE: _FakeGitilesServer() | 190 '%s/.*' % _GITILES_BRANCH_BASE_RE: _FakeGitilesServer() |
184 }) | 191 }) |
OLD | NEW |