CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-python-bidi

Python Bidi layout wrapping the Rust crate unicode-bidi

Overall
score

93%

Overview
Eval results
Files

task.mdevals/scenario-7/

Multi-Encoding Text Processor

Build a text processor that handles bidirectional text in multiple character encodings for a legacy document conversion system.

Requirements

Your solution must implement a function that processes text files containing right-to-left (RTL) content stored in various legacy encodings and prepares them for display.

Core Functionality

Implement a function process_text_file(data, encoding_name) that:

  • Accepts raw bytes as the first parameter
  • Accepts an encoding name (string) as the second parameter
  • Converts the bytes to displayable format while preserving the encoding type
  • Returns the processed bytes in the same encoding

The function should handle at least these encodings:

  • UTF-8 (utf-8)
  • Windows Hebrew (cp1255)
  • ISO Hebrew (iso-8859-8)

Test Cases

  • Processing UTF-8 encoded Hebrew text "שלום" (shalom) returns reversed bytes in UTF-8 encoding @test
  • Processing CP1255 encoded Hebrew text returns reversed bytes in CP1255 encoding @test
  • Processing ISO-8859-8 encoded Hebrew text returns reversed bytes in ISO-8859-8 encoding @test
  • Processing mixed English and Hebrew text maintains correct directionality for both scripts @test

Implementation

@generates

API

def process_text_file(data: bytes, encoding_name: str) -> bytes:
    """
    Process bidirectional text from bytes in the specified encoding.

    Args:
        data: Raw bytes containing text in the specified encoding
        encoding_name: The character encoding name (e.g., 'utf-8', 'cp1255', 'iso-8859-8')

    Returns:
        Processed bytes in the same encoding, with text reordered for display
    """
    pass

Dependencies { .dependencies }

python-bidi { .dependency }

Provides bidirectional text processing support for handling right-to-left scripts.

Install with Tessl CLI

npx tessl i tessl/pypi-python-bidi

tile.json