Skip to main content

A package for reading and writing World of Warcraft addon TOC files.

Project description

Tests

pytoc

A Python package for reading and writing World of Warcraft addon TOC files.

Installation

pip install wow-pytoc 

Usage

Reading a TOC file

from pytoc import TOCFile, TOCTextLocale

toc = TOCFile("path/to/MyAddon.toc")

print(toc.Interface)          # TOCListValue[int] of all interface versions
print(toc.Title)              # base (enUS) value
print(toc.Title.get_translation(TOCTextLocale.frFR))
print(toc.ExtendedDirectives.get("X-Website"))
print(toc.UnknownDirectives.get("SomeUnknownField"))

for dep in toc.Dependencies:
    print(f"Required: {dep}")
for dep in toc.OptionalDeps:
    print(f"Optional: {dep}")

for file_line in toc.Files:
    entry = file_line.FileEntry
    print(entry.export())

Writing a TOC file

from pytoc import TOCFile, TOCLocalizedDirectiveValue, TOCListValue, TOCTextLocale

toc = TOCFile()
toc.Interface = TOCListValue("110000", [110000])
toc.Author = TOCLocalizedDirectiveValue("Ghost")
toc.Title = TOCLocalizedDirectiveValue(
    "MyAddon",
    {TOCTextLocale.frFR: "MonAddon", TOCTextLocale.deDE: "MeinAddon"},
)

toc.add_file("MyAddon.lua")
toc.add_file("MyAddon.xml")
toc.add_dependency("totalRP3", required=False)

toc.export("path/to/MyAddon.toc", overwrite=True)

Round-trip

Reading and exporting an existing file produces byte-identical output.

toc = TOCFile("MyAddon.toc")
toc.Author = TOCLocalizedDirectiveValue("NewAuthor")
toc.export("MyAddon.toc", overwrite=True)
# Every line unchanged except ## Author:

Load condition simulation

TOCEvaluationContext lets you simulate whether an addon (or a specific file entry) would load under given game conditions.

from pytoc import (
    TOCFile, TOCEvaluationContext, TOCAllowLoadGameType,
    TOCGameType, TOCEnvironment, TOCTextLocale,
)

ctx = TOCEvaluationContext(TOCGameType.Mainline, TOCEnvironment.Global, TOCTextLocale.enUS)

toc = TOCFile("MyAddon.toc")
can_load, err = toc.can_load_addon(ctx)

# Per-file entry
for file_line in toc.Files:
    if file_line.FileEntry.should_load(ctx):
        print(file_line.FileEntry.resolve_path(ctx))

Notes/Quirks

[!NOTE]

  • Dependencies and OptionalDeps are TOCListValue[str]; use add_dependency(name, required=True/False) to append safely.
  • X- prefixed fields are available via toc.ExtendedDirectives (a dict[str, str]).
  • Unrecognised directives (non-X-, not in the known list) land in toc.UnknownDirectives and are not exported.
  • Multiple occurrences of the same directive are merged - last value wins for scalars, values are combined for list fields.
  • Comments and blank lines are preserved on round-trip.

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

wow_pytoc-0.8.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

wow_pytoc-0.8.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file wow_pytoc-0.8.0.tar.gz.

File metadata

  • Download URL: wow_pytoc-0.8.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for wow_pytoc-0.8.0.tar.gz
Algorithm Hash digest
SHA256 8fe9e1179b86aed855bead9b43584d3db7984b733ce5136151226f76dce3c43d
MD5 c8fe6b53da4aead289bef077fc52bb95
BLAKE2b-256 f98d75791c455c480d041a94a4a08f3ad98383ca936d78745d06e2fe94f41026

See more details on using hashes here.

File details

Details for the file wow_pytoc-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: wow_pytoc-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for wow_pytoc-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ee3dc144fd8f8213ccf38afd743abccac19f2203f8eaf99614dd15159d81869
MD5 6d637992fc23788fbd2706eff8594399
BLAKE2b-256 6572be4d3087fac08f6acdaab799aa030e8afd998548f731a8014d6b6c1c8567

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