Skip to main content

Two-stage encoding for Persian text.

Project description

Iran System Encoding

Python package CIPython Package using Conda

A Python package for encoding and decoding text using the Iran System character set, designed for environments like NDS Station Displays.

This library provides a direct mapping from Unicode characters to the custom Iran System byte representation. It includes robust support for both English (LTR) and Persian (RTL) text, automatically handling the complexities of bidirectional text display.

Key Features

  • Direct Encoding: A single-stage mapping from Unicode to the Iran System character set.
  • Bidirectional Text Support: Automatically detects and reverses Right-to-Left (Persian) text segments for correct logical-to-visual ordering, while leaving Left-to-Right (English) segments untouched.
  • Full ASCII and Persian Support: The character map includes standard ASCII, Persian letters, and Persian digits.
  • Fallback for Unknown Characters: Gracefully handles characters not in the map by replacing them with a '?'.
  • Command-Line Interface: Includes a CLI tool for easy encoding and decoding from the terminal.

Installation

To install the package directly from GitHub:

pip install git+https://github.com/movtigroup/Iran-System-encoding.git

Library Usage

The library provides simple encode() and decode() functions.

Example 1: Pure Persian (RTL)

from iran_encoding import encode, decode

text = "سلام دنیا"
encoded = encode(text)
print(f"Original: {text}")
print(f"Encoded: {encoded.hex()}")

decoded = decode(encoded)
print(f"Decoded: {decoded}")
# Correctly prints: سلام دنیا

Example 2: Pure English (LTR)

from iran_encoding import encode, decode

text = "Hello, World!"
encoded = encode(text)
print(f"\nOriginal: {text}")
print(f"Encoded: {encoded.hex()}")

decoded = decode(encoded)
print(f"Decoded: {decoded}")
# Correctly prints: Hello, World!

Example 3: Mixed Bidirectional Text

The library automatically handles the ordering of text segments.

from iran_encoding import encode, decode

text = "Final ETA: ۱۰ دقیقه"
encoded = encode(text)
print(f"\nOriginal: {text}")
print(f"Encoded: {encoded.hex()}")

decoded = decode(encoded)
print(f"Decoded: {decoded}")
# Correctly prints: Final ETA: ۱۰ دقیقه

Command-Line Interface

You can also use the package from the command line.

encode

iran-encoding encode "Test: تست"

This will print the raw encoded bytes to standard output.

decode

The decode command requires the input to be a Python bytes literal string.

iran-encoding decode "b'\\x54\\x65\\x73\\x74\\x3a\\x20\\x91\\x9d\\x8f'"

This will print the decoded string: Test: تست

Note: You need to wrap the byte string in quotes (" ") and prefix it with b'' to ensure it is correctly parsed by the command line.

decode-hex

The decode-hex command decodes a string of hexadecimal characters into text.

iran-encoding decode-hex 546573743a20919d8f

This will print the decoded string: Test: تست

WebSocket Support

This library also provides WebSocket support for both a server and a client.

WebSocket Server

You can start a WebSocket server that will listen for incoming messages and encode or decode them.

iran-encoding ws-server --host 0.0.0.0 --port 8765

The server expects messages in the format "command:data", where command is one of encode, decode, or decode-hex.

WebSocket Client

You can use the WebSocket client to send a message to the server and receive the response.

iran-encoding ws-client ws://localhost:8765 "encode:سلام"

This will send the message "encode:سلام" to the server and print the response.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iran_encoding-0.1.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iran_encoding-0.1.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file iran_encoding-0.1.0.tar.gz.

File metadata

  • Download URL: iran_encoding-0.1.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for iran_encoding-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9cb1ed81596a825b25c658d45a8e104b90f059c89aaae614a57d88c8899279dc
MD5 cd1f16ce7af23617afdf3c831e4d3adc
BLAKE2b-256 f8641722430fcfc555f924c9a7950cc8f520ddf58f59ac0160affd09ccd0c76e

See more details on using hashes here.

File details

Details for the file iran_encoding-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: iran_encoding-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for iran_encoding-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9be15e7904756946aa5f4070d9105c854389d6a4bb6735be671a3f96f26bf12
MD5 65a1fa7d90421463c760adf451d47191
BLAKE2b-256 4c1078520a842b6970ddd1c2ed1eecc15ed721e6cd63ad4b5c2f7960e5ba8340

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page