Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 37099:895f209b593b
util: use error.Abort instead of local alias
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 24 Mar 2018 14:08:50 +0900 |
parents | e24802ea8dbd |
children | a9ea2b1e5c4b |
comparison
equal
deleted
inserted
replaced
37098:e24802ea8dbd | 37099:895f209b593b |
---|---|
280 | 280 |
281 def __init__(self, digests, s=''): | 281 def __init__(self, digests, s=''): |
282 self._hashes = {} | 282 self._hashes = {} |
283 for k in digests: | 283 for k in digests: |
284 if k not in DIGESTS: | 284 if k not in DIGESTS: |
285 raise Abort(_('unknown digest type: %s') % k) | 285 raise error.Abort(_('unknown digest type: %s') % k) |
286 self._hashes[k] = DIGESTS[k]() | 286 self._hashes[k] = DIGESTS[k]() |
287 if s: | 287 if s: |
288 self.update(s) | 288 self.update(s) |
289 | 289 |
290 def update(self, data): | 290 def update(self, data): |
291 for h in self._hashes.values(): | 291 for h in self._hashes.values(): |
292 h.update(data) | 292 h.update(data) |
293 | 293 |
294 def __getitem__(self, key): | 294 def __getitem__(self, key): |
295 if key not in DIGESTS: | 295 if key not in DIGESTS: |
296 raise Abort(_('unknown digest type: %s') % k) | 296 raise error.Abort(_('unknown digest type: %s') % k) |
297 return nodemod.hex(self._hashes[key].digest()) | 297 return nodemod.hex(self._hashes[key].digest()) |
298 | 298 |
299 def __iter__(self): | 299 def __iter__(self): |
300 return iter(self._hashes) | 300 return iter(self._hashes) |
301 | 301 |
330 self._got += len(content) | 330 self._got += len(content) |
331 return content | 331 return content |
332 | 332 |
333 def validate(self): | 333 def validate(self): |
334 if self._size != self._got: | 334 if self._size != self._got: |
335 raise Abort(_('size mismatch: expected %d, got %d') % | 335 raise error.Abort(_('size mismatch: expected %d, got %d') % |
336 (self._size, self._got)) | 336 (self._size, self._got)) |
337 for k, v in self._digests.items(): | 337 for k, v in self._digests.items(): |
338 if v != self._digester[k]: | 338 if v != self._digester[k]: |
339 # i18n: first parameter is a digest name | 339 # i18n: first parameter is a digest name |
340 raise Abort(_('%s mismatch: expected %s, got %s') % | 340 raise error.Abort(_('%s mismatch: expected %s, got %s') % |
341 (k, v, self._digester[k])) | 341 (k, v, self._digester[k])) |
342 | 342 |
343 try: | 343 try: |
344 buffer = buffer | 344 buffer = buffer |
345 except NameError: | 345 except NameError: |
346 def buffer(sliceable, offset=0, length=None): | 346 def buffer(sliceable, offset=0, length=None): |
1526 cmd = cmd.replace('OUTFILE', outname) | 1526 cmd = cmd.replace('OUTFILE', outname) |
1527 code = os.system(cmd) | 1527 code = os.system(cmd) |
1528 if pycompat.sysplatform == 'OpenVMS' and code & 1: | 1528 if pycompat.sysplatform == 'OpenVMS' and code & 1: |
1529 code = 0 | 1529 code = 0 |
1530 if code: | 1530 if code: |
1531 raise Abort(_("command '%s' failed: %s") % | 1531 raise error.Abort(_("command '%s' failed: %s") % |
1532 (cmd, explainexit(code))) | 1532 (cmd, explainexit(code))) |
1533 return readfile(outname) | 1533 return readfile(outname) |
1534 finally: | 1534 finally: |
1535 try: | 1535 try: |
1536 if inname: | 1536 if inname: |
1537 os.unlink(inname) | 1537 os.unlink(inname) |
1829 # stat of copied file is ambiguous to original one | 1829 # stat of copied file is ambiguous to original one |
1830 advanced = ( | 1830 advanced = ( |
1831 oldstat.stat[stat.ST_MTIME] + 1) & 0x7fffffff | 1831 oldstat.stat[stat.ST_MTIME] + 1) & 0x7fffffff |
1832 os.utime(dest, (advanced, advanced)) | 1832 os.utime(dest, (advanced, advanced)) |
1833 except shutil.Error as inst: | 1833 except shutil.Error as inst: |
1834 raise Abort(str(inst)) | 1834 raise error.Abort(str(inst)) |
1835 | 1835 |
1836 def copyfiles(src, dst, hardlink=None, progress=lambda t, pos: None): | 1836 def copyfiles(src, dst, hardlink=None, progress=lambda t, pos: None): |
1837 """Copy a directory tree using hardlinks if possible.""" | 1837 """Copy a directory tree using hardlinks if possible.""" |
1838 num = 0 | 1838 num = 0 |
1839 | 1839 |
2807 pass | 2807 pass |
2808 | 2808 |
2809 try: | 2809 try: |
2810 return socket.getservbyname(pycompat.sysstr(port)) | 2810 return socket.getservbyname(pycompat.sysstr(port)) |
2811 except socket.error: | 2811 except socket.error: |
2812 raise Abort(_("no port number associated with service '%s'") % port) | 2812 raise error.Abort(_("no port number associated with service '%s'") |
2813 % port) | |
2813 | 2814 |
2814 class url(object): | 2815 class url(object): |
2815 r"""Reliable URL parser. | 2816 r"""Reliable URL parser. |
2816 | 2817 |
2817 This parses URLs and provides attributes for the following | 2818 This parses URLs and provides attributes for the following |
2968 if not self.host: | 2969 if not self.host: |
2969 self.host = None | 2970 self.host = None |
2970 | 2971 |
2971 if (self.host and self.scheme == 'file' and | 2972 if (self.host and self.scheme == 'file' and |
2972 self.host not in ('localhost', '127.0.0.1', '[::1]')): | 2973 self.host not in ('localhost', '127.0.0.1', '[::1]')): |
2973 raise Abort(_('file:// URLs can only refer to localhost')) | 2974 raise error.Abort(_('file:// URLs can only refer to localhost')) |
2974 | 2975 |
2975 self.path = path | 2976 self.path = path |
2976 | 2977 |
2977 # leave the query string escaped | 2978 # leave the query string escaped |
2978 for a in ('user', 'passwd', 'host', 'port', | 2979 for a in ('user', 'passwd', 'host', 'port', |