From: karltk Date: Sun, 29 Aug 2004 20:05:02 +0000 (-0000) Subject: Added exception checking to CmdBelongs to guard against bad regular expressions. X-Git-Tag: gentoolkit-0.2.4.3~383 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f919aee06cbb9e0a4d0f55885f19ce5002dae2e8;p=gentoolkit.git Added exception checking to CmdBelongs to guard against bad regular expressions. svn path=/; revision=119 --- diff --git a/trunk/src/equery/equery b/trunk/src/equery/equery index f9c1382..773a603 100755 --- a/trunk/src/equery/equery +++ b/trunk/src/equery/equery @@ -26,6 +26,10 @@ sys.path.insert(0, "/usr/lib/portage/pym") from output import * import gentoolkit +from gentoolkit import warn +from gentoolkit import error +from gentoolkit import info + # Auxiliary functions def fileAsStr(name, fdesc, showType=0, showMD5=0, showTimestamp=0): @@ -220,19 +224,22 @@ class CmdListBelongs(Command): if cat != "*": filter_fn = lambda x: x.find(cat+"/")==0 - if Config["verbosityLevel"] >= 3 and not Config["piping"]: - print "Searching for file '" + query + "' in " + cat + "..." + info(3, "Searching for file '" + query + "' in " + cat + "...") matches = gentoolkit.find_all_installed_packages(filter_fn) # Act intelligently on the query - if opts["fullRegex"]: - rx = re.compile(query) - elif len(query) and query[0] == "/": - rx = re.compile("^" + query + "$") - else: - rx = re.compile("/" + query + "$") - + try: + if opts["fullRegex"]: + rx = re.compile(query) + elif len(query) and query[0] == "/": + rx = re.compile("^" + query + "$") + else: + rx = re.compile("/" + query + "$") + except: + error("The query '" + query + "' does not appear to be a valid regular expression") + sys.exit(-2) + found = 0 for pkg in matches: cnt = pkg.get_contents()