r76908 - in /branches/upstream/libidna-punycode-perl: ./ current/ current/Changes current/MANIFEST current/Makefile.PL current/README current/lib/ current/lib/IDNA/ current/lib/IDNA/Punycode.pm current/t/ current/t/00_compile.t

fabreg-guest at users.alioth.debian.org fabreg-guest at users.alioth.debian.org
Fri Jul 1 22:58:13 UTC 2011


Author: fabreg-guest
Date: Fri Jul  1 22:58:04 2011
New Revision: 76908

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=76908
Log:
[svn-inject] Installing original source of libidna-punycode-perl (0.03)

Added:
    branches/upstream/libidna-punycode-perl/
    branches/upstream/libidna-punycode-perl/current/
    branches/upstream/libidna-punycode-perl/current/Changes
    branches/upstream/libidna-punycode-perl/current/MANIFEST
    branches/upstream/libidna-punycode-perl/current/Makefile.PL
    branches/upstream/libidna-punycode-perl/current/README
    branches/upstream/libidna-punycode-perl/current/lib/
    branches/upstream/libidna-punycode-perl/current/lib/IDNA/
    branches/upstream/libidna-punycode-perl/current/lib/IDNA/Punycode.pm
    branches/upstream/libidna-punycode-perl/current/t/
    branches/upstream/libidna-punycode-perl/current/t/00_compile.t

Added: branches/upstream/libidna-punycode-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libidna-punycode-perl/current/Changes?rev=76908&op=file
==============================================================================
--- branches/upstream/libidna-punycode-perl/current/Changes (added)
+++ branches/upstream/libidna-punycode-perl/current/Changes Fri Jul  1 22:58:04 2011
@@ -1,0 +1,11 @@
+Revision history for Perl extension IDNA::Punycode
+
+0.03  Thu Sep  1 14:49:17 MEST 2005
+	* added idn_prefix() function
+	* made "xn--" default prefix for punycode format
+
+0.02  Mon May 20 12:17:26 JST 2002
+	* [API change] now exception is thrown in conversion failure
+
+0.01  Tue May  7 11:47:28 2002
+	- original version

Added: branches/upstream/libidna-punycode-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libidna-punycode-perl/current/MANIFEST?rev=76908&op=file
==============================================================================
--- branches/upstream/libidna-punycode-perl/current/MANIFEST (added)
+++ branches/upstream/libidna-punycode-perl/current/MANIFEST Fri Jul  1 22:58:04 2011
@@ -1,0 +1,5 @@
+Changes
+MANIFEST			This list of files
+Makefile.PL
+lib/IDNA/Punycode.pm
+t/00_compile.t

Added: branches/upstream/libidna-punycode-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libidna-punycode-perl/current/Makefile.PL?rev=76908&op=file
==============================================================================
--- branches/upstream/libidna-punycode-perl/current/Makefile.PL (added)
+++ branches/upstream/libidna-punycode-perl/current/Makefile.PL Fri Jul  1 22:58:04 2011
@@ -1,0 +1,9 @@
+use ExtUtils::MakeMaker;
+require 5.6.0;
+WriteMakefile(
+    'NAME'      => 'IDNA::Punycode',
+    'VERSION_FROM' => 'lib/IDNA/Punycode.pm', # finds $VERSION
+    'PREREQ_PM' => {
+	'Test::More' => 0.32,
+    },
+);

