Skip to main content

Utilities for tstring

Project description

tstring-util

Utlities for Python 3.14 t-string.

Python 3.14 supports creating objects of type string.templatelib.Template by prefixing with a "t".

lazy rendering

render(string.templatelib.Template)->str

Provides ability to write t-string with function calls with deferred evaluation. Any callable marked !fn will consume as many following interpolations as its positional args, be invoked, and its stdout captured inline. Everything else is rendered in order.

Example

from tstring import render


def hello(name):
    print(f"hello {name}")

def test_lazy():
    who = 'bob'
    flavor = 'spicy'
    embedx = t'Call function {hello:!fn} {who} {flavor}'
    who = 'jane'
    r = render(embedx)
    assert r ==  "Call function hello jane spicy"

safe paths

path(string.templatelib.Template)->Path

Converts t-string to a path. If any interpolations have a NUL or path separator in them, ValueError is raised. A special case of the first character of the first element being a separator is permitted to make paths absolute.

Example

from tstring import path
config = '/etc'
p = path(t'{config}/systemd')
assert p.as_posix() ==  '/etc/systemd'

Invalid path:

 no_good = 'bob/carol'
 path(t'{no_good}')

raises ValueError Invalid character '/' in interpolation 'no_good'

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

tstring_util-0.3.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

tstring_util-0.3-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file tstring_util-0.3.tar.gz.

File metadata

  • Download URL: tstring_util-0.3.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for tstring_util-0.3.tar.gz
Algorithm Hash digest
SHA256 65a734e15d71544bead6d36694e0d0b605e4d7ae904c320522ef858abafc5bc3
MD5 8e6df7c13942b47207a16fb1fee96978
BLAKE2b-256 ed4dc0250f74db546cde1445c474bbc58f0b0dc1b56f921c575c2e4948345232

See more details on using hashes here.

File details

Details for the file tstring_util-0.3-py3-none-any.whl.

File metadata

  • Download URL: tstring_util-0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for tstring_util-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f174e653ffada4290a90a01b6e54355bf56d65158caf4d20409b037d2166f644
MD5 0d2074617959ef0e7417a4e73298a25a
BLAKE2b-256 0e7865c335ec1ced1b9db5ef2b00160ace97b86e15a1a59af55e3c71ff43ecc6

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