New submission from Shivaram Lingamneni <sling...@cs.stanford.edu>:

Importing the idna encoding has a significant time and memory cost. Therefore, 
the standard library tries to avoid importing it when it's not needed (i.e. 
when the domain name is already pure ASCII), e.g. in Lib/http/client.py and 
Modules/socketmodule.c with `idna_converter`.

However, there are code paths that still attempt to encode or decode as idna 
unconditionally, in particular Lib/ssl.py and _socket.getaddrinfo. Here's a 
one-line test case:

python3 -c "import sys, urllib.request; 
urllib.request.urlopen('https://www.google.com'); assert 'encodings.idna' not 
in sys.modules"

These code paths can be converted using existing code to do the import 
conditionally (I'll send a PR).

----------
assignee: christian.heimes
components: Interpreter Core, Library (Lib), SSL
messages: 413229
nosy: christian.heimes, slingamn
priority: normal
severity: normal
status: open
title: some code paths in ssl and _socket still import idna unconditionally
type: resource usage
versions: Python 3.11

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46750>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to