⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 heuristic.pm

📁 美国CMU大学开发的操作系统健壮性评测软件
💻 PM
字号:
package URI::Heuristic;# $Id: Heuristic.pm,v 1.1 1999/07/21 19:12:38 kraven Exp $=head1 NAMEuf_urlstr - Expand URL using heuristics=head1 SYNOPSIS use URI::Heuristic qw(uf_urlstr); $url = uf_urlstr("perl");             # http://www.perl.com $url = uf_urlstr("www.sol.no/sol");   # http://www.sol.no/sol $url = uf_urlstr("aas");              # http://www.aas.no $url = uf_urlstr("ftp.funet.fi");     # ftp://ftp.funet.fi $url = uf_urlstr("/etc/passwd");      # file:/etc/passwd=head1 DESCRIPTIONThis module provide functions that expand strings into real absoluteURLs using some builtin heuristics.  Strings that already representabsolute URLs (i.e. start with a C<scheme:> part) are never modifiedand are returned unchanged.  The main use of these functions are toallow abbreviated URLs similar to what many web browsers allow for URLstyped in by the user.The following functions are provided:=over 4=item uf_urlstr($str)The uf_urlstr() function will try to make the string passed asargument into a proper absolute URL string.  The "uf_" prefix standsfor "User Friendly".=item uf_url($str)This functions work the same way as uf_urlstr() but it willreturn a C<URI::URL> object.=back=head1 ENVIRONMENTIf the hostname portion of a URL does not contain any dots, thencertain qualified guesses will be made.  These guesses are governed bethe following two environment variables.=over 10=item COUNTRYThis is the two letter country code (ISO 3166) for your location.  Ifthe domain name of your host ends with two letters, then it is takento be the default country. See also L<Locale::Country>.=item URL_GUESS_PATTERNContain a space separated list of URL patterns to try.  The string"ACME" is for some reason used as a placeholder for the host name inthe URL provided.  Example: URL_GUESS_PATTERN="www.ACME.no www.ACME.se www.ACME.com" export URL_GUESS_PATTERNSpecifying URL_GUESS_PATTERN disables any guessing rules based oncountry.  An empty URL_GUESS_PATTERN disables any guessing thatinvolves host name lookups.=back=head1 COPYRIGHTCopyright 1997-1998, Gisle AasThis library is free software; you can redistribute it and/ormodify it under the same terms as Perl itself.=cutuse strict;use vars qw(@EXPORT_OK $VERSION $MY_COUNTRY %LOCAL_GUESSING $DEBUG);require Exporter;*import = \&Exporter::import;@EXPORT_OK = qw(uf_url uf_urlstr);$VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/);eval {    require Net::Domain;    my $fqdn = Net::Domain::hostfqdn();    $MY_COUNTRY = lc($1) if $fqdn =~ /\.([a-zA-Z]{2})$/;    # Some other heuristics to guess country?  Perhaps looking    # at some environment variable (LANG, LC_ALL, ???)    $MY_COUNTRY = $ENV{COUNTRY} if exists $ENV{COUNTRY};};%LOCAL_GUESSING =( 'us' => [qw(www.ACME.gov www.ACME.mil)], 'uk' => [qw(www.ACME.co.uk www.ACME.org.uk www.ACME.ac.uk)], 'au' => [qw(www.ACME.com.au www.ACME.org.au www.ACME.edu.au)], 'il' => [qw(www.ACME.co.il www.ACME.org.il www.ACME.net.il)], # send corrections and new entries to <aas@sn.no>);sub uf_url ($){    require URI::URL;    URI::URL->new(uf_urlstr($_[0]));}sub uf_urlstr ($){    local($_) = @_;    print STDERR "uf_urlstr: resolving $_\n" if $DEBUG;    return unless defined;    s/^\s+//;    s/\s+$//;    if (/^(www|web|home)\./) {	$_ = "http://$_";    } elsif (/^(ftp|gopher|news|wais|http|https)\./) {	$_ = "$1://$_";    } elsif (m,^/,      ||          # absolute file name	     m,^\.\.?/, ||          # relative file name	     m,^[a-zA-Z]:[/\\],)    # dosish file name    {	$_ = "file:$_";    } elsif (/^\w+([\.\-]\w+)*\@(\w+\.)+\w{2,3}$/) {	$_ = "mailto:$_";    } elsif (!/^[.+\-\w]+:/) {      # no scheme specified	if (s/^(\w+(?:\.\w+)*)([\/:\?\#]|$)/$2/) {	    my $host = $1;	    if ($host !~ /\./ && $host ne "localhost") {		my @guess;		if (exists $ENV{URL_GUESS_PATTERN}) {		    @guess = map { s/\bACME\b/$host/; $_ }		             split(' ', $ENV{URL_GUESS_PATTERN});		} else {		    if ($MY_COUNTRY) {			my $special = $LOCAL_GUESSING{$MY_COUNTRY};			if ($special) {			    my @special = @$special;			    push(@guess, map { s/\bACME\b/$host/; $_ }                                               @special);			} else {			    push(@guess, "www.$host.$MY_COUNTRY");			}		    }		    push(@guess, map "www.$host.$_",			             "com", "org", "net", "edu", "int");		}		my $guess;		for $guess (@guess) {		    print STDERR "uf_urlstr: gethostbyname('$guess')..."		      if $DEBUG;		    if (gethostbyname($guess)) {			print STDERR "yes\n" if $DEBUG;			$host = $guess;			last;		    }		    print STDERR "no\n" if $DEBUG;		}	    }	    $_ = "http://$host$_";	} else {	    # pure junk, just return it unchanged...	}    }    print STDERR "uf_urlstr: ==> $_\n" if $DEBUG;    $_;}1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -