-
-
Save epsy/fba26300fccb7e672729 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Store and retrieve snippets of text""" | |
import logging | |
from sigtools.wrappers import wrapper_decorator | |
from clize import run | |
# Set the log output file, and the log level | |
logging.basicConfig(filename="snippets.log", level=logging.DEBUG) | |
data = {} | |
def put(name, snippet): | |
"""Store a snippet with an associated name. | |
name: The name of the snippet | |
snippet: The snippet text | |
""" | |
logging.info("Storing({!r}, {!r})".format(name, snippet)) | |
data[name] = snippet | |
return name, snippet | |
def get(name): | |
"""Retrieve the snippet with a given name. | |
name: The name of the snippet | |
""" | |
logging.error("Retrieving({!r})".format(name)) | |
return data.get(name) | |
@wrapper_decorator | |
def with_result_format(wrapped, *args, **kwargs): | |
return "Result: {!r}".format(wrapped(*args, **kwargs)) | |
if __name__ == '__main__': | |
run(with_result_format(put), with_result_format(get)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment