Requests 2.0.14 API

IdnaEncoder
in package

IDNA URL encoder

Note: Not fully compliant, as nameprep does nothing yet.

Tags
link

IDNA specification

link

Punycode/Bootstrap specification

Table of Contents

Constants

ACE_PREFIX  = 'xn--'
ACE prefix used for IDNA
BOOTSTRAP_BASE  = 36
BOOTSTRAP_DAMP  = 700
BOOTSTRAP_INITIAL_BIAS  = 72
BOOTSTRAP_INITIAL_N  = 128
BOOTSTRAP_SKEW  = 38
BOOTSTRAP_TMAX  = 26
BOOTSTRAP_TMIN  = 1
MAX_LENGTH  = 64
Maximum length of a IDNA URL in ASCII.

Methods

encode()  : string
Encode a hostname using Punycode
to_ascii()  : string
Convert a UTF-8 text string to an ASCII string using Punycode
adapt()  : int|float
Adapt the bias
digit_to_char()  : string
Convert a digit to its respective character
nameprep()  : string
Prepare a text string for use as an IDNA name
utf8_to_codepoints()  : array<string|int, mixed>
Convert a UTF-8 string to a UCS-4 codepoint array

Constants

BOOTSTRAP_INITIAL_BIAS

public mixed BOOTSTRAP_INITIAL_BIAS = 72

BOOTSTRAP_INITIAL_N

public mixed BOOTSTRAP_INITIAL_N = 128

Methods

encode()

Encode a hostname using Punycode

public static encode(string|Stringable $hostname) : string
Parameters
$hostname : string|Stringable

Hostname

Tags
throws
InvalidArgument

When the passed argument is not a string or a stringable object.

Return values
string

Punycode-encoded hostname

to_ascii()

Convert a UTF-8 text string to an ASCII string using Punycode

public static to_ascii(string $text) : string
Parameters
$text : string

ASCII or UTF-8 string (max length 64 characters)

Tags
throws
Exception

Provided string longer than 64 ASCII characters (idna.provided_too_long)

throws
Exception

Prepared string longer than 64 ASCII characters (idna.prepared_too_long)

throws
Exception

Provided string already begins with xn-- (idna.provided_is_prefixed)

throws
Exception

Encoded string longer than 64 ASCII characters (idna.encoded_too_long)

Return values
string

ASCII string

adapt()

Adapt the bias

protected static adapt(int $delta, int $numpoints, bool $firsttime) : int|float
Parameters
$delta : int
$numpoints : int
$firsttime : bool
Tags
link
https://tools.ietf.org/html/rfc3492#section-6.1
Return values
int|float

New bias

function adapt(delta,numpoints,firsttime):

digit_to_char()

Convert a digit to its respective character

protected static digit_to_char(int $digit) : string
Parameters
$digit : int

Digit in the range 0-35

Tags
link
https://tools.ietf.org/html/rfc3492#section-5
throws
Exception

On invalid digit (idna.invalid_digit)

Return values
string

Single character corresponding to digit

nameprep()

Prepare a text string for use as an IDNA name

protected static nameprep(string $text) : string
Parameters
$text : string

Text to prepare.

Return values
string

Prepared string

utf8_to_codepoints()

Convert a UTF-8 string to a UCS-4 codepoint array

protected static utf8_to_codepoints(string $input) : array<string|int, mixed>

Based on \WpOrg\Requests\Iri::replace_invalid_with_pct_encoding()

Parameters
$input : string

Text to convert.

Tags
throws
Exception

Invalid UTF-8 codepoint (idna.invalidcodepoint)

Return values
array<string|int, mixed>

Unicode code points


        
On this page

Search results