HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: //snap/google-cloud-cli/396/platform/gsutil/third_party/charset_normalizer/bin/integration.py
from requests import get, __version__
from typing import List
from charset_normalizer import detect, __version__ as __version_cn__

if __name__ == "__main__":

    print(f"requests {__version__}")
    print(f"charset_normalizer {__version_cn__}")

    files: List[str] = get("http://127.0.0.1:8080/").json()

    print("## Testing with actual files")

    for file in files:
        r = get(
            "http://127.0.0.1:8080/" + file
        )

        if r.ok is False:
            print(f"Unable to retrieve '{file}' | HTTP/{r.status_code}")
            exit(1)

        expected_encoding = detect(r.content)["encoding"]

        if expected_encoding != r.apparent_encoding:
            print(f"Integration test failed | File '{file}' | Expected '{expected_encoding}' got '{r.apparent_encoding}'")
            exit(1)

        print(f"✅✅ '{file}' OK")

    print("## Testing with edge cases")

    # Should NOT crash
    get("http://127.0.0.1:8080/edge/empty/json").json()

    print("✅✅ Empty JSON OK")

    if get("http://127.0.0.1:8080/edge/empty/plain").apparent_encoding != "utf-8":
        print("Empty payload SHOULD not return apparent_encoding != UTF-8")
        exit(1)

    print("✅✅ Empty Plain Text OK")

    r = get("http://127.0.0.1:8080/edge/gb18030/json")

    if r.apparent_encoding != "GB18030":
        print("JSON Basic Detection FAILURE (/edge/gb18030/json)")
        exit(1)

    r.json()

    print("✅✅ GB18030 JSON Encoded OK")

    print("Integration tests passed!")