Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: cms/sources.py

Issue 29347181: Issue 4217 - Fix Prefix Regression Due To Mercurial Version Behavior Change (Closed)
Left Patch Set: remove legacy code replacement Created July 1, 2016, 11:28 a.m.
Right Patch Set: adds format operator to string forat Created July 1, 2016, 11:59 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-2016 Eyeo GmbH 2 # Copyright (C) 2006-2016 Eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 220
221 def __exit__(self, type, value, traceback): 221 def __exit__(self, type, value, traceback):
222 self.close() 222 self.close()
223 return False 223 return False
224 224
225 def close(self): 225 def close(self):
226 self._archive.close() 226 self._archive.close()
227 227
228 def has_file(self, filename): 228 def has_file(self, filename):
229 try: 229 try:
230 self._archive.getinfo('root/%s' % filename) 230 self._archive.getinfo('root/' + filename)
Sebastian Noack 2016/07/01 11:41:11 In the case here, it would be preferable to simply
231 except KeyError: 231 except KeyError:
232 return False 232 return False
233 return True 233 return True
234 234
235 def read_file(self, filename, binary=False): 235 def read_file(self, filename, binary=False):
236 data = self._archive.read('root/%s' % filename) 236 data = self._archive.read('root/' + filename)
Sebastian Noack 2016/07/01 11:41:11 Same here.
237 if not binary: 237 if not binary:
238 data = data.decode('utf-8') 238 data = data.decode('utf-8')
239 return (data, '%s!%s' % (self._name, filename)) 239 return (data, '%s!%s' % (self._name, filename))
240 240
241 def list_files(self, subdir): 241 def list_files(self, subdir):
242 prefix = 'root/%s/' % subdir 242 prefix = 'root/{}/'.format(subdir)
Sebastian Noack 2016/07/01 11:41:11 Please use format() rather than % in new code.
Sebastian Noack 2016/07/01 11:46:46 It's not unrelated here, bacuase you are changing/
Sebastian Noack 2016/07/01 11:58:57 What is about this comment?
243 for filename in self._archive.namelist(): 243 for filename in self._archive.namelist():
244 if filename.startswith(prefix): 244 if filename.startswith(prefix):
245 yield filename[len(prefix):] 245 yield filename[len(prefix):]
246 246
247 if os.name == 'posix': 247 if os.name == 'posix':
248 def get_cache_dir(self): 248 def get_cache_dir(self):
249 return '/var/cache/' + self._name 249 return '/var/cache/' + self._name
250 250
251 251
252 class FileSource(Source): 252 class FileSource(Source):
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 path = os.path.join(dir, filename) 292 path = os.path.join(dir, filename)
293 if os.path.isfile(path): 293 if os.path.isfile(path):
294 result.append(relpath + filename) 294 result.append(relpath + filename)
295 elif os.path.isdir(path): 295 elif os.path.isdir(path):
296 do_list(path, relpath + filename + '/') 296 do_list(path, relpath + filename + '/')
297 do_list(self.get_path(subdir), '') 297 do_list(self.get_path(subdir), '')
298 return result 298 return result
299 299
300 def get_cache_dir(self): 300 def get_cache_dir(self):
301 return os.path.join(self._dir, 'cache') 301 return os.path.join(self._dir, 'cache')
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld