Mercurial > public > mercurial-scm > hg-stable
diff tests/dummysmtpd.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 | 78f1899e4202 |
children | c102b704edb5 |
line wrap: on
line diff
--- a/tests/dummysmtpd.py Sat Oct 05 10:29:34 2019 -0400 +++ b/tests/dummysmtpd.py Sun Oct 06 09:45:02 2019 -0400 @@ -18,10 +18,12 @@ ui as uimod, ) + def log(msg): sys.stdout.write(msg) sys.stdout.flush() + class dummysmtpserver(smtpd.SMTPServer): def __init__(self, localaddr): smtpd.SMTPServer.__init__(self, localaddr, remoteaddr=None) @@ -38,6 +40,7 @@ # the expected way, and the server is available for subsequent requests. traceback.print_exc() + class dummysmtpsecureserver(dummysmtpserver): def __init__(self, localaddr, certfile): dummysmtpserver.__init__(self, localaddr) @@ -58,25 +61,30 @@ return smtpd.SMTPChannel(self, conn, addr) + def run(): try: asyncore.loop() except KeyboardInterrupt: pass + def _encodestrsonly(v): if isinstance(v, type(u'')): return v.encode('ascii') return v + def bytesvars(obj): unidict = vars(obj) bd = {k.encode('ascii'): _encodestrsonly(v) for k, v in unidict.items()} if bd[b'daemon_postexec'] is not None: bd[b'daemon_postexec'] = [ - _encodestrsonly(v) for v in bd[b'daemon_postexec']] + _encodestrsonly(v) for v in bd[b'daemon_postexec'] + ] return bd + def main(): op = optparse.OptionParser() op.add_option('-d', '--daemon', action='store_true') @@ -92,6 +100,7 @@ op.error('--certificate must be specified') addr = (opts.address, opts.port) + def init(): if opts.tls == 'none': dummysmtpserver(addr) @@ -100,9 +109,13 @@ log('listening at %s:%d\n' % addr) server.runservice( - bytesvars(opts), initfn=init, runfn=run, - runargs=[pycompat.sysexecutable, - pycompat.fsencode(__file__)] + pycompat.sysargv[1:]) + bytesvars(opts), + initfn=init, + runfn=run, + runargs=[pycompat.sysexecutable, pycompat.fsencode(__file__)] + + pycompat.sysargv[1:], + ) + if __name__ == '__main__': main()