diff --git a/LICENSE.txt b/LICENSE.txt index c5c1f7b..cffde60 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright 2019 Rafael Guillén +Copyright 2019-2023 Rafael Guillén Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.rst b/README.rst index 0a7ab12..0ced925 100644 --- a/README.rst +++ b/README.rst @@ -129,22 +129,6 @@ The following characters are reserved and cannot be used in sigils: * ``\``: escape character -Protected Sigils ----------------- - -By starting a sigil with a ``.`` character, you can protect it from being -printed to logs unless the ``SIGILS_LOG_PROTECTED`` environment variable -is set to ``1``. This is useful for sensitive data such as passwords. - -.. code-block:: text - - [.MODEL='natural-key'.PASSWORD] - [.USER=[USERNAME].SECRET] - - -Instead of the sigil, its value will be replaced with ``[...]`` in the logs. - - Resolve and Replace ------------------- @@ -203,8 +187,7 @@ with the result and a list of sigils that were not resolved: The *replace* function doesn't resolve a sigil, instead it replaces it with another pattern of text and extracts all sigils that were replaced. -This is useful for logging. For example, you can replace a sigil with -a placeholder and then log the sigil separately: +This may also be useful for debugging and logging. For example: .. code-block:: python @@ -265,21 +248,38 @@ Then you can use something like this in your template: .. _simple tag: https://docs.djangoproject.com/en/2.2/howto/custom-template-tags/#simple-tags -Dependencies ------------- +Project Dependencies +-------------------- -* lark_: Allows us to parse complex sigils faster. -* lru-dict_: A fast LRU cache implementation. +.. _lark: https://github.com/lark-parser/lark +.. _pip: https://pip.pypa.io/en/stable/quickstart/ -Roadmap -------- +Features Roadmap +---------------- - [ ] Improved built-in support for Django models. -- [ ] Access to environment variables within SYS context. +- [ ] Improved access to environment variables within SYS context. +- [ ] Support for custom context functions (probably via a decorator) +- [ ] Support for list indexing and slicing. +- [ ] Ability to monkey-patch sigil functionality into existing classes. +- [ ] Ability to load context from a JSON, YAML, or TOML file. +- [ ] Additional SYS operations: OR, AND, NOT, IN, XPATH, REGEX, etc. +- [ ] Keep track of accessed context keys to optimize performance. +- [ ] More magic. +Protected Sigils (In Development) +---------------- +By starting a sigil with a ``.`` character, you can protect it from being +printed to logs unless the ``SIGILS_LOG_PROTECTED`` environment variable +is set to ``1``. This is useful for sensitive data such as passwords. -.. _lark: https://github.com/lark-parser/lark -.. _pip: https://pip.pypa.io/en/stable/quickstart/ +.. code-block:: text + + [.MODEL='natural-key'.PASSWORD] + [.USER=[USERNAME].SECRET] + + +Instead of the sigil, its value will be replaced with ``[...]`` in the logs. diff --git a/requirements.txt b/requirements.txt index d2a2cfc..7785e89 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ lark lru-dict django -pytest \ No newline at end of file +pytest +twine \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index b88034e..5aef279 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,2 @@ [metadata] -description-file = README.md +description-file = README.rst diff --git a/setup.py b/setup.py index 48e0cb0..c8f3df6 100644 --- a/setup.py +++ b/setup.py @@ -7,12 +7,11 @@ setup( name='sigils', - version='0.1.0', + version='0.1.1', description='Extract, resolve, replace and connect [SIGILS] embedded in text.', long_description=long_description, - long_description_content_type='text/x-rst', url='http://github.com/arthexis/sigils', - download_url='https://github.com/arthexis/sigils/archive/v0.1.0.tar.gz', + download_url='https://github.com/arthexis/sigils/archive/v0.1.1.tar.gz', author='Rafael Jesus Guillén Osorio', author_email='arthexis@gmail.com', license='MIT', @@ -27,17 +26,16 @@ 'Topic :: Utilities', 'License :: OSI Approved :: MIT License', 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', ], install_requires=[ 'lark-parser', 'lru-dict' ], - extras_require={ - 'django': [ - 'django', - ], + extras_require={ # Optional 'dev': [ + 'django', 'pytest', 'black', 'pytest-cov', diff --git a/sigils/transforms.py b/sigils/transforms.py index 8882f55..3d92b04 100644 --- a/sigils/transforms.py +++ b/sigils/transforms.py @@ -117,8 +117,8 @@ def replace( """ sigils = list(parsing.extract(text)) - n = hasattr(pattern, "__next__") for sigil in set(sigils): - text = text.replace(sigil, str(next(pattern)) if n else pattern) + text = (text.replace(sigil, str(next(pattern)) + if hasattr(pattern, "__next__") else pattern)) return text, tuple(sigils)