
Security News
NIST Under Federal Audit for NVD Processing Backlog and Delays
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
python package with useful mapping shortcuts
pip install mapping-shortcuts
from mapping_shortcuts.decors import create_collector
decorator, collection = create_collector(
raise_on_duplicate=True, # default: True
)
@decorator('key1')
def func1():
...
@decorator('key2')
def func2():
...
print(collection)
'''
output: {
'key1': <function func1 at 0x104adc430>,
'key2': <function func2 at 0x104adc4c0>,
}
'''
from mapping_shortcuts.decors import create_class_collector
decorator, collection = create_class_collector(
raise_on_duplicate=True, # default: True
key_getter=lambda x: x.key # default: lambda x: x.__name__
)
@decorator
class SomeClass1:
key = 123
@decorator
class SomeClass2:
key = 456
print(collection)
'''
output: {
123: <class '__main__.SomeClass1'>,
456: <class '__main__.SomeClass2'>,
}
'''
import abc
from mapping_shortcuts.meta import create_collection_meta
MetaClass, collections = create_collection_meta(
base=abc.ABCMeta, # default: type
getter=lambda x: x.__name__, # default: lambda x: str(x)
raise_on_duplicate = True, # default: True
)
class A(metaclass=MetaClass):
...
class B(metaclass=MetaClass):
...
print(collections)
'''
oputput: {
'A': <class '__main__.A'>,
'B': <class '__main__.B'>,
}
'''
For exmaple with have five files:
app/tools.py
app/providers/a/__init__.py
app/providers/b/__init__.py
app/providers/a/module.py
app/providers/b/module.py
app/tools.py
be like:
from mapping_shortcuts.decors import create_collector
decorator, collection = create_collector()
app/providers/a/module.py
is:
from app.tools import decorator
@decorator('A-func')
def function_a():
...
app/providers/b/module.py
is:
from app.tools import decorator
@decorator('B-func')
def function_b():
...
execute load_package()
:
from mapping_shortcuts.dirtools import load_package
from app.tools import collection
load_package('app.providers')
print(collection)
'''
output: {
'A-func': <function function_a at 0x104cfa0e0>,
'B-func': <function function_b at 0x104cfa290>,
}
'''
from pydantic import BaseModel, Field
from mapping_shortcuts.cli import cli_handler, process_sysargv
@cli_handler('command1', desc='run handler for command1')
def handler_1(args: dict[str, str | bool]) -> None:
print('command 1 handled!')
class ArgModel(BaseModel):
x: int = Field(alias='--x', description='arg x')
y: int = Field(alias='--y', description='arg y')
@cli_handler('command2', desc='sum X and Y', model=ArgModel)
def handler_1(args) -> None:
print(f'{args.x=}')
print(f'{args.y=}')
print(f'result: {args.x + args.y}')
@cli_handler('command3', desc='sum X and Y')
def handler_1(args: ArgModel) -> None:
print(f'{args.x=}')
print(f'{args.y=}')
print(f'result: {args.x + args.y}')
if __name__ == '__main__':
process_sysargv(
help_msg_header='That\'s my program!',
help_msg_run_cmd='python -m project',
)
Execution:
$ python script.py
That's my program!
usage: python -m project [options] [command]
command:
help - see this cool msg again
command1 - run handler for command1
command2 - sum X and Y
--x - arg x
--y - arg y
command3 - sum X and Y
--x - arg x
--y - arg y
$ python script.py command3 --x=123 --y=456
args.x=123
args.y=456
result: 579
FAQs
Useful shortcuts for create mappings
We found that mapping-shortcuts demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.
Security News
TypeScript Native Previews offers a 10x faster Go-based compiler, now available on npm for public testing with early editor and language support.