CharacterMapping
This module maps Unicode characters to native encoding.
Source characters can be specified as Unicode characters ("<character>" or '<character>'), as decimal values (<number>), or as hexadecimal values (0x<number>).
Destination characters are specified as integer values.
Mapping specifications can be given as a list or a string:
-
A list specification has the following formats:
-
For single character mapping:
[<source>, <target>] -
For range mapping:
[<source_start>, <source_end>, <target_start>]
-
-
A string specification has the following format:
-
For single character mapping:
<source>:<target> -
For range mapping:
<source_start>-<source_end>:<target_start>
-
CharacterMapping(mappings=[])
Map Unicode characters to native encoding.
| PARAMETER | DESCRIPTION |
|---|---|
mappings
|
List of mappings to add.
TYPE:
|
add_mapping(arguments)
Add a mapping.
| PARAMETER | DESCRIPTION |
|---|---|
arguments
|
Mapping to add.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If mapping specification is invalid. |
add_range(source_start, source_end, target)
Add a range of mappings.
| PARAMETER | DESCRIPTION |
|---|---|
source_start
|
Start of Unicode character range.
TYPE:
|
source_end
|
End of Unicode character range.
TYPE:
|
target
|
Start of native character range.
TYPE:
|
add_single(character, target)
Add a single mapping.
| PARAMETER | DESCRIPTION |
|---|---|
character
|
Unicode character.
TYPE:
|
target
|
Native character.
TYPE:
|
encode(string)
Encode Unicode string.
| PARAMETER | DESCRIPTION |
|---|---|
string
|
String to encode.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bytes
|
Encoded string. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If string contains unmapped characters. |
petscii()
staticmethod
Create PETSCII character mapping.
| RETURNS | DESCRIPTION |
|---|---|
CharacterMapping
|
PETSCII character mapping. |