py3: don’t subscript socket.error
On Python 2, socket.error was subscriptable. On Python 3, socket.error is an
alias to OSError and is not subscriptable. The except block passes the
exception to self.send_error(). This fails on both Python 2 (if it was
executed) and Python 3, as it expects a string.
Getting the attribute .strerror works on Python 2 and Python 3, and has the
same effect as the previous code on Python 2.
# Dummy extension to define a namespace containing revision names
from __future__ import absolute_import
from mercurial import namespaces
def reposetup(ui, repo):
names = {b'r%d' % rev: repo[rev].node() for rev in repo}
namemap = lambda r, name: names.get(name)
nodemap = lambda r, node: [b'r%d' % repo[node].rev()]
ns = namespaces.namespace(
b'revnames',
templatename=b'revname',
logname=b'revname',
listnames=lambda r: names.keys(),
namemap=namemap,
nodemap=nodemap,
)
repo.names.addnamespace(ns)