From 49fffb5d3a94a5598f28355cb1b0ad169a31807f Mon Sep 17 00:00:00 2001 From: Alec Warner Date: Thu, 11 Jan 2007 21:29:22 +0000 Subject: Valid categories in catpkgsplit svn path=/main/trunk/; revision=5568 --- pym/portage_versions.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'pym') diff --git a/pym/portage_versions.py b/pym/portage_versions.py index 8e58c2f47..5cedd6504 100644 --- a/pym/portage_versions.py +++ b/pym/portage_versions.py @@ -249,7 +249,23 @@ def pkgsplit(mypkg,silent=1): catcache={} def catpkgsplit(mydata,silent=1): - "returns [cat, pkgname, version, rev ]" + """ + Takes a Category/Package-Version-Rev and returns a list of each. + + @param mydata: Data to split + @type mydata: string + @param silent: suppress error messages + @type silent: Boolean (integer) + @rype: list + @return: + 1. If each exists, it returns [cat, pkgname, version, rev] + 2. If cat is not specificed in mydata, cat will be "null" + 3. if rev does not exist it will be '-r0' + 1. If the cat, pkg, or version is invalid, return None + """ + + # Categories may contain a-zA-z0-9+_- but cannot start with - + valid_category = re.compile("^[A-Za-z0-9+_][A-Za-z0-9+_-]*") try: if not catcache[mydata]: return None @@ -262,6 +278,8 @@ def catpkgsplit(mydata,silent=1): retval=["null"] p_split=pkgsplit(mydata,silent=silent) elif len(mysplit)==2: + if not valid_category.match(mysplit[0]): + raise ValueError("Invalid category in %s" %mydata ) retval=[mysplit[0]] p_split=pkgsplit(mysplit[1],silent=silent) if not p_split: -- cgit v1.2.3-1-g7c22