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'

When passing multiple commands, each command's lnhashes are verified immediately before that command runs.

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 iterable 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/"])

# Hashes are checked just-in-time per command.
# If earlier commands change/shift a later target line, recompute lnhash first.

# 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.2.0.tar.gz (23.3 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.2.0-cp313-cp313-manylinux_2_34_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

exhash-0.2.0-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.2.0.tar.gz.

File metadata

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

File hashes

Hashes for exhash-0.2.0.tar.gz
Algorithm Hash digest
SHA256 961d98152c7d38344cc9d27c6e47b559064f5206a33d1643c70f37e15c7ca193
MD5 e6c99e04bc0a6e01cbf39ff88213d390
BLAKE2b-256 378d90ee9ced6a65158996efb7a8d04391d616c0af6cccc1bfc8663aa5891cb7

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.2.0.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.2.0-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for exhash-0.2.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3708a57463d84c52b71d1b35eba985134b524b36eb4f89a2160ab35c1edf5cac
MD5 a6dfc7d7fcabb2c708e5222fa2767ea7
BLAKE2b-256 d093921818b8355f0f2531ce2df9df298c67b2c0c58c942ed81ebe272ff81b66

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.2.0-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.2.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for exhash-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2c763c8ae528ebd8183bb2394c93df8a53256754bff06ba51bba8b5c1dbc928e
MD5 49531d346598c652941d7af901728ef7
BLAKE2b-256 01f2328aceaaa7c3ad1881932f5676530d6fe9d0da62a1b74d3e77c48858e8fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.2.0-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.2.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for exhash-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c3ff72707b13e81ff95e39b61babb8ba45e692d800404f9f3a255ab2c3e59042
MD5 2aa2f1b6ec8babe1a12b0a40fb780d27
BLAKE2b-256 011b5f8c93206330d3a62d52241c4b9f29dd972b9d50856bb68b891a5c8c5a49

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.2.0-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.2.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for exhash-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f802a11b07f05b478c185904d625f5867f2323567d07cfd46ee25b5899508267
MD5 a290555353fdca9de585a60c26153dde
BLAKE2b-256 c8ef15aec4fdba1d018f25954b497d5ee9f48bf9c378b8f00c7388bf765f9109

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.2.0-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.2.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for exhash-0.2.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ae5f2174deb4dbe177456a5997d79b7f5fdeba3f7c4cc97d3159b6709b854780
MD5 a3d2ec5d11683268bdfe57fe0040f1a4
BLAKE2b-256 de07508a402a52c29ee261175c06fb454563448666fa1874817f6af21b9b92d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.2.0-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.2.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for exhash-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0ab4d8e5faff11ae60a8f7dc851f3b6914272bc37e72f4f190d243de8ca8d981
MD5 532f74720fd25e2a9443cd0d3a5a9c46
BLAKE2b-256 c2de7e3581803e9731e667d03aa75746c7e36779d029cf15f2ad3e0933792d8e

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.2.0-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.2.0-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for exhash-0.2.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d0faf4cdbd12a263e9aadbd300b7c1a7186041074a03565d4d46f6b5041c8db9
MD5 cce4baee4a46b833d92c06f0ac4c9be7
BLAKE2b-256 b01e536ea4b285b9a7ea01f14c14092b737579f13182db0b56d6796e6ff02d98

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.2.0-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.2.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for exhash-0.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8e2d1cd424f456ba8fa6b4f524581e679d3eccccd39825bd3b13f201ffa6ca62
MD5 adff54e51e312ce17ec51701143afc57
BLAKE2b-256 495870b23a870e0cdf03f9bf1d58d873c6c36c8382fad297b203069e1c248a90

See more details on using hashes here.

Provenance

The following attestation bundles were made for exhash-0.2.0-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