Skip to main content

Verified line-addressed file editor using lnhash addresses

Project description

exhash — Verified Line-Addressed File Editor

exhash combines Can Bölük's very clever line number + hash editing system with the powerful and expressive syntax of the classic ex editor.

Install via pip to get both a convenient Python API, and native CLI binaries:

pip install exhash

Or install just the CLI binaries via cargo:

cargo install exhash

lnhash format

We refer to an lnhash as a tag of the form lineno|hash|, where hash is the lower 16 bits of Rust's DefaultHasher over the line content. exhash is just like ex, except that addresses must be in lnhash format. Addresses like %, ., etc are not permitted.

CLI

The native Rust binaries are installed into your PATH via pip.

View

# Shows every line prefixed with its lnhash
lnhashview path/to/file.txt
# Optional line number range to show
lnhashview path/to/file.txt 10 20

Edit

# Substitute on one line
exhash file.txt '12|abcd|s/foo/bar/g'

# Append multiline text (terminated by a single dot)
exhash file.txt '12|abcd|a' <<'EOF'
new line 1
new line 2
.
EOF

# Dry-run
exhash --dry-run file.txt '12|abcd|d'

For a/i/c commands, provide the text block on stdin:

printf "new line 1\nnew line 2\n.\n" | exhash file.txt "2|beef|a"

Stdin filter mode

cat file.txt | exhash --stdin - '1|abcd|s/foo/bar/'

In --stdin mode, multiline a/i/c text blocks are not available.

Python API

from exhash import exhash, exhash_result, lnhash, lnhashview, line_hash

Viewing

text = "foo\nbar\n"
view = lnhashview(text)  # ["1|a1b2|  foo", "2|c3d4|  bar"]

Editing

exhash(text, cmds) takes the text and a required list of command strings (use [] for no-op). For a/i/c commands, lines after the command are the text block (no . terminator needed):

addr = lnhash(1, "foo")  # "1|a1b2|"
res = exhash(text, [f"{addr}s/foo/baz/"])
print(res["lines"])    # ["baz", "bar"]
print(res["modified"]) # [1]

# Multiple commands
a1, a2 = lnhash(1, "foo"), lnhash(2, "bar")
res = exhash(text, [f"{a1}s/foo/FOO/", f"{a2}s/bar/BAR/"])

# Append multiline text (no dot terminator)
res = exhash(text, [f"{addr}a\nnew line 1\nnew line 2"])

Result dict

  • lines — list of output lines
  • hashes — lnhash for each output line
  • modified — 1-based line numbers of modified/added lines
  • deleted — 1-based line numbers of removed lines (in original)

exhash_result([res1, res2, ...]) renders modified lines in lnhash format, matching the old repr(EditResult) style.

Tests

cargo test && pytest -q

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

exhash-0.1.4.tar.gz (22.9 kB view details)

Uploaded Source

Built Distributions

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

exhash-0.1.4-cp313-cp313-manylinux_2_34_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

exhash-0.1.4-cp313-cp313-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

exhash-0.1.4-cp312-cp312-manylinux_2_34_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

exhash-0.1.4-cp312-cp312-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

exhash-0.1.4-cp311-cp311-manylinux_2_34_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

exhash-0.1.4-cp311-cp311-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

exhash-0.1.4-cp310-cp310-manylinux_2_34_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

exhash-0.1.4-cp310-cp310-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file exhash-0.1.4.tar.gz.

File metadata

  • Download URL: exhash-0.1.4.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for exhash-0.1.4.tar.gz
Algorithm Hash digest
SHA256 eb8aa00e2be39431454e077c05da3c82292a6e63e72332eecc60666ab8438a48
MD5 b00b88cce67c81d15bf48ea5e20cb4b7
BLAKE2b-256 6c1b6d0a5ac5f08af48afcdfbb5364e3896e59b08cffdb1d94e057760f99797e

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.1.4.tar.gz:

Publisher: ci.yml on AnswerDotAI/exhash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exhash-0.1.4-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for exhash-0.1.4-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 52ef2419c35d36877722412891de66ee51fdd29f7f6a15b9884c83e3f2a0b747
MD5 f240acc7744718fdc3f7d74fecee19b7
BLAKE2b-256 f6db818da56eebb753dc2a025a61e48d41c1ebf8dc81a4d27606178412f11786

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.1.4-cp313-cp313-manylinux_2_34_x86_64.whl:

Publisher: ci.yml on AnswerDotAI/exhash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exhash-0.1.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for exhash-0.1.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d5a5604654613ebddbaed23ebe01bfa1a65977751ecceb2a166b6b0ce5ad5f26
MD5 e645cfe251917bdddc040178d9bcae95
BLAKE2b-256 04c47a3a14e50253cd7d5e1c6789d1b74b5f4f47da924f75404ff8c651b3605e

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.1.4-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: ci.yml on AnswerDotAI/exhash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exhash-0.1.4-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for exhash-0.1.4-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 116c0162e5bc6fba788ad2db4709f2fb0b6f69f1ce22ad839605d5062d29eeb6
MD5 4e83c0e0894a2752891fd5f66823e0cb
BLAKE2b-256 cb7f9f3f0684a174b4fe62cae561454b789d40a8fa6c9d6c1a3716992ea285e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.1.4-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: ci.yml on AnswerDotAI/exhash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exhash-0.1.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for exhash-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2cbcd36cb635eb521d933bfe07e97ec457d96dbe8e8623922fcacabbfc32062d
MD5 a5fb098b498470f14bc3f499d5158151
BLAKE2b-256 635d244af8bd319b621aeb902bf858917e94d99bb647cb10384f3dca0f304f73

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.1.4-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: ci.yml on AnswerDotAI/exhash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exhash-0.1.4-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for exhash-0.1.4-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 318e7deadccc448adaec18c99bebeb64fd8de747f4b768d5d9b9671326c08d90
MD5 6d5bfa75ea5847ed0ca3e493b1c48e00
BLAKE2b-256 1f6d114b6fc9f289ae6132f4154525b7b8e3725cd3ce1625cd3b5cab860fa13e

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.1.4-cp311-cp311-manylinux_2_34_x86_64.whl:

Publisher: ci.yml on AnswerDotAI/exhash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exhash-0.1.4-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for exhash-0.1.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 251908680abd6718b8313dbfb963a35edd8b9dbce925804b4ef627c2ed425941
MD5 4a392514e97244106ce620972149a944
BLAKE2b-256 d70f3272f980164022268ef96ba395d090b973cbbd5a65f8edf47fab3992b679

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.1.4-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: ci.yml on AnswerDotAI/exhash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exhash-0.1.4-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for exhash-0.1.4-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8a6ef80a32ffda3c17f0527f57d26570b4e919e6576906c13ce5d9b6ef992d38
MD5 4a71c4731472de04a6d655d0f505640e
BLAKE2b-256 7b9b3f35ca81c93d0cf1ca3652c184172a0571df7a314164ea091aadef4dbed8

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.1.4-cp310-cp310-manylinux_2_34_x86_64.whl:

Publisher: ci.yml on AnswerDotAI/exhash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exhash-0.1.4-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for exhash-0.1.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aa6734865891955795d1805fff2d1334810068349a5f20b30502cced263f583d
MD5 7a9001ef890e8b0f5466aa5d6be26e37
BLAKE2b-256 9e0468305e87b37ab8bf2836908f4a9efadafdf832784d2051034aa7a4a700f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.1.4-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: ci.yml on AnswerDotAI/exhash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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