Installing
python3 -m pip install stroke
Useful for creating a simple command based interface
import stroke
commands = stroke.State()
# create command
@commands.sub('echo')
def commands_0(content):
print(content)
# this is a subcommand
@commands_0.sub('loud')
def commands_0_0(content):
content = content.upper()
print(content)
# another subcommand with aliases
@commands_0.sub('pretty', 'aesthetic')
def commands_0_1(content):
content = ' '.join(iter(content))
print(content)
def main(content):
# analyse into names separated by .
# anything after a space is the argument
# use the names to find the invoke
# KeyError will be raised on invalid trail
(names, argument, invoke) = commands.analyse(content)
invoke(argument)
main('echo marco') # not polo
main('echo.loud whoa') # > WHOA
main('echo.aesthetic fancy words') # chill vibes
Useful for parsing arguments into parts
import stroke
commands = stroke.State()
figure_0 = {
'-and': 'int'
}
@commands.sub('add')
def commands_0(content):
# list of (flag, value)
arguments = stroke.craft(figure_0, content)
value = 0
# flag is always -and
for (flag, argument) in arguments:
value += int(argument)
print('result', value)
figure_1 = {
'-upper': 'numerator',
'-lower': 'denominator'
}
@commands.sub('div')
def commands_1(content):
# same thing
arguments = stroke.craft(figure_1, content)
# ignore multiple flags
arguments = dict(arguments)
# we need every flag for this one
values = (arguments[key] for key in figure_1)
# convert and unpack
(upper, lower) = map(int, values)
# handle errors on demand
value = upper / lower
print('result', value)
figure_2 = {
'-and': {
'-op': 'name',
'-co': 'args'
}
}
@commands.sub('calc')
def commands_2(content):
# this is actually a generator
arguments = stroke.craft(figure_2, content)
# here, argument is also one
for (flag, argument) in arguments:
# we only need one invoke
invoke = None
# can be executed multiple times
contents = []
for (flag, argument) in argument:
# signal for name
if flag == '-op':
# ignore empties
if not argument:
continue
# only first
if not invoke:
# get the invoke from name
invoke = commands.trail(argument)
continue
# no need to check if -co
contents.append(argument)
# execute commands
for content in contents:
invoke(content)
def main(content):
(names, argument, invoke) = commands.analyse(content)
invoke(argument)
print('>', stroke.draw(figure_0))
main('add 5 -and 9 -and -3') # 11
print('>', stroke.draw(figure_1, full = True))
main('div -upper 20 -lower 2 -upper 15') # 7.5
print('>', stroke.draw(figure_2, full = True))
main('calc add -co 1 \-and 2 -and div -co -upper 1 -lower 4') # 3 and 0.25
Metadata
Release files for stroke 2.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| stroke-2.3.2.tar.gz | 5.6 kB | Without provenance | Details for stroke-2.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stroke-2.3.2-py3-none-any.whl | Python 3 | none | any | Details for stroke-2.3.2-py3-none-any.whl |
Total release size: 13.4 kB
Release files / stroke-2.3.2.tar.gz
| Download URL | stroke-2.3.2.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
15f234d47ccf8a92aa77675fb7e6efbbbb902550c9eb1de8eef5cf16ebe97fd9
|
|
BLAKE2b-256 checksum How to use checksums |
220e051d301784559bdc8caa4247e4585306e037c65561e51946bb8de4d1eb96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|
Release files / stroke-2.3.2-py3-none-any.whl
| Download URL | stroke-2.3.2-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
affdde6fc25e5c3fd0ec79fd29daaba97a76cc6b12943015a551bcebb66b4672
|
|
BLAKE2b-256 checksum How to use checksums |
5213ea1349d287f6bd9b774fdc814b4fd77a70872b42969475057d1e96833b0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|
Security for stroke 2.3.2
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.