Files
anybadge/anybadge/templates/__init__.py
Jon Grace-Cox 8a434d95b5 Drop <3.7 support and add type hints (#59)
- Drop support for Python <3.7
- Bump the pre-commit version used in CI
- Add type hinting and docstrings
- Add mypy to pre-commit config
- Fix typing issues
- Update colors module
  - Update colors module to use uppercase hex codes
  - Add `__lt__` to allow sorting colors by name
- Fix `build_examples.py` to work with color Enum
- Update example badges in `README.md`
- Fix typing issues in server
- Update travis links in `README.md`
- Fix PyPi deployment bug (#60)
2022-08-08 23:19:50 -04:00

25 lines
523 B
Python

"""Templates package."""
import pkgutil
from anybadge.exceptions import UnknownBadgeTemplate
def get_template(name: str) -> str:
"""Get a template by name.
Examples:
>>> get_template('default') # doctest: +ELLIPSIS
'<?xml version="1.0" encoding="UTF-8...
"""
try:
data = pkgutil.get_data(__name__, name + ".svg")
except FileNotFoundError as e:
raise UnknownBadgeTemplate from e
if not data:
raise UnknownBadgeTemplate
return data.decode("utf-8")