--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/d4331b21-d9e8-4647-aa1f-357b00fb0125n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/90f58142-7808-4136-a06d-8ba1352857c7n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/81d94d7b-cd25-477c-ad11-41688b5c7aben%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/af30a602-1a8b-40ee-9133-556f375e3ae6n%40googlegroups.com.
You may use the codec encoding and decoding methods using the idna.codec module:
>>> import idna.codecHi Julien.I didn't get a canonical answer from the security team yet, but it may be that we can make the idna an optional dependency quite easily. I already have it installed in my dev environment, for instance, coming from selenium and requests.From the package docs: https://pypi.org/project/idna/You may use the codec encoding and decoding methods using the idna.codec module:
>>> import idna.codec>>> print('домен.испытание'.encode('idna'))b'xn--d1acufc.xn--80akhbyknj4f'So "use if installed" (catching the ImportError if not) would look feasible. (The usage in the punycode helper is just `domain.encode("idna")` which matches this example already.)
Would you fancy looking a PR around that?
We'd need *some* tests for both the installed and not-installed cases, ideally showing the difference. I didn't immediately have success with your https://fuss.standcore.com/ example:% python
Python 3.10.6 (v3.10.6:9c7b4bd164, Aug 1 2022, 17:13:48) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print('https://fuß.standcore.com/'.encode('idna'))
b'https://fuss.standcore.com/'
>>> import idna.codec
>>> print('https://fuß.standcore.com/'.encode('idna'))
b'https://fuss.standcore.com/' # Was expecting https://xn--fu-hia.standcore.com/ from discussion 🤔
>>> import idna
>>> idna.encode('https://fuß.standcore.com/')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/carlton/Envs/django/lib/python3.10/site-packages/idna/core.py", line 357, in encode
s = alabel(label)
File "/Users/carlton/Envs/django/lib/python3.10/site-packages/idna/core.py", line 269, in alabel
check_label(label)
File "/Users/carlton/Envs/django/lib/python3.10/site-packages/idna/core.py", line 250, in check_label
raise InvalidCodepoint('Codepoint {} at position {} of {} not allowed'.format(_unot(cp_value), pos+1, repr(label)))
idna.core.InvalidCodepoint: Codepoint U+003A at position 6 of 'https://fuß' not allowed
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/ac461b01-3992-4838-855b-c6335fbfc784n%40googlegroups.com.