Mercurial > public > mercurial-scm > hg-stable
diff hgext/zeroconf/__init__.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | fa2071753dc2 |
children | 687b865b95ad |
line wrap: on
line diff
--- a/hgext/zeroconf/__init__.py Sat Oct 05 10:29:34 2019 -0400 +++ b/hgext/zeroconf/__init__.py Sun Oct 06 09:45:02 2019 -0400 @@ -37,9 +37,7 @@ pycompat, ui as uimod, ) -from mercurial.hgweb import ( - server as servermod -) +from mercurial.hgweb import server as servermod # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should @@ -52,6 +50,7 @@ server = None localip = None + def getip(): # finds external-facing interface without sending any packets (Linux) try: @@ -83,6 +82,7 @@ return dumbip + def publish(name, desc, path, port): global server, localip if not server: @@ -98,25 +98,32 @@ name = r"%s-%s" % (hostname, name) # advertise to browsers - svc = Zeroconf.ServiceInfo('_http._tcp.local.', - pycompat.bytestr(name + r'._http._tcp.local.'), - server = host, - port = port, - properties = {'description': desc, - 'path': "/" + path}, - address = localip, weight = 0, priority = 0) + svc = Zeroconf.ServiceInfo( + '_http._tcp.local.', + pycompat.bytestr(name + r'._http._tcp.local.'), + server=host, + port=port, + properties={'description': desc, 'path': "/" + path}, + address=localip, + weight=0, + priority=0, + ) server.registerService(svc) # advertise to Mercurial clients - svc = Zeroconf.ServiceInfo('_hg._tcp.local.', - pycompat.bytestr(name + r'._hg._tcp.local.'), - server = host, - port = port, - properties = {'description': desc, - 'path': "/" + path}, - address = localip, weight = 0, priority = 0) + svc = Zeroconf.ServiceInfo( + '_hg._tcp.local.', + pycompat.bytestr(name + r'._hg._tcp.local.'), + server=host, + port=port, + properties={'description': desc, 'path': "/" + path}, + address=localip, + weight=0, + priority=0, + ) server.registerService(svc) + def zc_create_server(create_server, ui, app): httpd = create_server(ui, app) port = httpd.port @@ -146,17 +153,22 @@ publish(name, desc, path, port) return httpd + # listen + class listener(object): def __init__(self): self.found = {} + def removeService(self, server, type, name): if repr(name) in self.found: del self.found[repr(name)] + def addService(self, server, type, name): self.found[repr(name)] = server.getServiceInfo(type, name) + def getzcpaths(): ip = getip() if ip.startswith(r'127.'): @@ -167,11 +179,15 @@ time.sleep(1) server.close() for value in l.found.values(): - name = value.name[:value.name.index(b'.')] - url = r"http://%s:%s%s" % (socket.inet_ntoa(value.address), value.port, - value.properties.get(r"path", r"/")) + name = value.name[: value.name.index(b'.')] + url = r"http://%s:%s%s" % ( + socket.inet_ntoa(value.address), + value.port, + value.properties.get(r"path", r"/"), + ) yield b"zc-" + name, pycompat.bytestr(url) + def config(orig, self, section, key, *args, **kwargs): if section == "paths" and key.startswith("zc-"): for name, path in getzcpaths(): @@ -179,12 +195,14 @@ return path return orig(self, section, key, *args, **kwargs) + def configitems(orig, self, section, *args, **kwargs): repos = orig(self, section, *args, **kwargs) if section == "paths": repos += getzcpaths() return repos + def configsuboptions(orig, self, section, name, *args, **kwargs): opt, sub = orig(self, section, name, *args, **kwargs) if section == "paths" and name.startswith("zc-"): @@ -195,12 +213,14 @@ return zcurl, sub return opt, sub + def defaultdest(orig, source): for name, path in getzcpaths(): if path == source: return name.encode(encoding.encoding) return orig(source) + def cleanupafterdispatch(orig, ui, options, cmd, cmdfunc): try: return orig(ui, options, cmd, cmdfunc) @@ -211,6 +231,7 @@ if server: server.close() + extensions.wrapfunction(dispatch, '_runcommand', cleanupafterdispatch) extensions.wrapfunction(uimod.ui, 'config', config)