You are looking at historical revision 26526 of this page. It may differ significantly from its current revision.
An interface to Internationalizing Domain Names in Applications (IDNA).
The idna egg allows you to convert Internationalized Domain Names from Unicode to a restricted ASCII representation suitable for DNS, and vice versa. It uses GNU libidn to do the conversion.
The encoding and decoding mechanism used is Punycode, and the format of the resulting ASCII string is called ASCII Compatible Encoding (ACE). An ACE-format string is simply a Punycode string with a unique ACE prefix, xn--, prepended to distinguish it from regular ASCII.
This extension assumes that input and output strings are UTF-8 encoded.
'''procedure:''' (idna:nameprep str)
Prepares str according to the Stringprep profile Nameprep. In simpler terms, it performs processing on str such as lowercasing and other normalization, in order to increase interoperability with the DNS, and returns the result.
'''procedure:''' (idna:to-ascii str)
Convert UTF-8 domain name to ASCII string in ACE format. All labels (sections of a domain name, separated by dots) are converted.
The ToASCII algorithm will apply NamePrep to an individual label before conversion if it detects any non-ASCII characters, but does not do so if the label is entirely ASCII. You may wish to pass the entire string through idna:nameprep beforehand in order to lowercase the pure-ASCII labels.
An error will be signaled on certain fatal conditions (for example, if the result is too long for DNS, or if the input is non-ASCII yet already contains the ACE prefix).
'''procedure:''' (idna:to-unicode str)
Convert ASCII string, possibly in ACE format, to UTF-8. If decoding fails, the original string is returned. It is therefore safe to pass unencoded ASCII strings to this procedure.
(idna:nameprep "WWW.Λ-CALCULUS.GOV") ; => "www.λ-calculus.gov" (idna:to-ascii "www.λ-calculus.gov") ; => "www.xn---calculus-k0g.gov" (idna:to-ascii "WWW.Λ-CALCULUS.GOV") ; => "WWW.xn---calculus-k0g.GOV" (idna:to-unicode "www.xn---calculus-k0g.gov") ; => "www.λ-calculus.gov"
About this egg
- Initial release
Copyright (c) 2007 Jim Ursetto. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.