Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 78 by
stefan.h...@gmail.com: django html.py fix for jython -
where to put?
http://code.google.com/p/django-jython/issues/detail?id=78
I had to fix django's html.py to get it work with jython. I am not sure, if
this fix therefore should go on django or better django-jython project.
Following code I had to fix:
==========================
django, fix for jython
==========================
Lib/site-packages/django/utils/html.py
# sorry, forget to save original to make diff...
#jython fix, requires java6 / took from jython socket.py
_encode_idna = None
import sys
if sys.platform.startswith('java'):
# Attempt to provide IDNA (RFC 3490) support.
#
# Try java.net.IDN, built into java 6
#
import java.lang
idna_libraries = [
('java.net.IDN', 'toASCII', java.lang.IllegalArgumentException)
]
for idna_lib, idna_fn_name, exc in idna_libraries:
try:
m = __import__(idna_lib, globals(), locals(), [idna_fn_name])
idna_fn = getattr(m, idna_fn_name)
def _encode_idna(name):
try:
return idna_fn(name)
except exc:
raise UnicodeEncodeError(name)
break
except (AttributeError, ImportError), e:
pass
else:
_encode_idna = lambda x: x.encode("ascii")
def smart_urlquote(url):
....
if _encode_idna: # jython fix, see above
netloc = _encode_idna(netloc)
else:
netloc = netloc.encode('idna') # IDN -> ACE