comparison mercurial/hgweb/hgweb_mod.py @ 36258:af0a19d8812b

py3: get bytes-repr of network errors portably This resolves a lot of weird issues in Python 3 around error strings. Differential Revision: https://phab.mercurial-scm.org/D2295
author Augie Fackler <augie@google.com>
date Sat, 17 Feb 2018 01:11:48 -0500
parents 98a00aa0288d
children a87093e2805d
comparison
equal deleted inserted replaced
36257:46c97973ee46 36258:af0a19d8812b
441 441
442 return content 442 return content
443 443
444 except (error.LookupError, error.RepoLookupError) as err: 444 except (error.LookupError, error.RepoLookupError) as err:
445 req.respond(HTTP_NOT_FOUND, ctype) 445 req.respond(HTTP_NOT_FOUND, ctype)
446 msg = str(err) 446 msg = pycompat.bytestr(err)
447 if (util.safehasattr(err, 'name') and 447 if (util.safehasattr(err, 'name') and
448 not isinstance(err, error.ManifestLookupError)): 448 not isinstance(err, error.ManifestLookupError)):
449 msg = 'revision not found: %s' % err.name 449 msg = 'revision not found: %s' % err.name
450 return tmpl('error', error=msg) 450 return tmpl('error', error=msg)
451 except (error.RepoError, error.RevlogError) as inst: 451 except (error.RepoError, error.RevlogError) as inst:
452 req.respond(HTTP_SERVER_ERROR, ctype) 452 req.respond(HTTP_SERVER_ERROR, ctype)
453 return tmpl('error', error=str(inst)) 453 return tmpl('error', error=pycompat.bytestr(inst))
454 except ErrorResponse as inst: 454 except ErrorResponse as inst:
455 req.respond(inst, ctype) 455 req.respond(inst, ctype)
456 if inst.code == HTTP_NOT_MODIFIED: 456 if inst.code == HTTP_NOT_MODIFIED:
457 # Not allowed to return a body on a 304 457 # Not allowed to return a body on a 304
458 return [''] 458 return ['']
459 return tmpl('error', error=str(inst)) 459 return tmpl('error', error=pycompat.bytestr(inst))
460 460
461 def check_perm(self, rctx, req, op): 461 def check_perm(self, rctx, req, op):
462 for permhook in permhooks: 462 for permhook in permhooks:
463 permhook(rctx, req, op) 463 permhook(rctx, req, op)
464 464