Re: Treatment of NANs in the statistics module
On Saturday, March 17, 2018 at 3:22:46 PM UTC+5:30, Léo El Amri wrote: > On 17/03/2018 00:16, Steven D'Aprano wrote: > > The bug tracker currently has a discussion of a bug in the median(), > > median_low() and median_high() functions that they wrongly compute the > > medians in the face of NANs in the data: > > > > https://bugs.python.org/issue33084 > > > > I would like to ask people how they would prefer to handle this issue: > > TL;DR: I choose (5) Just like to point out that 5 is really 5a and 5b 5a One can give the option at the function call point 5b One can set a module level flag: See how pandas sets 'pandas.options. ...' for similar choices https://pandas.pydata.org/pandas-docs/stable/missing_data.html I guess I'd go for 5b even though it makes the code less 'functional' in the sense of FP — ie the same (looking) function call can have different effects -- https://mail.python.org/mailman/listinfo/python-list
Re: TLSServer: certificate one request behind...
Hello? Rfd, anyone? Thus wrote Fabiano Sidler: > Thus wrote Fabiano Sidler: > > What's the reason for this? Please find attached my TLSServer. > > Oh, sorry...! Apparently, the attachment has been stripped. Here inline: > > === tlsserver.py === > from socketserver import ThreadingTCPServer,StreamRequestHandler > import ssl > > class TLSServer(ThreadingTCPServer): > def __init__(self, *args, **kwargs): > super(TLSServer, self).__init__(*args, **kwargs) > ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) > ctx.set_servername_callback(self.servername_callback) > ctx.check_hostname = False > self._ctx = ctx > def get_request(self): > s,a = super(TLSServer, self).get_request() > s = self._ctx.wrap_socket(s, server_side=True) > return s,a > def servername_callback(self, sock, req_hostname, cb_context): > return ssl.ALERT_DESCRIPTION_INTERNAL_ERROR > > > from OpenSSL import crypto as x509 > from tempfile import NamedTemporaryFile > > class SelfSigningServer(TLSServer): > def servername_callback(self, sock, req_hostname, cb_context): > key = x509.PKey() > key.generate_key(x509.TYPE_RSA, 2048) > cert = x509.X509() > subj = cert.get_subject() > subj.C = 'CH' > subj.ST = 'ZH' > subj.L = 'Zurich' > subj.O = 'ACME Inc.' > subj.OU = 'IT dept.' > subj.CN = req_hostname > cert.set_version(0x02) > cert.set_serial_number(1000) > cert.gmtime_adj_notBefore(0) > cert.gmtime_adj_notAfter(10*365*24*60*60) > cert.set_issuer(subj) > cert.set_pubkey(key) > cert.sign(key, 'sha256') > certfile = NamedTemporaryFile() > keyfile = NamedTemporaryFile() > certfile.write(x509.dump_certificate(x509.FILETYPE_PEM, cert)) > keyfile.write(x509.dump_privatekey(x509.FILETYPE_PEM, key)) > certfile.seek(0) > keyfile.seek(0) > cb_context.load_cert_chain(certfile=certfile.name, > keyfile=keyfile.name) > cb_context.set_servername_callback(self.servername_callback) > sock.context = cb_context > certfile.close() > keyfile.close() > > class SelfSigningHandler(StreamRequestHandler): > def handle(self): > self.wfile.write(b'Hello World!\r\n') > > server = SelfSigningServer(('localhost',1234), SelfSigningHandler) > server.serve_forever() > === tlsserver.py === > > Thanks again! > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Keys in dict and keys not in dict
hello, i'd like to check if a function parameter (json) has all the keys I expect it to have and if it doesn't - point out the one that is missing. What's the good way of doing that? "good way" - something concise... i'd like to avoid using : if key in json: #pass else print(" Oops, i did it again ...") thank you AZ -- https://mail.python.org/mailman/listinfo/python-list
Re: Keys in dict and keys not in dict
On Mon, Mar 19, 2018 at 2:32 PM, Andrew Z wrote: > hello, > > i'd like to check if a function parameter (json) has all the keys I expect > it to have and if it doesn't - point out the one that is missing. > > What's the good way of doing that? > > "good way" - something concise... i'd like to avoid using : > if key in json: > #pass > else >print(" Oops, i did it again ...") Sounds like a set operation to me. expected = {"foo", "bar", "spam"} missing = expected - set(json) if missing: print("Missing keys:", missing) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Keys in dict and keys not in dict
Chris Angelico writes: > Sounds like a set operation to me. > > expected = {"foo", "bar", "spam"} > missing = expected - set(json) That works (because iterating a dict returns its keys). But it is less immediately understandable, IMO, than this:: expected = {"foo", "bar", "spam"} missing = expected - set(json.keys()) -- \ “The greater the artist, the greater the doubt; perfect | `\ confidence is granted to the less talented as a consolation | _o__) prize.” —Robert Hughes | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: Keys in dict and keys not in dict
On Mon, Mar 19, 2018 at 3:18 PM, Ben Finney wrote: > Chris Angelico writes: > >> Sounds like a set operation to me. >> >> expected = {"foo", "bar", "spam"} >> missing = expected - set(json) > > That works (because iterating a dict returns its keys). But it is less > immediately understandable, IMO, than this:: > > expected = {"foo", "bar", "spam"} > missing = expected - set(json.keys()) > Sure, whichever way you want to do it. Either way, it's a set difference operation that gives the OP's desired information. ChrisA -- https://mail.python.org/mailman/listinfo/python-list