#!/usr/bin/env python from __future__ import (unicode_literals, print_function, with_statement, absolute_import) try: from . import cmdline except ValueError: import cmdline cmdline.main()
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import absolute_import from cmdline import main main()
try: if not outfile: #print formatter, 'using', formatter.encoding realoutfile = formatter.encoding and BytesIO() or StringIO() formatter.format(tokens, realoutfile) return realoutfile.getvalue() else: formatter.format(tokens, outfile) except TypeError, err: if isinstance(err.args[0], str) and \ 'unbound method format' in err.args[0]: raise TypeError('format() argument must be a formatter instance, ' 'not a class') raise def highlight(code, lexer, formatter, outfile=None): """ Lex ``code`` with ``lexer`` and format it with the formatter ``formatter``. If ``outfile`` is given and a valid file object (an object with a ``write`` method), the result will be written to it, otherwise it is returned as a string. """ return format(lex(code, lexer), formatter, outfile) if __name__ == '__main__': from cmdline import main sys.exit(main(sys.argv))
write_out() return Response(status=200) except IndexError: # recipe with specified index does not exist return Response("{\"error\":\"no such recipe\"}", status=404, mimetype="application/json") @app.route("/recipes/filter", methods=['GET']) def filter(): """ Filter the array of recipes by a kind of ingredient """ ingredient = request.args.get("ingredient") if ingredient == None: # no ingredient parameter was included in the request return Response("{\"error\":\"ingredient parameter is required\"}", status=400, mimetype="application/json") recipes = [ recipe.to_json_dict() for recipe in recipebook.recipes if recipe.has_ingredient(ingredient) ] return Response(json.dumps(recipes), mimetype="application/json") if __name__ == "__main__": # file was executed as a command line script cmdline.main(recipebook, sys.argv) write_out()