Skip to content

Instantly share code, notes, and snippets.

@epsy
Created April 29, 2015 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epsy/fba26300fccb7e672729 to your computer and use it in GitHub Desktop.
Save epsy/fba26300fccb7e672729 to your computer and use it in GitHub Desktop.
"""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