Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: chrome/common/extensions/docs/server2/fake_fetchers.py

Issue 498503002: Docserver: Fixes for GitilesFileSystem (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/gitiles_file_system.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 except OSError as e: 72 except OSError as e:
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 # NOTE: _GITILES_BRANCH_BASE_RE must be first, because _GITILES_BASE_RE is
83 r'(' + _GITILES_BASE_RE + r'|' + _GITILES_BRANCH_BASE_RE + r').+?/(.*)') 83 # a more general pattern.
84 _GITILES_URL_RE = r'(%s|%s)/' % (_GITILES_BRANCH_BASE_RE, _GITILES_BASE_RE)
85 _GITILES_URL_TO_COMMIT_PATTERN = re.compile(
86 r'%s[^/]+\?format=JSON' % _GITILES_URL_RE)
87 _GITILES_URL_TO_PATH_PATTERN = re.compile(r'%s.+?/(.*)' % _GITILES_URL_RE)
84 def _ExtractPathFromGitilesUrl(url): 88 def _ExtractPathFromGitilesUrl(url):
85 return _GITILES_URL_TO_PATH_PATTERN.match(url).group(2) 89 return _GITILES_URL_TO_PATH_PATTERN.match(url).group(2)
86 90
87 91
88 class _FakeGitilesServer(_FakeFetcher): 92 class _FakeGitilesServer(_FakeFetcher):
89 def fetch(self, url): 93 def fetch(self, url):
94 if _GITILES_URL_TO_COMMIT_PATTERN.match(url) is not None:
95 return json.dumps({'commit': '1' * 40})
90 path = _ExtractPathFromGitilesUrl(url) 96 path = _ExtractPathFromGitilesUrl(url)
91 chromium_path = ChromiumPath(path) 97 chromium_path = ChromiumPath(path)
92 if self._IsDir(chromium_path): 98 if self._IsDir(chromium_path):
93 jsn = {} 99 jsn = {}
94 dir_stat = self._Stat(chromium_path) 100 dir_stat = self._Stat(chromium_path)
95 jsn['id'] = dir_stat 101 jsn['id'] = dir_stat
96 jsn['entries'] = [] 102 jsn['entries'] = []
97 for f in self._ListDir(chromium_path): 103 for f in self._ListDir(chromium_path):
98 if f.startswith('.'): 104 if f.startswith('.'):
99 continue 105 continue
106 f_path = os.path.join(chromium_path, f)
100 jsn['entries'].append({ 107 jsn['entries'].append({
101 'id': self._Stat(os.path.join(chromium_path, f)), 108 'id': self._Stat(f_path),
102 'name': f 109 'name': f,
110 'type': 'tree' if self._IsDir(f_path) else 'blob'
103 }) 111 })
104 return json.dumps(jsn) 112 return json.dumps(jsn)
105 try: 113 try:
106 return base64.b64encode(ReadFile(path)) 114 return base64.b64encode(ReadFile(path))
107 except IOError: 115 except IOError:
108 return None 116 return None
109 117
110 118
111 class _FakeViewvcServer(_FakeFetcher): 119 class _FakeViewvcServer(_FakeFetcher):
112 def fetch(self, url): 120 def fetch(self, url):
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 url_constants.OMAHA_PROXY_URL: _FakeOmahaProxy(), 183 url_constants.OMAHA_PROXY_URL: _FakeOmahaProxy(),
176 '%s/.*' % url_constants.SVN_URL: _FakeSubversionServer(), 184 '%s/.*' % url_constants.SVN_URL: _FakeSubversionServer(),
177 '%s/.*' % url_constants.VIEWVC_URL: _FakeViewvcServer(), 185 '%s/.*' % url_constants.VIEWVC_URL: _FakeViewvcServer(),
178 '%s/.*/commits/.*' % url_constants.GITHUB_REPOS: _FakeGithubStat(), 186 '%s/.*/commits/.*' % url_constants.GITHUB_REPOS: _FakeGithubStat(),
179 '%s/.*/zipball' % url_constants.GITHUB_REPOS: _FakeGithubZip(), 187 '%s/.*/zipball' % url_constants.GITHUB_REPOS: _FakeGithubZip(),
180 '%s/api/.*' % url_constants.CODEREVIEW_SERVER: _FakeRietveldAPI(), 188 '%s/api/.*' % url_constants.CODEREVIEW_SERVER: _FakeRietveldAPI(),
181 '%s/tarball/.*' % url_constants.CODEREVIEW_SERVER: _FakeRietveldTarball(), 189 '%s/tarball/.*' % url_constants.CODEREVIEW_SERVER: _FakeRietveldTarball(),
182 '%s/.*' % _GITILES_BASE_RE: _FakeGitilesServer(), 190 '%s/.*' % _GITILES_BASE_RE: _FakeGitilesServer(),
183 '%s/.*' % _GITILES_BRANCH_BASE_RE: _FakeGitilesServer() 191 '%s/.*' % _GITILES_BRANCH_BASE_RE: _FakeGitilesServer()
184 }) 192 })
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/gitiles_file_system.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698