lstr: partially lockable Python strings
lstr is a Python package for partially lockable strings.
Installation
lstr requires Python 3.8 or later.
pip install lstr
Examples
Creating an lstr
from lstr import lstr
greeting = lstr("Hello, world!")
print(greeting)
Hello, world!
Getting help with indexes
from lstr import lstr
greeting = lstr("Hello, world!")
print(repr(greeting))
0 1 2 3 4 5 6 7 8 9 10 11 12
H e l l o , w o r l d !
Inserting text
from lstr import lstr
greeting = lstr("Good morning, Bobby!")
greeting.write("Captain ", index=14)
print(greeting)
Good morning, Captain Bobby!
Overwriting text
from lstr import lstr
greeting = lstr("Good morning, Captain Bobby!")
greeting.write("Fleet Admiral", index=14, length=7)
print(greeting)
Good morning, Fleet Admiral Bobby!
Substituting text
from lstr import lstr
greeting = lstr("Good morning, Fleet Admiral Bobby!")
greeting.sub("morning", "evening")
print(greeting)
Good evening, Fleet Admiral Bobby!
Substituting text with a regular expression
from lstr import lstr
greeting = lstr("Good evening, Fleet Admiral Bobby!")
greeting.sub(r"(Fleet Admiral)", r"🎉\g<1>🎉")
print(greeting)
Good evening, 🎉Fleet Admiral🎉 Bobby!
Locking a range
from lstr import lstr
greeting = lstr("Good morning, Fleet Admiral Bobby!")
greeting.lock(index=14, length=13)
greeting.write("Ensign", index=14, length=13)
print(greeting)
Good morning, Fleet Admiral Bobby!
Locking a substitution
from lstr import lstr
greeting = lstr("Good morning, Captain Bobby!")
greeting.sub("Captain", "Fleet Admiral", lock=True)
greeting.sub("Fleet Admiral", "Ensign")
print(greeting)
Good morning, Fleet Admiral Bobby!
Equality
lstr instances are considered equal only if their string value and locks are identical.
lstr("f", locks=[Lock(index=1, length=2)]) == lstr("f", locks=[Lock(index=1, length=2)])
lstr("f", locks=[Lock(index=1, length=2)]) != lstr("f", locks=[Lock(index=3, length=4)])
lstr and str instances are considered equal if the string value is identical, regardless of the locks.
lstr("f") == "f"
lstr("f") != "g"
Thank you! 🎉
My name is Cariad, and I'm an independent freelance DevOps engineer.
I'd love to spend more time working on projects like this, but--as a freelancer--my income is sporadic and I need to chase gigs that pay the rent.
If this project has value to you, please consider ☕️ sponsoring me. Sponsorships grant me time to work on your wants rather than someone else's.
Thank you! ❤️
Metadata
Release files for lstr 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lstr-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for lstr-1.0.0-py3-none-any.whl |
Release files / lstr-1.0.0-py3-none-any.whl
| Download URL | lstr-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
522a612629c743608b3e8b2ae9c6b520f06a0ac228989cad7e3de166a861ac8d
|
|
BLAKE2b-256 checksum How to use checksums |
b19986749b3aafeac9982df0bf39d6e7bf8393cc586df4c5c5ae6149933af60d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
|
Security for lstr 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.