Added: branches/upstream/libidna-punycode-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libidna-punycode-perl/current/README?rev=76908&op=file
==============================================================================
--- branches/upstream/libidna-punycode-perl/current/README (added)
+++ branches/upstream/libidna-punycode-perl/current/README Fri Jul  1 22:58:04 2011
@@ -1,0 +1,23 @@
+IDNA::Punycode - conversion from IDN domain names to Punycode and back
+======================================================================
+
+1. DESCRIPTION
+--------------
+
+IDNA::Punycode will convert a domain-name from the "native" IDN
+(Internationalized Domain Name) form, i.e., a domain-name
+containing non-ASCII characters, into it's corresponding
+ACE (ASCII Compatible Encoding), and vice versa.
+
+Before you do the ACE conversion, however, you must first "normalize"
+the string to convert using Net::IDN::Nameprep.  See RFC3940
+(http://www.ietf.org/rfc/rfc3490.txt) for more information.
+
+IDNA::Punycode has no dependencies.
+
+2. COPYRIGHT
+------------
+
+Copyright (c) Tatsuhiko Miyagawa <miyagawa at bulknews.net>. This program
+is free software; you can redistribute it and/or modify it under the
+same terms as Perl itself

Added: branches/upstream/libidna-punycode-perl/current/lib/IDNA/Punycode.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libidna-punycode-perl/current/lib/IDNA/Punycode.pm?rev=76908&op=file
==============================================================================
--- branches/upstream/libidna-punycode-perl/current/lib/IDNA/Punycode.pm (added)
+++ branches/upstream/libidna-punycode-perl/current/lib/IDNA/Punycode.pm Fri Jul  1 22:58:04 2011
@@ -1,0 +1,240 @@
+package IDNA::Punycode;
+
+use strict;
+our $VERSION = 0.03;
+
+require Exporter;
+our @ISA	= qw(Exporter);
+our @EXPORT = qw(encode_punycode decode_punycode idn_prefix);
+
+use integer;
+
+our $DEBUG = 0;
+our $PREFIX = 'xn--';
+
+use constant BASE => 36;
+use constant TMIN => 1;
+use constant TMAX => 26;
+use constant SKEW => 38;
+use constant DAMP => 700;
+use constant INITIAL_BIAS => 72;
+use constant INITIAL_N => 128;
+
+my $Delimiter = chr 0x2D;
+my $BasicRE   = qr/[\x00-\x7f]/;
+
+sub _croak { require Carp; Carp::croak(@_); }
+
+sub idn_prefix {
+	$PREFIX = shift;
+}
+
+sub digit_value {
+	my $code = shift;
+	return ord($code) - ord("A") if $code =~ /[A-Z]/;
+	return ord($code) - ord("a") if $code =~ /[a-z]/;
+	return ord($code) - ord("0") + 26 if $code =~ /[0-9]/;
+	return;
+}
+
+sub code_point {
+	my $digit = shift;
+	return $digit + ord('a') if 0 <= $digit && $digit <= 25;
+	return $digit + ord('0') - 26 if 26 <= $digit && $digit <= 36;
+	die 'NOT COME HERE';
+}
+
+sub adapt {
+	my($delta, $numpoints, $firsttime) = @_;
+	$delta = $firsttime ? $delta / DAMP : $delta / 2;
+	$delta += $delta / $numpoints;
+	my $k = 0;
+	while ($delta > ((BASE - TMIN) * TMAX) / 2) {
+		$delta /= BASE - TMIN;
+		$k += BASE;
+	}
+	return $k + (((BASE - TMIN + 1) * $delta) / ($delta + SKEW));
+}
+
+sub decode_punycode {
+	my $code = shift;
+
+	my $n	  = INITIAL_N;
+	my $i	  = 0;
+	my $bias   = INITIAL_BIAS;
+	my @output;
+
+	if ($PREFIX) {
+		if ($code !~ /^$PREFIX/) {
+			return $code;
+		}
+		$code =~ s/^$PREFIX//;
+	}
+
+	if ($code =~ s/(.*)$Delimiter//o) {
+		push @output, map ord, split //, $1;
+		return _croak('non-basic code point') unless $1 =~ /^$BasicRE*$/o;
+	}
+
+	while ($code) {
+		my $oldi = $i;
+		my $w	= 1;
+		LOOP:
+		for (my $k = BASE; 1; $k += BASE) {
+			my $cp = substr($code, 0, 1, '');
+			my $digit = digit_value($cp);
+			defined $digit or return _croak("invalid punycode input");
+			$i += $digit * $w;
+			my $t = ($k <= $bias) ? TMIN
+			: ($k >= $bias + TMAX) ? TMAX : $k - $bias;
+			last LOOP if $digit < $t;
+			$w *= (BASE - $t);
+		}
+		$bias = adapt($i - $oldi, @output + 1, $oldi == 0);
+		warn "bias becomes $bias" if $DEBUG;
+		$n += $i / (@output + 1);
+		$i = $i % (@output + 1);
+		splice(@output, $i, 0, $n);
+		warn join " ", map sprintf('%04x', $_), @output if $DEBUG;
+		$i++;
+	}
+	return join '', map chr, @output;
+}
+
+sub encode_punycode {
+	my $input = shift;
+	# my @input = split //, $input; # doesn't work in 5.6.x!
+	my @input = map substr($input, $_, 1), 0..length($input)-1;
+
+	my $n	 = INITIAL_N;
+	my $delta = 0;
+	my $bias  = INITIAL_BIAS;
+
+	my @output;
+	my @basic = grep /$BasicRE/, @input;
+	my $h = my $b = @basic;
+	#push @output, @basic, $Delimiter if $b > 0;
+	push @output, @basic if $b > 0;
+	warn "basic codepoints: (@output)" if $DEBUG;
+
+	if ($h < @input) {
+		$PREFIX && unshift(@output, $PREFIX);
+		push(@output, $Delimiter);
+	} else {
+		return join '', @output;
+	}
+
+	while ($h < @input) {
+		my $m = min(grep { $_ >= $n } map ord, @input);
+		warn sprintf "next code point to insert is %04x", $m if $DEBUG;
+		$delta += ($m - $n) * ($h + 1);
+		$n = $m;
+		for my $i (@input) {
+			my $c = ord($i);
+			$delta++ if $c < $n;
+			if ($c == $n) {
+				my $q = $delta;
+				LOOP:
+				for (my $k = BASE; 1; $k += BASE) {
+					my $t = ($k <= $bias) ? TMIN :
+					($k >= $bias + TMAX) ? TMAX : $k - $bias;
+					last LOOP if $q < $t;
+					my $cp = code_point($t + (($q - $t) % (BASE - $t)));
+					push @output, chr($cp);
+					$q = ($q - $t) / (BASE - $t);
+				}
+				push @output, chr(code_point($q));
+				$bias = adapt($delta, $h + 1, $h == $b);
+				warn "bias becomes $bias" if $DEBUG;
+				$delta = 0;
+				$h++;
+			}
+		}
+		$delta++;
+		$n++;
+	}
+	return join '', @output;
+}
+
+sub min {
+	my $min = shift;
+	for (@_) { $min = $_ if $_ <= $min }
+	return $min;
+}
+
+1;
+__END__
+
+=head1 NAME
+
+IDNA::Punycode - encodes Unicode string in Punycode
+
+=head1 SYNOPSIS
+
+  use IDNA::Punycode;
+  idn_prefix('xn--');
+  $punycode = encode_punycode($unicode);
+  $unicode  = decode_punycode($punycode);
+
+=head1 DESCRIPTION
+
+IDNA::Punycode is a module to encode / decode Unicode strings into
+Punycode, an efficient encoding of Unicode for use with IDNA.
+
+This module requires Perl 5.6.0 or over to handle UTF8 flagged Unicode
+strings.
+
+=head1 FUNCTIONS
+
+This module exports following functions by default.
+
+=over 4
+
+=item encode_punycode
+
+  $punycode = encode_punycode($unicode);
+
+takes Unicode string (UTF8-flagged variable) and returns Punycode
+encoding for it.
+
+=item decode_punycode
+
+  $unicode = decode_punycode($punycode)
+
+takes Punycode encoding and returns original Unicode string.
+
+=item idn_prefix
+
+  idn_prefix($prefix);
+
+causes encode_punycode() to add $prefix to ACE-string after conversion.
+As a side-effect decode_punycode() will only consider strings
+beginning with $prefix as punycode representations.
+
+According to RFC 3490 the ACE prefix "xn--" had been chosen as the
+standard.  Thus, "xn--" is also the default ACE prefix.  For compatibility
+I'm leaving idn_prefix() in the module.  Use C<idn_prefix(undef)> to
+get the old behaviour.
+
+=back
+
+These functions throws exceptionsn on failure. You can catch 'em via
+C<eval>.
+
+=head1 AUTHORS
+
+Tatsuhiko Miyagawa E<lt>miyagawa at bulknews.netE<gt> is the original
+author and wrote almost all the code.
+
+Robert Urban E<lt>urban at UNIX-Beratung.deE<gt> added C<idn_prefix()>.
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=head1 SEE ALSO
+
+http://www.ietf.org/internet-drafts/draft-ietf-idn-punycode-01.txt
+
+L<Encode::Punycode>
+
+=cut

Added: branches/upstream/libidna-punycode-perl/current/t/00_compile.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libidna-punycode-perl/current/t/00_compile.t?rev=76908&op=file
==============================================================================
--- branches/upstream/libidna-punycode-perl/current/t/00_compile.t (added)
+++ branches/upstream/libidna-punycode-perl/current/t/00_compile.t Fri Jul  1 22:58:04 2011
@@ -1,0 +1,4 @@
+use strict;
+use Test::More tests => 1;
+
+BEGIN { use_ok 'IDNA::Punycode' }




More information about the Pkg-perl-cvs-commits mailing list