From 9821815de452583e3d948a6d15c28972049140b5 Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Fri, 17 Oct 2014 11:10:31 +0100 Subject: Fulfil TODO: don't keyerror on invalid op --- import/pip_lorry.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/import/pip_lorry.py b/import/pip_lorry.py index 3083ee6..13a84af 100755 --- a/import/pip_lorry.py +++ b/import/pip_lorry.py @@ -120,13 +120,20 @@ def filter_urls(urls): # TODO: find a nicer way to do this def specs_satisfied(version, specs): + def mapping_error(op): + # We parse ops with requirements-parser, so any invalid user input + # should be detected there. This really guards against + # the pip developers adding some new operation to a requirement. + error("Invalid op in spec: %s" % op) + opmap = {'==' : lambda x, y: x == y, '!=' : lambda x, y: x != y, '<=' : lambda x, y: x <= y, '>=' : lambda x, y: x >= y, '<': lambda x, y: x < y, '>' : lambda x, y: x > y} - TODO: don't just key error if we don't recognise the op + def get_op_func(op): + return opmap[op] if op in opmap else lambda x, y: mapping_error(op) - return all([opmap[op](version, sv) for (op, sv) in specs]) + return all([get_op_func(op)(version, sv) for (op, sv) in specs]) def generate_tarball_lorry(requirement): try: -- cgit v1.2.1