{ "info": { "author": "Rafael Guill\u00e9n", "author_email": "arthexis@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries", "Topic :: Text Processing", "Topic :: Utilities" ], "description": "Sigils\n======\n\nA **sigil** is a token embedded in text, used as a magical placeholder\nfor a future value. When resolved, the actual value will be extracted\nfrom an user-provided or global context.\n\nThis library contains tools to extract, replace and resolve such sigils.\n\n\n.. _Documentation:\n\n\nInstalling\n----------\n\nInstall and update using `pip`_:\n\n.. code-block:: text\n\n pip install -U sigils\n\n\nStructure of Sigils\n-------------------\n\nA typical sigil has one of the following forms:\n\n.. code-block:: text\n\n [USERNAME]\n [SETTINGS.BASE_DIR]\n [MODEL='natural-key'.FIELD]\n [MODEL.USR=[USERNAME].STATUS]\n\nEach sigil is a list of **nodes** separated by a dot.\nNodes can be standalone or parametrized. If parametrized, they can take one\n**argument** by using the equals sign. The argument can be a number, a single-quoted string,\nor another sigil.\n\n.. code-block:: text\n\n [NODE1='ARG1'.NODE2=[ARG2].NODE3=10.ETC]\n\nSigils used as arguments can be nested to any depth.\n\n\nResolving Sigils\n----------------\n\nThe *resolve* function will replace any sigils found in a string, given a context:\n\n.. code-block:: python\n\n from sigils import resolve\n\n text = \"[USERNAME]: The BASE_DIR is [SETTINGS.BASE_DIR].\"\n context = {\n \"USERNAME\": \"arthexis\",\n \"SETTINGS\": {\"BASE_DIR\": \"/home/arth/webapp\"},\n }\n result = list(resolve(text, context))\n assert result == \"arthexis: The BASE_DIR is /home/arth/webapp\"\n\n\nNote that *resolve* returns a generator, so you will need to pass\nit to *list* or some other kind os sequence, or iterate it in a loop or comprehension.\n\nAll keys in the context mapping should be strings. Values can be anything, but usually it\nwill be a string, another dict, a callable or an instance with public fields:\n\n.. code-block:: python\n\n class Model:\n owner = \"arthexis\"\n # Valid tokens\n context = {\n \"USERNAME\": \"arthexis\", # [USERNAME]\n \"SETTINGS\": {\"NAME\": \"webapp\"}, # [SETTINGS.NAME]\n \"MODEL\": Model, # [MODEL.OWNER]\n \"UPPER\": lambda x: x.upper(), # [UPPER='text']\n \"RNG\": lambda _: randint(), # [RNG]\n }\n\nInstead of passing the context explicitly, a global default context can be set\nto be used by all calls to *resolve*, you can see an example in the Django integration below.\n\n\n\nDjango Integration\n------------------\n\nYou can create a `simple tag`_ to resolve sigils in templates.\nCreate */templatetags/sigils.py* with the following code:\n\n.. code-block:: python\n\n import sigils\n from django import templates\n\n register = template.Library()\n\n @register.simple_tag\n def resolve(text, **context):\n return sigils.resolve(text, context)\n\nIn *app.py* add the following to register a model in the global context\n(rename MyModel to the name of your model class):\n\n.. code-block:: python\n\n import sigils\n from django.apps import AppConfig\n\n class MyAppConfig(AppConfig):\n def ready():\n from .models import MyModel\n\n def my_model_lookup(parent, slug):\n if not parent:\n return MyModel.objects.filter(slug=slug)\n return parent.my_models.get(slug=slug)\n\n sigils.set_context(\"MyModel\", my_model_lookup)\n\nYou can change the lambda to make your model searchable with\na different argument or manager, here the primary key is used.\n\nThen you can use something like this in your template:\n\n.. code-block:: django\n\n {% load sigils %}\n Some stuff: {% sigil '[MyModel=[obj.slug].some_field]' obj=foo %}\n\n.. _simple tag: https://docs.djangoproject.com/en/2.2/howto/custom-template-tags/#simple-tags\n\nDependencies\n------------\n\n* lark_: Allows us to parse arbitrarily complex sigils fast.\n\n\n.. _lark: https://github.com/lark-parser/lark\n.. _pip: https://pip.pypa.io/en/stable/quickstart/", "description_content_type": "text/x-rst", "docs_url": null, "download_url": "https://github.com/arthexis/sigils/archive/v0.0.4.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/arthexis/sigils", "keywords": "UTILS,SIGIL,STRING,TEXT", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "sigils", "package_url": "https://pypi.org/project/sigils/", "platform": "", "project_url": "https://pypi.org/project/sigils/", "project_urls": { "Download": "https://github.com/arthexis/sigils/archive/v0.0.4.tar.gz", "Homepage": "http://github.com/arthexis/sigils" }, "release_url": "https://pypi.org/project/sigils/0.0.4/", "requires_dist": null, "requires_python": "", "summary": "Extract, resolve and replace [SIGILS] embedded in text.", "version": "0.0.4" }, "last_serial": 5981272, "releases": { "0.0.2": [ { "comment_text": "", "digests": { "md5": "788a6acb794972a290de3c91fa9ce13b", "sha256": "2ecb07379671e6844242dc63d41dc42fa01a6bce56d0481a42cbb8a9f739200f" }, "downloads": -1, "filename": "sigils-0.0.2.tar.gz", "has_sig": false, "md5_digest": "788a6acb794972a290de3c91fa9ce13b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4837, "upload_time": "2019-10-15T01:08:14", "url": "https://files.pythonhosted.org/packages/29/ac/bba1ebdf6708b05673ee9ce63fd97c9d463406dd880b3e1389db69f75cbd/sigils-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "58ecb35007cf6a6fac3e632aa377eee7", "sha256": "ecd1625cb58ae5530e1ff07ca293ef68350b9171b954cf2b489cfb3ef79c1e01" }, "downloads": -1, "filename": "sigils-0.0.3.tar.gz", "has_sig": false, "md5_digest": "58ecb35007cf6a6fac3e632aa377eee7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4841, "upload_time": "2019-10-15T01:11:47", "url": "https://files.pythonhosted.org/packages/a9/bd/f1b9717b74ff4b5565792f9c18541e14f6aaed7343964aa55afe08113c80/sigils-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "cbd721fcdea6fff197cfef57e0d41195", "sha256": "49864d22ab95d27703f0d25c07603100ff4335609b9f511fe636ba83e1d2a793" }, "downloads": -1, "filename": "sigils-0.0.4.tar.gz", "has_sig": false, "md5_digest": "cbd721fcdea6fff197cfef57e0d41195", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6992, "upload_time": "2019-10-16T05:03:01", "url": "https://files.pythonhosted.org/packages/f1/85/2bfa0123f1b536b880afed2bf89d4e86a70e405baa84079f2d5cfa777f2a/sigils-0.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "cbd721fcdea6fff197cfef57e0d41195", "sha256": "49864d22ab95d27703f0d25c07603100ff4335609b9f511fe636ba83e1d2a793" }, "downloads": -1, "filename": "sigils-0.0.4.tar.gz", "has_sig": false, "md5_digest": "cbd721fcdea6fff197cfef57e0d41195", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6992, "upload_time": "2019-10-16T05:03:01", "url": "https://files.pythonhosted.org/packages/f1/85/2bfa0123f1b536b880afed2bf89d4e86a70e405baa84079f2d5cfa777f2a/sigils-0.0.4.tar.gz" } ] }