Metadata-Version: 2.1
Name: tstring-util
Version: 0.3
Summary: Utilities for tstring
Author: Gerard Weatherby
Author-email: gerardw@alum.mit.edu
License: MIT
Project-URL: Homepage, https://github.com/Gerardwx/tstring-util
Project-URL: Repository, https://github.com/Gerardwx/tstring-util
Project-URL: Issues, https://github.com/Gerardwx/tstring-util/issues
Project-URL: Changelog, https://github.com/Gerardwx/tstring-util/releases
Requires-Python: >=3.14
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: test
Requires-Dist: pytest; extra == "test"

# 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'*
